std::string NBRequest::getFoesString(NBEdge* from, NBEdge* to, int toLane, const bool checkLaneFoes) const { // remember the case when the lane is a "dead end" in the meaning that // vehicles must choose another lane to move over the following // junction // !!! move to forbidden std::string result; for (EdgeVector::const_reverse_iterator i = myIncoming.rbegin(); i != myIncoming.rend(); i++) { unsigned int noLanes = (*i)->getNumLanes(); for (unsigned int j = noLanes; j-- > 0;) { std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j); int size = (int) connected.size(); for (int k = size; k-- > 0;) { if (foes(from, to, (*i), connected[k].toEdge) && (!checkLaneFoes || laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane))) { result += '1'; } else { result += '0'; } } } } return result; }
SUMOReal NBOwnTLDef::computeUnblockedWeightedStreamNumber(const NBEdge* const e1, const NBEdge* const e2) { SUMOReal val = 0; for (unsigned int e1l = 0; e1l < e1->getNumLanes(); e1l++) { std::vector<NBEdge::Connection> approached1 = e1->getConnectionsFromLane(e1l); for (unsigned int e2l = 0; e2l < e2->getNumLanes(); e2l++) { std::vector<NBEdge::Connection> approached2 = e2->getConnectionsFromLane(e2l); for (std::vector<NBEdge::Connection>::iterator e1c = approached1.begin(); e1c != approached1.end(); ++e1c) { if (e1->getTurnDestination() == (*e1c).toEdge) { continue; } for (std::vector<NBEdge::Connection>::iterator e2c = approached2.begin(); e2c != approached2.end(); ++e2c) { if (e2->getTurnDestination() == (*e2c).toEdge) { continue; } if (!foes(e1, (*e1c).toEdge, e2, (*e2c).toEdge)) { val += getDirectionalWeight(e1->getToNode()->getDirection(e1, (*e1c).toEdge)); val += getDirectionalWeight(e2->getToNode()->getDirection(e2, (*e2c).toEdge)); } } } } } return val; }
void NBRequest::resetSignalised() { // go through possible prohibitions for (EdgeVector::const_iterator i11 = myIncoming.begin(); i11 != myIncoming.end(); i11++) { unsigned int noLanesEdge1 = (*i11)->getNumLanes(); for (unsigned int j1 = 0; j1 < noLanesEdge1; j1++) { std::vector<NBEdge::Connection> el1 = (*i11)->getConnectionsFromLane(j1); for (std::vector<NBEdge::Connection>::iterator i12 = el1.begin(); i12 != el1.end(); ++i12) { int idx1 = getIndex((*i11), (*i12).toEdge); if (idx1 < 0) { continue; } // go through possibly prohibited for (EdgeVector::const_iterator i21 = myIncoming.begin(); i21 != myIncoming.end(); i21++) { unsigned int noLanesEdge2 = (*i21)->getNumLanes(); for (unsigned int j2 = 0; j2 < noLanesEdge2; j2++) { std::vector<NBEdge::Connection> el2 = (*i21)->getConnectionsFromLane(j2); for (std::vector<NBEdge::Connection>::iterator i22 = el2.begin(); i22 != el2.end(); i22++) { int idx2 = getIndex((*i21), (*i22).toEdge); if (idx2 < 0) { continue; } // check // same incoming connections do not prohibit each other if ((*i11) == (*i21)) { myForbids[idx1][idx2] = false; myForbids[idx2][idx1] = false; continue; } // check other // if both are non-signalised or both are signalised if (((*i12).tlID == "" && (*i22).tlID == "") || ((*i12).tlID != "" && (*i22).tlID != "")) { // do nothing continue; } // supposing, we don not have to // brake if we are no foes if (!foes(*i11, (*i12).toEdge, *i21, (*i22).toEdge)) { continue; } // otherwise: // the non-signalised must break if ((*i12).tlID != "") { myForbids[idx1][idx2] = true; myForbids[idx2][idx1] = false; } else { myForbids[idx1][idx2] = false; myForbids[idx2][idx1] = true; } } } } } } } }
void NBLoadedSUMOTLDef::initNeedsContRelation() const { if (!amInvalid() && !myNeedsContRelationReady) { myNeedsContRelation.clear(); myRightOnRedConflicts.clear(); const bool controlledWithin = !OptionsCont::getOptions().getBool("tls.uncontrolled-within"); const std::vector<NBTrafficLightLogic::PhaseDefinition> phases = myTLLogic->getPhases(); for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) { const std::string state = (*it).state; for (NBConnectionVector::const_iterator it1 = myControlledLinks.begin(); it1 != myControlledLinks.end(); it1++) { const NBConnection& c1 = *it1; const int i1 = c1.getTLIndex(); if (i1 == NBConnection::InvalidTlIndex || state[i1] != 'g' || c1.getFrom() == 0 || c1.getTo() == 0) { continue; } for (NBConnectionVector::const_iterator it2 = myControlledLinks.begin(); it2 != myControlledLinks.end(); it2++) { const NBConnection& c2 = *it2; const int i2 = c2.getTLIndex(); if (i2 != NBConnection::InvalidTlIndex && i2 != i1 && (state[i2] == 'G' || state[i2] == 'g') && c2.getFrom() != 0 && c2.getTo() != 0) { const bool rightTurnConflict = NBNode::rightTurnConflict( c1.getFrom(), c1.getTo(), c1.getFromLane(), c2.getFrom(), c2.getTo(), c2.getFromLane()); const bool forbidden = forbids(c2.getFrom(), c2.getTo(), c1.getFrom(), c1.getTo(), true, controlledWithin); const bool isFoes = foes(c2.getFrom(), c2.getTo(), c1.getFrom(), c1.getTo()); if (forbidden || rightTurnConflict) { myNeedsContRelation.insert(StreamPair(c1.getFrom(), c1.getTo(), c2.getFrom(), c2.getTo())); } if (isFoes) { myRightOnRedConflicts.insert(std::make_pair(i1, i2)); } //std::cout << getID() << " i1=" << i1 << " i2=" << i2 << " rightTurnConflict=" << rightTurnConflict << " forbidden=" << forbidden << " isFoes=" << isFoes << "\n"; } } } } } myNeedsContRelationReady = true; myRightOnRedConflictsReady = true; }