Ejemplo n.º 1
0
bool CompilerInterface::objects(FileName *filenames) const
{
  FUNCTION_TRACE;
  int i;
  filenames->clear();
  for (i=1;i<args.argc();i++)
  {
    const char *file=args[i];
    if (!isDestination(file))
      if (isObject(file))
        filenames->append(file);
  }

  return true;
}
Ejemplo n.º 2
0
void
RODFNet::computeTypes(RODFDetectorCon& detcont,
                      bool sourcesStrict) const {
    PROGRESS_BEGIN_MESSAGE("Computing detector types");
    const std::vector< RODFDetector*>& dets = detcont.getDetectors();
    // build needed information. first
    buildDetectorEdgeDependencies(detcont);
    // compute detector types then
    for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
        if (isSource(**i, detcont, sourcesStrict)) {
            (*i)->setType(SOURCE_DETECTOR);
            mySourceNumber++;
        }
        if (isDestination(**i, detcont)) {
            (*i)->setType(SINK_DETECTOR);
            mySinkNumber++;
        }
        if ((*i)->getType() == TYPE_NOT_DEFINED) {
            (*i)->setType(BETWEEN_DETECTOR);
            myInBetweenNumber++;
        }
    }
    // recheck sources
    for (std::vector< RODFDetector*>::const_iterator i = dets.begin(); i != dets.end(); ++i) {
        if ((*i)->getType() == SOURCE_DETECTOR && isFalseSource(**i, detcont)) {
            (*i)->setType(DISCARDED_DETECTOR);
            myInvalidNumber++;
            mySourceNumber--;
        }
    }
    // print results
    PROGRESS_DONE_MESSAGE();
    WRITE_MESSAGE("Computed detector types:");
    WRITE_MESSAGE(" " + toString(mySourceNumber) + " source detectors");
    WRITE_MESSAGE(" " + toString(mySinkNumber) + " sink detectors");
    WRITE_MESSAGE(" " + toString(myInBetweenNumber) + " in-between detectors");
    WRITE_MESSAGE(" " + toString(myInvalidNumber) + " invalid detectors");
}
Ejemplo n.º 3
0
bool
RODFNet::isDestination(const RODFDetector& det, ROEdge* edge, std::vector<ROEdge*>& seen,
                       const RODFDetectorCon& detectors) const {
    if (seen.size() == 1000) { // !!!
        WRITE_WARNING("Quitting checking for being a destination for detector '" + det.getID() + "' due to seen edge limit.");
        return false;
    }
    if (edge == getDetectorEdge(det)) {
        // maybe there is another detector at the same edge
        //  get the list of this/these detector(s)
        const std::vector<std::string>& detsOnEdge = myDetectorsOnEdges.find(edge)->second;
        for (std::vector<std::string>::const_iterator i = detsOnEdge.begin(); i != detsOnEdge.end(); ++i) {
            if ((*i) == det.getID()) {
                continue;
            }
            const RODFDetector& sec = detectors.getDetector(*i);
            if (getAbsPos(sec) > getAbsPos(det)) {
                // ok, there is another detector on the same edge and it is
                //  after this one -> no destination
                return false;
            }
        }
    }
    if (!hasApproached(edge)) {
        if (edge != getDetectorEdge(det)) {
            if (hasDetector(edge)) {
                return false;
            }
        }
        return true;
    }
    if (edge != getDetectorEdge(det)) {
        // ok, we are at one of the edges coming behind
        if (myAmInHighwayMode) {
            if (edge->getSpeed() >= 19.4) {
                if (hasDetector(edge)) {
                    // we are still on the highway and there is another detector
                    return false;
                }
            }
        }
    }

    if (myAmInHighwayMode) {
        if (edge->getSpeed() < 19.4 && edge != getDetectorEdge(det)) {
            if (hasDetector(edge)) {
                return true;
            }
            if (myApproachedEdges.find(edge)->second.size() > 1) {
                return true;
            }

        }
    }

    if (myDetectorsOnEdges.find(edge) != myDetectorsOnEdges.end()
            &&
            myDetectorEdges.find(det.getID())->second != edge) {
        return false;
    }
    const std::vector<ROEdge*>& appr  = myApproachedEdges.find(edge)->second;
    bool isall = true;
    size_t no = 0;
    seen.push_back(edge);
    for (size_t i = 0; i < appr.size() && isall; i++) {
        bool had = std::find(seen.begin(), seen.end(), appr[i]) != seen.end();
        if (!had) {
            if (!isDestination(det, appr[i], seen, detectors)) {
                no++;
                isall = false;
            }
        }
    }
    return isall;
}
Ejemplo n.º 4
0
bool
RODFNet::isDestination(const RODFDetector& det, const RODFDetectorCon& detectors) const {
    std::vector<ROEdge*> seen;
    return isDestination(det, getDetectorEdge(det), seen, detectors);
}
Ejemplo n.º 5
0
int processODRmsg(struct ODRmsg *m, struct sockaddr *sa)
{
	int gr = 0, s = 0;
	char temp[16];
	struct demux *found;
	struct sockaddr_ll *sall;
	struct ODRmsg msg, RREP, RREQ;

	sall = (struct sockaddr_ll *) sa;
	
	msg = *m;
	
	if(msg.type == 0)
	{
		printf("Received RREQ\n");
		
		//Update the routing table with information about the neighbor
		updateTable(msg.src_ip, neighbor, sall->sll_ifindex, ntohs(msg.hopcount), ntohs(msg.forced_discovery));
		
		//If we're the destination, send an RREP
		if(isDestination(msg.dest_ip))
		{
			//Send an RREP to your neighbor
			if(ntohs(msg.RREPsent) == 0)
			{
				strncpy(RREP.src_ip, canonical, 16);
				strncpy(RREP.dest_ip, msg.src_ip, 16);
				RREP.hopcount = msg.hopcount;
				RREP.forced_discovery = msg.forced_discovery;
				sendRREP(RREP, sall->sll_ifindex, -1, msg.forced_discovery);
			}
			else
				printf("RREP already sent, do nothing\n");
		}
		else
		{
			//Check for a route in the table
			gr = gotFreshRoute(msg.dest_ip);
			if(gr == -1) //If there's no route in the table, send an RREQ
				sendRREQ(msg, sall->sll_ifindex, msg.forced_discovery, 0);
			else //If there's a fresh route, send an RREP
			{
				if(ntohs(msg.RREPsent) == 0)
				{
					strncpy(RREP.src_ip, msg.dest_ip, 16);
					strncpy(RREP.dest_ip, msg.src_ip, 16);
					RREP.hopcount = routing_table[gr].hops;
					RREP.forced_discovery = msg.forced_discovery;
					sendRREP(RREP, sall->sll_ifindex, -1, msg.forced_discovery);
				}
				else
					printf("RREP already sent, do nothing\n");
			}
		}
	}
	else if(msg.type == 1)
	{
		printf("Received RREP\n");
		
		//Update the table
		updateTable(msg.src_ip , neighbor, sall->sll_ifindex, ntohs(msg.hopcount), ntohs(msg.forced_discovery)); //src_ip or dest_ip?
		
		if(!isDestination(msg.dest_ip))
		{
			//If you have a route, forward the RREP
			gr = gotFreshRoute(msg.dest_ip);
			if(gr != -1)
				sendRREP(RREP, routing_table[gr].index, gr, msg.forced_discovery);
			else
				printf("No route?\n");
		}
	}
	else if(msg.type == 2)
	{
		printf("Received application payload\n");
		
		//Update the table
		updateTable(msg.src_ip, neighbor, sall->sll_ifindex, ntohs(msg.hopcount), ntohs(msg.forced_discovery)); //src_ip or dest_ip?
		
		//If this is the destination of the app payload, send it to the peer process
		if(isDestination(msg.dest_ip))
		{
			printf("Forwarding to peer process\n");
			sendtoDest(msg);
		}
		else
		{
			//Find a route
			gr = gotFreshRoute(msg.dest_ip);
			if(gr != -1)
			{
				//If there's no route, send an RREQ, wait for an RREP, and forward the message
				strncpy(RREQ.src_ip, canonical, 16);
				strncpy(RREQ.dest_ip, msg.dest_ip, 16);
				RREQ.hopcount = htons(0);
				sendRREQ(RREQ, sall->sll_ifindex, -1, 1);
				if(waitforRREP(msg.dest_ip) == 0)
					sendAPPmsg(&msg, gr);
				else
					printf("waitforRREP failed\n");
			}
			else
				sendAPPmsg(&msg, gr);
		}
	}
	else
		printf("Message has invalid type: %d\n", ntohs(msg.type));
	
	return 0;
}
void AStarSearch::getRoute(MineMap* m, Point &start, Point &dest, list<Point> &route,
	TCheckFunction checkFunc, char* forbidCells)
{
	list<Node>* frontier = new list<Node>();
	
	if (lookupField == NULL)
		this->initLookupField(m->GetWidth(), m->GetHeight());
	else
		this->eraseLookupField();

	//Destination
	Node d = Node(dest.x, dest.y);
	//Start position
	Node s = Node(start.x, start.y);
	//Initialization
	s.heuristic = this->getManhattenDistance(s, d);
	d.heuristic = 0;
	//Add neighbors for start node
 	this->addPossibleNeighbors(m, s, d, *frontier, checkFunc, forbidCells);
	lookupField[s.y][s.x] = s;
	lookupField[s.y][s.x].isDiscovered = true;

	bool frontierChanged = true;
	bool success = false;
	int prevSize = -1;

	int i = 0;
	while (frontier->size() && (frontierChanged))
	{
		Node n = getOptimalNode(*frontier);
		if (!isDestination(n, d))
		{
			prevSize = frontier->size();
			//into frontier add possible neighbours
			bool isAdded = addPossibleNeighbors(m, n, d, *frontier, checkFunc, forbidCells);
			this->removeNodeFromFrontier(n, *frontier);
			bool isSizeChanged = prevSize != frontier->size();
			frontierChanged = isAdded || isSizeChanged;
		}
		else
		{
			//We found our goal!
			d.cost = n.cost;
			d.heuristic = n.heuristic;
			d.father_x = n.father_x;
			d.father_y = n.father_y;
			success = true;

			break;
		}
	}

	if (success)
	{
		Node tmp = d;
		//Reconstructing path
		while(!isStart(tmp, s))
		{
			route.push_front(Point(tmp.x, tmp.y));
			tmp = lookupField[tmp.father_y][tmp.father_x];
		}
	}

	frontier->clear();
	delete frontier;
}