53 #ifdef CHECK_MEMORY_LEAKS
55 #endif // CHECK_MEMORY_LEAKS
78 myCrossings(junction->getCrossings()) {
79 const size_t variations =
numLinks();
83 myDone.reserve(variations);
84 for (
size_t i = 0; i < variations; i++) {
89 for (NBConnectionProhibits::const_iterator j = loadedProhibits.begin(); j != loadedProhibits.end(); j++) {
91 bool ok1 = prohibited.
check(ec);
106 for (NBConnectionVector::const_iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
108 bool ok2 = sprohibiting.
check(ec);
121 myDone[idx2][idx1] =
true;
122 myDone[idx1][idx2] =
true;
127 std::string ptID = prohibited.
getTo() != 0 ? prohibited.
getTo()->
getID() :
"UNKNOWN";
128 std::string bfID = sprohibiting.
getFrom() != 0 ? sprohibiting.
getFrom()->
getID() :
"UNKNOWN";
129 std::string btID = sprohibiting.
getTo() != 0 ? sprohibiting.
getTo()->
getID() :
"UNKNOWN";
130 WRITE_WARNING(
"could not prohibit " + pfID +
"->" + ptID +
" by " + bfID +
"->" + btID);
137 for (
size_t s1 = 0; s1 < variations; s1++) {
138 for (
size_t s2 = s1 + 1; s2 < variations; s2++) {
159 EdgeVector::const_iterator i, j;
175 EdgeVector::const_iterator pfrom = find(
myAll.begin(),
myAll.end(), from);
176 while (*pfrom != to) {
179 EdgeVector::const_iterator pto = find(
myAll.begin(),
myAll.end(), to);
180 while (*pto != from) {
193 EdgeVector::const_iterator pfrom = find(
myAll.begin(),
myAll.end(), from);
194 while (*pfrom != to) {
197 EdgeVector::const_iterator pto = find(
myAll.begin(),
myAll.end(), to);
198 while (*pto != from) {
214 if (to1 == 0 || to2 == 0) {
220 if (idx1 < 0 || idx2 < 0) {
229 myDone[idx1][idx2] =
true;
230 myDone[idx2][idx1] =
true;
254 if (from1p > from2p) {
258 if (from2p > from1p) {
286 EdgeVector::const_iterator c1 = find(
myAll.begin(),
myAll.end(), from1);
289 while (*c1 != from1 && *c1 != from2) {
299 NBContHelper::nextCW(
myAll, c1);
302 EdgeVector::const_iterator c2 = find(
myAll.begin(),
myAll.end(), from2);
303 NBContHelper::nextCW(
myAll, c2);
305 while (*c2 != from2 && *c2 != from1) {
315 NBContHelper::nextCW(
myAll, c2);
322 EdgeVector::const_iterator p = find(
myAll.begin(),
myAll.end(), from);
326 if (p ==
myAll.begin()) {
338 EdgeVector::const_iterator i;
341 unsigned int noLanes = (*i)->getNumLanes();
342 for (
unsigned int k = 0; k < noLanes; k++) {
347 for (std::vector<NBNode::Crossing>::const_iterator i =
myCrossings.begin(); i !=
myCrossings.end(); i++) {
357 unsigned int noLanesEdge1 = (*i11)->getNumLanes();
358 for (
unsigned int j1 = 0; j1 < noLanesEdge1; j1++) {
359 std::vector<NBEdge::Connection> el1 = (*i11)->getConnectionsFromLane(j1);
360 for (std::vector<NBEdge::Connection>::iterator i12 = el1.begin(); i12 != el1.end(); ++i12) {
361 int idx1 =
getIndex((*i11), (*i12).toEdge);
367 unsigned int noLanesEdge2 = (*i21)->getNumLanes();
368 for (
unsigned int j2 = 0; j2 < noLanesEdge2; j2++) {
369 std::vector<NBEdge::Connection> el2 = (*i21)->getConnectionsFromLane(j2);
370 for (std::vector<NBEdge::Connection>::iterator i22 = el2.begin(); i22 != el2.end(); i22++) {
371 int idx2 =
getIndex((*i21), (*i22).toEdge);
377 if ((*i11) == (*i21)) {
384 if (((*i12).tlID ==
"" && (*i22).tlID ==
"")
386 ((*i12).tlID !=
"" && (*i22).tlID !=
"")) {
392 if (!
foes(*i11, (*i12).toEdge, *i21, (*i22).toEdge)) {
397 if ((*i12).tlID !=
"") {
413 std::pair<unsigned int, unsigned int>
415 unsigned int noLanes = 0;
416 unsigned int noLinks = 0;
417 for (EdgeVector::const_iterator i =
myIncoming.begin();
419 unsigned int noLanesEdge = (*i)->getNumLanes();
420 for (
unsigned int j = 0; j < noLanesEdge; j++) {
421 unsigned int numConnections = (
unsigned int)(*i)->getConnectionsFromLane(j).size();
422 noLinks += numConnections;
423 if (numConnections > 0) {
428 return std::make_pair(noLanes, noLinks);
434 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
436 if (to1 == 0 || to2 == 0) {
442 if (idx1 < 0 || idx2 < 0) {
453 const NBEdge*
const possProhibitedFrom,
const NBEdge*
const possProhibitedTo,
454 bool regardNonSignalisedLowerPriority)
const {
456 if (possProhibitorTo == 0 || possProhibitedTo == 0) {
460 int possProhibitorIdx =
getIndex(possProhibitorFrom, possProhibitorTo);
461 int possProhibitedIdx =
getIndex(possProhibitedFrom, possProhibitedTo);
462 if (possProhibitorIdx < 0 || possProhibitedIdx < 0) {
468 if (!regardNonSignalisedLowerPriority) {
469 return myForbids[possProhibitorIdx][possProhibitedIdx];
472 if (!
myForbids[possProhibitorIdx][possProhibitedIdx]) {
485 int fromLane,
int pos,
const bool checkLaneFoes)
const {
487 for (std::vector<NBEdge::Connection>::iterator j = connected.begin(); j != connected.end(); j++) {
488 assert((*j).toEdge != 0);
511 for (
int j = noLanes; j-- > 0;) {
513 int size = (
int) connected.size();
514 for (
int k = size; k-- > 0;) {
515 const NBEdge* to = connected[k].toEdge;
517 for (EdgeVector::const_iterator it_e = crossing.
edges.begin(); it_e != crossing.
edges.end(); ++it_e) {
518 if ((*it_e) == from || (*it_e) == to) {
523 foes += foe ?
'1' :
'0';
540 int fromLane,
int toLane,
bool mayDefinitelyPass,
const bool checkLaneFoes)
const {
547 for (std::vector<NBNode::Crossing>::const_reverse_iterator i =
myCrossings.rbegin(); i !=
myCrossings.rend(); i++) {
553 unsigned int noLanes = (*i)->getNumLanes();
554 for (
int j = noLanes; j-- > 0;) {
555 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
556 int size = (
int) connected.size();
557 for (
int k = size; k-- > 0;) {
558 if (mayDefinitelyPass) {
560 }
else if ((*i) == from && fromLane == j) {
564 assert(k < (
int) connected.size());
566 assert(connected[k].toEdge != 0);
570 (!checkLaneFoes ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane)))
571 ||
rightTurnConflict(from, to, fromLane, *i, connected[k].toEdge, connected[k].fromLane)) {
592 for (std::vector<NBNode::Crossing>::const_reverse_iterator i =
myCrossings.rbegin(); i !=
myCrossings.rend(); i++) {
594 for (EdgeVector::const_iterator it_e = (*i).edges.begin(); it_e != (*i).edges.end(); ++it_e) {
595 if ((*it_e) == from || (*it_e) == to) {
600 result += foes ?
'1' :
'0';
603 for (EdgeVector::const_reverse_iterator i =
myIncoming.rbegin();
606 for (
int j = (
int)(*i)->getNumLanes() - 1; j >= 0; --j) {
607 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
608 int size = (
int) connected.size();
609 for (
int k = size; k-- > 0;) {
610 if ((
foes(from, to, (*i), connected[k].toEdge) &&
611 (!checkLaneFoes ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane)))
612 ||
rightTurnConflict(from, to, fromLane, *i, connected[k].toEdge, connected[k].fromLane)) {
626 const NBEdge* prohibitorFrom,
const NBEdge* prohibitorTo,
int prohibitorToLane)
const {
627 if (to != prohibitorTo) {
642 return rightOfProhibitor ? toLane >= prohibitorToLane : toLane <= prohibitorToLane;
648 const NBEdge* prohibitorFrom,
const NBEdge* prohibitorTo,
int prohibitorFromLane)
const {
649 if (from != prohibitorFrom) {
657 if ((!lefthand && fromLane <= prohibitorFromLane) ||
658 (lefthand && fromLane >= prohibitorFromLane)) {
684 for (
size_t i = 0; i < variations; i++) {
686 for (
size_t j = 0; j < variations; j++) {
714 for (
size_t idx1 = 0; idx1 <
numLinks(); idx1++) {
721 for (std::vector<NBNode::Crossing>::const_reverse_iterator i =
myCrossings.rbegin(); i !=
myCrossings.rend(); i++) {
733 if (crossing.
priority || mustYield) {
734 for (EdgeVector::const_iterator it_e = crossing.
edges.begin(); it_e != crossing.
edges.end(); ++it_e) {
736 if (((*it_e) == from && crossing.
priority) || (*it_e) == to) {
747 const NBEdge*
const possProhibitedFrom,
const NBEdge*
const possProhibitedTo)
const {
749 int idx1 =
getIndex(possProhibitorFrom, possProhibitorTo);
750 int idx2 =
getIndex(possProhibitedFrom, possProhibitedTo);
767 std::map<NBEdge*, size_t> incomingCount;
769 std::map<NBEdge*, std::set<int> > approachedLanes;
771 std::map<NBEdge*, EdgeVector> incomingEdges;
773 const std::vector<NBEdge::Connection> connections = (*it_e)->getConnections();
774 for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); ++it_c) {
775 incomingCount[it_c->toEdge]++;
776 approachedLanes[it_c->toEdge].insert(it_c->toLane);
777 incomingEdges[it_c->toEdge].push_back(*it_e);
780 for (std::map<NBEdge*, size_t>::iterator it = incomingCount.begin(); it != incomingCount.end(); ++it) {
783 if (approachedLanes[to].size() >= it->second) {
786 for (EdgeVector::iterator it_e1 = incoming.begin(); it_e1 != incoming.end(); ++it_e1) {
787 for (EdgeVector::iterator it_e2 = incoming.begin(); it_e2 != incoming.end(); ++it_e2) {