53 #ifdef CHECK_MEMORY_LEAKS
55 #endif // CHECK_MEMORY_LEAKS
74 : myJunction(junction),
75 myAll(all), myIncoming(incoming), myOutgoing(outgoing) {
80 myDone.reserve(variations);
81 for (
size_t i = 0; i < variations; i++) {
86 for (NBConnectionProhibits::const_iterator j = loadedProhibits.begin(); j != loadedProhibits.end(); j++) {
88 bool ok1 = prohibited.
check(ec);
103 for (NBConnectionVector::const_iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
105 bool ok2 = sprohibiting.
check(ec);
118 myDone[idx2][idx1] =
true;
119 myDone[idx1][idx2] =
true;
124 std::string ptID = prohibited.
getTo() != 0 ? prohibited.
getTo()->
getID() :
"UNKNOWN";
125 std::string bfID = sprohibiting.
getFrom() != 0 ? sprohibiting.
getFrom()->
getID() :
"UNKNOWN";
126 std::string btID = sprohibiting.
getTo() != 0 ? sprohibiting.
getTo()->
getID() :
"UNKNOWN";
127 WRITE_WARNING(
"could not prohibit " + pfID +
"->" + ptID +
" by " + bfID +
"->" + btID);
135 for (
size_t s1 = 0; s1 < no; s1++) {
136 for (
size_t s2 = s1 + 1; s2 < no; s2++) {
157 EdgeVector::const_iterator i, j;
173 EdgeVector::const_iterator pfrom = find(
myAll.begin(),
myAll.end(), from);
174 while (*pfrom != to) {
177 EdgeVector::const_iterator pto = find(
myAll.begin(),
myAll.end(), to);
178 while (*pto != from) {
191 EdgeVector::const_iterator pfrom = find(
myAll.begin(),
myAll.end(), from);
192 while (*pfrom != to) {
195 EdgeVector::const_iterator pto = find(
myAll.begin(),
myAll.end(), to);
196 while (*pto != from) {
212 if (to1 == 0 || to2 == 0) {
218 if (idx1 < 0 || idx2 < 0) {
227 myDone[idx1][idx2] =
true;
228 myDone[idx2][idx1] =
true;
252 if (from1p > from2p) {
256 if (from2p > from1p) {
284 EdgeVector::const_iterator c1 = find(
myAll.begin(),
myAll.end(), from1);
287 while (*c1 != from1 && *c1 != from2) {
300 EdgeVector::const_iterator c2 = find(
myAll.begin(),
myAll.end(), from2);
303 while (*c2 != from2 && *c2 != from1) {
320 EdgeVector::const_iterator p = find(
myAll.begin(),
myAll.end(), from);
324 if (p ==
myAll.begin()) {
336 EdgeVector::const_iterator i;
338 unsigned int noLanes = (*i)->getNumLanes();
339 for (
unsigned int k = 0; k < noLanes; k++) {
350 unsigned int noLanesEdge1 = (*i11)->getNumLanes();
351 for (
unsigned int j1 = 0; j1 < noLanesEdge1; j1++) {
352 std::vector<NBEdge::Connection> el1 = (*i11)->getConnectionsFromLane(j1);
353 for (std::vector<NBEdge::Connection>::iterator i12 = el1.begin(); i12 != el1.end(); ++i12) {
354 int idx1 =
getIndex((*i11), (*i12).toEdge);
360 unsigned int noLanesEdge2 = (*i21)->getNumLanes();
361 for (
unsigned int j2 = 0; j2 < noLanesEdge2; j2++) {
362 std::vector<NBEdge::Connection> el2 = (*i21)->getConnectionsFromLane(j2);
363 for (std::vector<NBEdge::Connection>::iterator i22 = el2.begin(); i22 != el2.end(); i22++) {
364 int idx2 =
getIndex((*i21), (*i22).toEdge);
370 if ((*i11) == (*i21)) {
377 if (((*i12).tlID ==
"" && (*i22).tlID ==
"")
379 ((*i12).tlID !=
"" && (*i22).tlID !=
"")) {
385 if (!
foes(*i11, (*i12).toEdge, *i21, (*i22).toEdge)) {
390 if ((*i12).tlID !=
"") {
406 std::pair<unsigned int, unsigned int>
408 unsigned int noLanes = 0;
409 unsigned int noLinks = 0;
410 for (EdgeVector::const_iterator i =
myIncoming.begin();
412 unsigned int noLanesEdge = (*i)->getNumLanes();
413 for (
unsigned int j = 0; j < noLanesEdge; j++) {
414 unsigned int numConnections = (
unsigned int)(*i)->getConnectionsFromLane(j).size();
415 noLinks += numConnections;
416 if (numConnections > 0) {
421 return std::make_pair(noLanes, noLinks);
427 const NBEdge*
const from2,
const NBEdge*
const to2)
const {
429 if (to1 == 0 || to2 == 0) {
435 if (idx1 < 0 || idx2 < 0) {
446 const NBEdge*
const possProhibitedFrom,
const NBEdge*
const possProhibitedTo,
447 bool regardNonSignalisedLowerPriority)
const {
449 if (possProhibitorTo == 0 || possProhibitedTo == 0) {
453 int possProhibitorIdx =
getIndex(possProhibitorFrom, possProhibitorTo);
454 int possProhibitedIdx =
getIndex(possProhibitedFrom, possProhibitedTo);
455 if (possProhibitorIdx < 0 || possProhibitedIdx < 0) {
461 if (!regardNonSignalisedLowerPriority) {
462 return myForbids[possProhibitorIdx][possProhibitedIdx];
465 if (!
myForbids[possProhibitorIdx][possProhibitedIdx]) {
478 int fromLane,
int pos,
const bool checkLaneFoes)
const {
480 for (std::vector<NBEdge::Connection>::iterator j = connected.begin(); j != connected.end(); j++) {
481 assert((*j).toEdge != 0);
497 int fromLane,
int toLane,
bool mayDefinitelyPass,
const bool checkLaneFoes)
const {
505 unsigned int noLanes = (*i)->getNumLanes();
506 for (
int j = noLanes; j-- > 0;) {
507 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
508 int size = (
int) connected.size();
509 for (
int k = size; k-- > 0;) {
510 if (mayDefinitelyPass) {
512 }
else if ((*i) == from && fromLane == j) {
516 assert(k < (
int) connected.size());
518 assert(connected[k].toEdge != 0);
522 (!checkLaneFoes ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane))) {
542 for (EdgeVector::const_reverse_iterator i =
myIncoming.rbegin();
545 unsigned int noLanes = (*i)->getNumLanes();
546 for (
unsigned int j = noLanes; j-- > 0;) {
547 std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
548 int size = (
int) connected.size();
549 for (
int k = size; k-- > 0;) {
550 if (
foes(from, to, (*i), connected[k].toEdge) &&
551 (!checkLaneFoes ||
laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane))) {
565 const NBEdge* prohibitorFrom,
const NBEdge* prohibitorTo,
int prohibitorToLane)
const {
566 if (to != prohibitorTo) {
581 return rightOfProhibitor ? toLane >= prohibitorToLane : toLane <= prohibitorToLane;
600 for (
size_t i = 0; i < variations; i++) {
602 for (
size_t j = 0; j < variations; j++) {
642 const NBEdge*
const possProhibitedFrom,
const NBEdge*
const possProhibitedTo)
const {
644 int idx1 =
getIndex(possProhibitorFrom, possProhibitorTo);
645 int idx2 =
getIndex(possProhibitedFrom, possProhibitedTo);
662 std::map<NBEdge*, size_t> incomingCount;
664 std::map<NBEdge*, std::set<int> > approachedLanes;
666 std::map<NBEdge*, EdgeVector> incomingEdges;
668 const std::vector<NBEdge::Connection> connections = (*it_e)->getConnections();
669 for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); ++it_c) {
670 incomingCount[it_c->toEdge]++;
671 approachedLanes[it_c->toEdge].insert(it_c->toLane);
672 incomingEdges[it_c->toEdge].push_back(*it_e);
675 for (std::map<NBEdge*, size_t>::iterator it = incomingCount.begin(); it != incomingCount.end(); ++it) {
678 if (approachedLanes[to].size() >= it->second) {
681 for (EdgeVector::iterator it_e1 = incoming.begin(); it_e1 != incoming.end(); ++it_e1) {
682 for (EdgeVector::iterator it_e2 = incoming.begin(); it_e2 != incoming.end(); ++it_e2) {