bool NBTrafficLightDefinition::foes(const NBEdge* const from1, const NBEdge* const to1, const NBEdge* const from2, const NBEdge* const to2) const { if (to1 == 0 || to2 == 0) { return false; } // retrieve both nodes (it is possible that a connection std::vector<NBNode*>::const_iterator incoming = find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_incoming_finder(from1)); std::vector<NBNode*>::const_iterator outgoing = find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_outgoing_finder(to1)); assert(incoming != myControlledNodes.end()); NBNode* incnode = *incoming; NBNode* outnode = *outgoing; if (incnode != outnode) { return false; } return incnode->foes(from1, to1, from2, to2); }
bool NBTrafficLightDefinition::forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo, const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo, bool regardNonSignalisedLowerPriority, bool sameNodeOnly) const { if (possProhibitorFrom == 0 || possProhibitorTo == 0 || possProhibitedFrom == 0 || possProhibitedTo == 0) { return false; } // retrieve both nodes std::vector<NBNode*>::const_iterator incoming = find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_incoming_finder(possProhibitorFrom)); std::vector<NBNode*>::const_iterator outgoing = find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_outgoing_finder(possProhibitedTo)); assert(incoming != myControlledNodes.end()); NBNode* incnode = *incoming; NBNode* outnode = *outgoing; EdgeVector::const_iterator i; if (incnode != outnode) { if (sameNodeOnly) { return false; } // the links are located at different nodes const EdgeVector& ev1 = possProhibitedTo->getConnectedEdges(); // go through the following edge, // check whether one of these connections is prohibited for (i = ev1.begin(); i != ev1.end(); ++i) { std::vector<NBNode*>::const_iterator outgoing2 = find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_outgoing_finder(*i)); if (outgoing2 == myControlledNodes.end()) { continue; } NBNode* outnode2 = *outgoing2; if (incnode != outnode2) { continue; } if (incnode->getDirection(possProhibitedTo, *i) != LINKDIR_STRAIGHT) { continue; } bool ret1 = incnode->foes(possProhibitorFrom, possProhibitorTo, possProhibitedTo, *i); bool ret2 = incnode->forbids(possProhibitorFrom, possProhibitorTo, possProhibitedTo, *i, regardNonSignalisedLowerPriority); bool ret = ret1 || ret2; if (ret) { return true; } } const EdgeVector& ev2 = possProhibitorTo->getConnectedEdges(); // go through the following edge, // check whether one of these connections is prohibited for (i = ev2.begin(); i != ev2.end(); ++i) { std::vector<NBNode*>::const_iterator incoming2 = find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_incoming_finder(possProhibitorTo)); if (incoming2 == myControlledNodes.end()) { continue; } NBNode* incnode2 = *incoming2; if (incnode2 != outnode) { continue; } if (incnode2->getDirection(possProhibitorTo, *i) != LINKDIR_STRAIGHT) { continue; } bool ret1 = incnode2->foes(possProhibitorTo, *i, possProhibitedFrom, possProhibitedTo); bool ret2 = incnode2->forbids(possProhibitorTo, *i, possProhibitedFrom, possProhibitedTo, regardNonSignalisedLowerPriority); bool ret = ret1 || ret2; if (ret) { return true; } } return false; } // both links are located at the same node // check using this node's information return incnode->forbids(possProhibitorFrom, possProhibitorTo, possProhibitedFrom, possProhibitedTo, regardNonSignalisedLowerPriority); }