Eclipse SUMO - Simulation of Urban MObility
NBRequest.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // This class computes the logic of a junction
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include <string>
26 #include <vector>
27 #include <set>
28 #include <algorithm>
29 #include <bitset>
30 #include <sstream>
31 #include <map>
32 #include <cassert>
34 #include <utils/common/ToString.h>
37 #include "NBEdge.h"
38 #include "NBContHelper.h"
39 #include "NBNode.h"
40 #include "NBRequest.h"
41 
42 //#define DEBUG_RESPONSE
43 //#define DEBUG_SETBLOCKING
44 #define DEBUGCOND (myJunction->getID() == "C")
45 
46 // ===========================================================================
47 // static member variables
48 // ===========================================================================
50 int NBRequest::myNotBuild = 0;
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
57  NBNode* junction,
58  const EdgeVector& all,
59  const EdgeVector& incoming,
60  const EdgeVector& outgoing,
61  const NBConnectionProhibits& loadedProhibits) :
62  myJunction(junction),
63  myAll(all),
64  myIncoming(incoming),
65  myOutgoing(outgoing) {
66  const int variations = numLinks();
67  // build maps with information which forbidding connection were
68  // computed and what's in there
69  myForbids.reserve(variations);
70  myDone.reserve(variations);
71  for (int i = 0; i < variations; i++) {
72  myForbids.push_back(LinkInfoCont(variations, false));
73  myDone.push_back(LinkInfoCont(variations, false));
74  }
75  // insert loaded prohibits
76  for (NBConnectionProhibits::const_iterator j = loadedProhibits.begin(); j != loadedProhibits.end(); j++) {
77  NBConnection prohibited = (*j).first;
78  bool ok1 = prohibited.check(ec);
79  if (find(myIncoming.begin(), myIncoming.end(), prohibited.getFrom()) == myIncoming.end()) {
80  ok1 = false;
81  }
82  if (find(myOutgoing.begin(), myOutgoing.end(), prohibited.getTo()) == myOutgoing.end()) {
83  ok1 = false;
84  }
85  int idx1 = 0;
86  if (ok1) {
87  idx1 = getIndex(prohibited.getFrom(), prohibited.getTo());
88  if (idx1 < 0) {
89  ok1 = false;
90  }
91  }
92  const NBConnectionVector& prohibiting = (*j).second;
93  for (NBConnectionVector::const_iterator k = prohibiting.begin(); k != prohibiting.end(); k++) {
94  NBConnection sprohibiting = *k;
95  bool ok2 = sprohibiting.check(ec);
96  if (find(myIncoming.begin(), myIncoming.end(), sprohibiting.getFrom()) == myIncoming.end()) {
97  ok2 = false;
98  }
99  if (find(myOutgoing.begin(), myOutgoing.end(), sprohibiting.getTo()) == myOutgoing.end()) {
100  ok2 = false;
101  }
102  if (ok1 && ok2) {
103  int idx2 = getIndex(sprohibiting.getFrom(), sprohibiting.getTo());
104  if (idx2 < 0) {
105  ok2 = false;
106  } else {
107  myForbids[idx2][idx1] = true;
108  myDone[idx2][idx1] = true;
109  myDone[idx1][idx2] = true;
110  myGoodBuilds++;
111  }
112  } else {
113  std::string pfID = prohibited.getFrom() != nullptr ? prohibited.getFrom()->getID() : "UNKNOWN";
114  std::string ptID = prohibited.getTo() != nullptr ? prohibited.getTo()->getID() : "UNKNOWN";
115  std::string bfID = sprohibiting.getFrom() != nullptr ? sprohibiting.getFrom()->getID() : "UNKNOWN";
116  std::string btID = sprohibiting.getTo() != nullptr ? sprohibiting.getTo()->getID() : "UNKNOWN";
117  WRITE_WARNING("could not prohibit " + pfID + "->" + ptID + " by " + bfID + "->" + btID);
118  myNotBuild++;
119  }
120  }
121  }
122  // ok, check whether someone has prohibited two links vice versa
123  // (this happens also in some Vissim-networks, when edges are joined)
124  for (int s1 = 0; s1 < variations; s1++) {
125  for (int s2 = s1 + 1; s2 < variations; s2++) {
126  // not set, yet
127  if (!myDone[s1][s2]) {
128  continue;
129  }
130  // check whether both prohibit vice versa
131  if (myForbids[s1][s2] && myForbids[s2][s1]) {
132  // mark unset - let our algorithm fix it later
133  myDone[s1][s2] = false;
134  myDone[s2][s1] = false;
135  }
136  }
137  }
138 }
139 
140 
142 
143 
144 void
146  EdgeVector::const_iterator i, j;
147  for (i = myIncoming.begin(); i != myIncoming.end(); i++) {
148  for (j = myOutgoing.begin(); j != myOutgoing.end(); j++) {
151  }
152  }
153  // reset signalised/non-signalised dependencies
154  resetSignalised();
155  // reset foes it the number of lanes matches (or exceeds) the number of incoming connections
157 }
158 
159 
160 void
162  EdgeVector::const_iterator pfrom = std::find(myAll.begin(), myAll.end(), from);
163  while (*pfrom != to) {
165  if ((*pfrom)->getToNode() == myJunction) {
166  EdgeVector::const_iterator pto = std::find(myAll.begin(), myAll.end(), to);
167  while (*pto != from) {
168  if (!((*pto)->getToNode() == myJunction)) {
169  setBlocking(from, to, *pfrom, *pto);
170  }
172  }
173  }
174  }
175 }
176 
177 
178 void
180  EdgeVector::const_iterator pfrom = std::find(myAll.begin(), myAll.end(), from);
181  while (*pfrom != to) {
182  NBContHelper::nextCW(myAll, pfrom);
183  if ((*pfrom)->getToNode() == myJunction) {
184  EdgeVector::const_iterator pto = std::find(myAll.begin(), myAll.end(), to);
185  while (*pto != from) {
186  if (!((*pto)->getToNode() == myJunction)) {
187  setBlocking(from, to, *pfrom, *pto);
188  }
190  }
191  }
192  }
193 }
194 
195 
196 void
198  NBEdge* from2, NBEdge* to2) {
199  // check whether one of the links has a dead end
200  if (to1 == nullptr || to2 == nullptr) {
201  return;
202  }
203  // get the indices of both links
204  int idx1 = getIndex(from1, to1);
205  int idx2 = getIndex(from2, to2);
206  if (idx1 < 0 || idx2 < 0) {
207  return; // !!! error output? did not happend, yet
208  }
209  // check whether the link crossing has already been checked
210  assert(idx1 < (int)(myIncoming.size() * myOutgoing.size()));
211  if (myDone[idx1][idx2]) {
212  return;
213  }
214  // mark the crossings as done
215  myDone[idx1][idx2] = true;
216  myDone[idx2][idx1] = true;
217  // special case all-way stop
219  // all ways forbid each other. Conflict resolution happens via arrival time
220  myForbids[idx1][idx2] = true;
221  myForbids[idx2][idx1] = true;
222  return;
223  }
224  // check if one of the links is a turn; this link is always not priorised
225  // true for right-before-left and priority
226  if (from1->isTurningDirectionAt(to1)) {
227  myForbids[idx2][idx1] = true;
228  return;
229  }
230  if (from2->isTurningDirectionAt(to2)) {
231  myForbids[idx1][idx2] = true;
232  return;
233  }
234  // if there are no connections, there are no prohibitions
235  if (from1->isConnectedTo(to1)) {
236  if (!from2->isConnectedTo(to2)) {
237  myForbids[idx1][idx2] = true;
238  myForbids[idx2][idx1] = false;
239  return;
240  }
241  } else {
242  if (!from2->isConnectedTo(to2)) {
243  myForbids[idx1][idx2] = false;
244  myForbids[idx2][idx1] = false;
245  return;
246  } else {
247  myForbids[idx1][idx2] = false;
248  myForbids[idx2][idx1] = true;
249  return;
250  }
251  }
252 #ifdef DEBUG_SETBLOCKING
253  if (DEBUGCOND) std::cout << "setBlocking type=" << toString(myJunction->getType())
254  << " bentPrio=" << myJunction->isBentPriority()
255  << " 1:" << from1->getID() << "->" << to1->getID()
256  << " 2:" << from2->getID() << "->" << to2->getID() << "\n";
257 #endif
258  // check the priorities if required by node type
260  int from1p = from1->getJunctionPriority(myJunction);
261  int from2p = from2->getJunctionPriority(myJunction);
262 #ifdef DEBUG_SETBLOCKING
263  if (DEBUGCOND) {
264  std::cout << " p1=" << from1p << " p2=" << from2p << "\n";
265  }
266 #endif
267  // check if one of the connections is higher priorised when incoming into
268  // the junction, the connection road will yield
269  if (from1p > from2p) {
270  myForbids[idx1][idx2] = true;
271  return;
272  }
273  if (from2p > from1p) {
274  myForbids[idx2][idx1] = true;
275  return;
276  }
277  }
278  // straight connections prohibit turning connections if the priorities are equal
279  // (unless the junction is a bent priority junction)
281  LinkDirection ld1 = myJunction->getDirection(from1, to1);
282  LinkDirection ld2 = myJunction->getDirection(from2, to2);
283 #ifdef DEBUG_SETBLOCKING
284  if (DEBUGCOND) std::cout << "setBlocking"
285  << " 1:" << from1->getID() << "->" << to1->getID()
286  << " 2:" << from2->getID() << "->" << to2->getID()
287  << " dir1=" << toString(ld1) << " dir2=" << toString(ld2) << "\n";
288 #endif
289  if (ld1 == LinkDirection::STRAIGHT) {
290  if (ld2 != LinkDirection::STRAIGHT) {
291  myForbids[idx1][idx2] = true;
292  myForbids[idx2][idx1] = false;
293  return;
294  }
295  } else {
296  if (ld2 == LinkDirection::STRAIGHT) {
297  myForbids[idx1][idx2] = false;
298  myForbids[idx2][idx1] = true;
299  return;
300  }
301  }
302  }
303 
304  // check whether one of the connections is higher priorised on
305  // the outgoing edge when both roads are high priorised
306  // the connection with the lower priorised outgoing edge will lead
307  // should be valid for priority junctions only
308  /*
309  if (from1p > 0 && from2p > 0) {
310  assert(myJunction->getType() != SumoXMLNodeType::RIGHT_BEFORE_LEFT);
311  int to1p = to1->getJunctionPriority(myJunction);
312  int to2p = to2->getJunctionPriority(myJunction);
313  if (to1p > to2p) {
314  myForbids[idx1][idx2] = true;
315  return;
316  }
317  if (to2p > to1p) {
318  myForbids[idx2][idx1] = true;
319  return;
320  }
321  }
322  */
323 
324  // compute the yielding due to the right-before-left rule
325  // get the position of the incoming lanes in the junction-wheel
326  EdgeVector::const_iterator c1 = std::find(myAll.begin(), myAll.end(), from1);
328  // go through next edges clockwise...
329  while (*c1 != from1 && *c1 != from2) {
330  if (*c1 == to2) {
331  // if we encounter to2 the second one prohibits the first
332  myForbids[idx2][idx1] = true;
333  return;
334  }
336  }
337  // get the position of the incoming lanes in the junction-wheel
338  EdgeVector::const_iterator c2 = std::find(myAll.begin(), myAll.end(), from2);
340  // go through next edges clockwise...
341  while (*c2 != from2 && *c2 != from1) {
342  if (*c2 == to1) {
343  // if we encounter to1 the second one prohibits the first
344  myForbids[idx1][idx2] = true;
345  return;
346  }
348  }
349 #ifdef DEBUG_SETBLOCKING
350  if (DEBUGCOND) std::cout << "setBlocking"
351  << " 1:" << from1->getID() << "->" << to1->getID()
352  << " 2:" << from2->getID() << "->" << to2->getID()
353  << " noDecision\n";
354 #endif
355 }
356 
357 
358 int
360  EdgeVector::const_iterator p = std::find(myAll.begin(), myAll.end(), from);
361  int ret = 0;
362  do {
363  ret++;
364  if (p == myAll.begin()) {
365  p = myAll.end();
366  }
367  p--;
368  } while (*p != to);
369  return ret;
370 }
371 
372 const std::string&
373 NBRequest::getFoes(int linkIndex) const {
374  assert(linkIndex >= 0);
375  assert(linkIndex < (int)myFoes.size());
376  return myFoes[linkIndex];
377 }
378 
379 
380 const std::string&
381 NBRequest::getResponse(int linkIndex) const {
382  assert(linkIndex >= 0);
383  assert(linkIndex < (int)myResponse.size());
384  return myResponse[linkIndex];
385 }
386 
387 
388 void
390  int numLinks = (int)myResponse.size();
391  assert((int)myFoes.size() == numLinks);
392  assert((int)myHaveVia.size() == numLinks);
393  const bool padding = numLinks > 10;
394  for (int i = 0; i < numLinks; i++) {
396  into.writeAttr(SUMO_ATTR_INDEX, i);
397  if (padding && i < 10) {
398  into.writePadding(" ");
399  }
401  into.writeAttr(SUMO_ATTR_FOES, myFoes[i]);
402  if (!OptionsCont::getOptions().getBool("no-internal-links")) {
404  }
405  into.closeTag();
406  }
407 }
408 
409 
410 void
411 NBRequest::computeLogic(const bool checkLaneFoes) {
412  myResponse.clear();
413  myFoes.clear();
414  myHaveVia.clear();
415  int pos = 0;
416  EdgeVector::const_iterator i;
417  // normal connections
418  for (i = myIncoming.begin(); i != myIncoming.end(); i++) {
419  int noLanes = (*i)->getNumLanes();
420  for (int k = 0; k < noLanes; k++) {
421  pos = computeLaneResponse(*i, k, pos, checkLaneFoes || myJunction->getType() == SumoXMLNodeType::ZIPPER);
422  }
423  }
424  // crossings
425  auto crossings = myJunction->getCrossings();
426  for (auto c : crossings) {
427  pos = computeCrossingResponse(*c, pos);
428  }
429 }
430 
431 void
433  // go through possible prohibitions
434  for (EdgeVector::const_iterator i11 = myIncoming.begin(); i11 != myIncoming.end(); i11++) {
435  int noLanesEdge1 = (*i11)->getNumLanes();
436  for (int j1 = 0; j1 < noLanesEdge1; j1++) {
437  std::vector<NBEdge::Connection> el1 = (*i11)->getConnectionsFromLane(j1);
438  for (std::vector<NBEdge::Connection>::iterator i12 = el1.begin(); i12 != el1.end(); ++i12) {
439  int idx1 = getIndex((*i11), (*i12).toEdge);
440  if (idx1 < 0) {
441  continue;
442  }
443  // go through possibly prohibited
444  for (EdgeVector::const_iterator i21 = myIncoming.begin(); i21 != myIncoming.end(); i21++) {
445  int noLanesEdge2 = (*i21)->getNumLanes();
446  for (int j2 = 0; j2 < noLanesEdge2; j2++) {
447  std::vector<NBEdge::Connection> el2 = (*i21)->getConnectionsFromLane(j2);
448  for (std::vector<NBEdge::Connection>::iterator i22 = el2.begin(); i22 != el2.end(); i22++) {
449  int idx2 = getIndex((*i21), (*i22).toEdge);
450  if (idx2 < 0) {
451  continue;
452  }
453  // check
454  // same incoming connections do not prohibit each other
455  if ((*i11) == (*i21)) {
456  myForbids[idx1][idx2] = false;
457  myForbids[idx2][idx1] = false;
458  continue;
459  }
460  // check other
461  // if both are non-signalised or both are signalised
462  if (((*i12).tlID == "" && (*i22).tlID == "")
463  ||
464  ((*i12).tlID != "" && (*i22).tlID != "")) {
465  // do nothing
466  continue;
467  }
468  // supposing, we don not have to
469  // brake if we are no foes
470  if (!foes(*i11, (*i12).toEdge, *i21, (*i22).toEdge)) {
471  continue;
472  }
473  // otherwise:
474  // the non-signalised must break
475  if ((*i12).tlID != "") {
476  myForbids[idx1][idx2] = true;
477  myForbids[idx2][idx1] = false;
478  } else {
479  myForbids[idx1][idx2] = false;
480  myForbids[idx2][idx1] = true;
481  }
482  }
483  }
484  }
485  }
486  }
487  }
488 }
489 
490 
491 std::pair<int, int>
493  int noLanes = 0;
494  int noLinks = 0;
495  for (EdgeVector::const_iterator i = myIncoming.begin();
496  i != myIncoming.end(); i++) {
497  int noLanesEdge = (*i)->getNumLanes();
498  for (int j = 0; j < noLanesEdge; j++) {
499  int numConnections = (int)(*i)->getConnectionsFromLane(j).size();
500  noLinks += numConnections;
501  if (numConnections > 0) {
502  noLanes++;
503  }
504  }
505  }
506  return std::make_pair(noLanes, noLinks);
507 }
508 
509 
510 bool
511 NBRequest::foes(const NBEdge* const from1, const NBEdge* const to1,
512  const NBEdge* const from2, const NBEdge* const to2) const {
513  // unconnected edges do not forbid other edges
514  if (to1 == nullptr || to2 == nullptr) {
515  return false;
516  }
517  // get the indices
518  int idx1 = getIndex(from1, to1);
519  int idx2 = getIndex(from2, to2);
520  if (idx1 < 0 || idx2 < 0) {
521  return false; // sure? (The connection does not exist within this junction)
522  }
523  assert(idx1 < (int)(myIncoming.size() * myOutgoing.size()));
524  assert(idx2 < (int)(myIncoming.size()*myOutgoing.size()));
525  return myForbids[idx1][idx2] || myForbids[idx2][idx1];
526 }
527 
528 
529 bool
530 NBRequest::forbids(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
531  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo,
532  bool regardNonSignalisedLowerPriority) const {
533  // unconnected edges do not forbid other edges
534  if (possProhibitorTo == nullptr || possProhibitedTo == nullptr) {
535  return false;
536  }
537  // get the indices
538  int possProhibitorIdx = getIndex(possProhibitorFrom, possProhibitorTo);
539  int possProhibitedIdx = getIndex(possProhibitedFrom, possProhibitedTo);
540  if (possProhibitorIdx < 0 || possProhibitedIdx < 0) {
541  return false; // sure? (The connection does not exist within this junction)
542  }
543  assert(possProhibitorIdx < (int)(myIncoming.size() * myOutgoing.size()));
544  assert(possProhibitedIdx < (int)(myIncoming.size() * myOutgoing.size()));
545  // check simple right-of-way-rules
546  if (!regardNonSignalisedLowerPriority) {
547  return myForbids[possProhibitorIdx][possProhibitedIdx];
548  }
549  // if its not forbidden, report
550  if (!myForbids[possProhibitorIdx][possProhibitedIdx]) {
551  return false;
552  }
553  // do not forbid a signalised stream by a non-signalised
554  if (!possProhibitorFrom->hasSignalisedConnectionTo(possProhibitorTo)) {
555  return false;
556  }
557  return true;
558 }
559 
560 int
561 NBRequest::computeLaneResponse(NBEdge* from, int fromLane, int pos, const bool checkLaneFoes) {
562  for (const NBEdge::Connection& c : from->getConnectionsFromLane(fromLane)) {
563  assert(c.toEdge != 0);
564  pos++;
565  const std::string foes = getFoesString(from, c.toEdge, fromLane, c.toLane, checkLaneFoes);
566  const std::string response = getResponseString(from, c, checkLaneFoes);
567  myFoes.push_back(foes);
568  myResponse.push_back(response);
569  myHaveVia.push_back(c.haveVia);
570  }
571  return pos;
572 }
573 
574 
575 int
577  std::string foes(myJunction->getCrossings().size(), '0');
578  std::string response(myJunction->getCrossings().size(), '0');
579  // conflicts with normal connections
580  for (EdgeVector::const_reverse_iterator i = myIncoming.rbegin(); i != myIncoming.rend(); i++) {
581  //const std::vector<NBEdge::Connection> &allConnections = (*i)->getConnections();
582  const NBEdge* from = *i;
583  int noLanes = from->getNumLanes();
584  for (int j = noLanes; j-- > 0;) {
585  std::vector<NBEdge::Connection> connected = from->getConnectionsFromLane(j);
586  int size = (int) connected.size();
587  for (int k = size; k-- > 0;) {
588  const NBEdge* to = connected[k].toEdge;
589  bool foe = false;
590  for (EdgeVector::const_iterator it_e = crossing.edges.begin(); it_e != crossing.edges.end(); ++it_e) {
591  if ((*it_e) == from || (*it_e) == to) {
592  foe = true;
593  break;
594  }
595  }
596  foes += foe ? '1' : '0';
597  response += mustBrakeForCrossing(myJunction, from, to, crossing) || !foe ? '0' : '1';
598  }
599  }
600  }
601  pos++;
602  myResponse.push_back(response);
603  myFoes.push_back(foes);
604  myHaveVia.push_back(false);
605  return pos;
606 }
607 
608 
609 std::string
610 NBRequest::getResponseString(const NBEdge* const from, const NBEdge::Connection& c, const bool checkLaneFoes) const {
611  const NBEdge* const to = c.toEdge;
612  const int fromLane = c.fromLane;
613  const int toLane = c.toLane;
614  int idx = 0;
615  if (to != nullptr) {
616  idx = getIndex(from, to);
617  }
618  std::string result;
619  const bool zipper = myJunction->getType() == SumoXMLNodeType::ZIPPER;
620  // crossings
621  auto crossings = myJunction->getCrossings();
622  for (std::vector<NBNode::Crossing*>::const_reverse_iterator i = crossings.rbegin(); i != crossings.rend(); i++) {
623  result += mustBrakeForCrossing(myJunction, from, to, **i) ? '1' : '0';
624  }
625  NBEdge::Connection queryCon = from->getConnection(fromLane, to, toLane);
626  // normal connections
627  for (EdgeVector::const_reverse_iterator i = myIncoming.rbegin(); i != myIncoming.rend(); i++) {
628  //const std::vector<NBEdge::Connection> &allConnections = (*i)->getConnections();
629  int noLanes = (*i)->getNumLanes();
630  for (int j = noLanes; j-- > 0;) {
631  std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
632  int size = (int) connected.size();
633  for (int k = size; k-- > 0;) {
634  if (c.mayDefinitelyPass) {
635  result += '0';
636 #ifdef DEBUG_RESPONSE
637  if (DEBUGCOND) {
638  std::cout << " c=" << queryCon.getDescription(from) << " pass\n";
639  }
640 #endif
641  } else if ((*i) == from && fromLane == j) {
642  // do not prohibit a connection by others from same lane
643  // except for indirect turns
644 #ifdef DEBUG_RESPONSE
645  if (DEBUGCOND) {
646  std::cout << " c=" << queryCon.getDescription(from) << " prohibitC=" << connected[k].getDescription(*i)
647  << " itc=" << indirectLeftTurnConflict(from, queryCon, *i, connected[k], false)
648  << "\n";
649  }
650 #endif
651  if (indirectLeftTurnConflict(from, queryCon, *i, connected[k], false)) {
652  result += '1';
653  } else {
654  result += '0';
655  }
656  } else {
657  assert(connected[k].toEdge != 0);
658  const int idx2 = getIndex(*i, connected[k].toEdge);
659  assert(k < (int) connected.size());
660  assert(idx < (int)(myIncoming.size() * myOutgoing.size()));
661  assert(idx2 < (int)(myIncoming.size() * myOutgoing.size()));
662  // check whether the connection is prohibited by another one
663 #ifdef DEBUG_RESPONSE
664  if (DEBUGCOND) {
665  std::cout << " c=" << queryCon.getDescription(from) << " prohibitC=" << connected[k].getDescription(*i)
666  << " f=" << myForbids[idx2][idx]
667  << " clf=" << checkLaneFoes
668  << " clfbc=" << checkLaneFoesByClass(queryCon, *i, connected[k])
669  << " clfbcoop=" << checkLaneFoesByCooperation(from, queryCon, *i, connected[k])
670  << " lc=" << laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane)
671  << " rtc=" << NBNode::rightTurnConflict(from, to, fromLane, *i, connected[k].toEdge, connected[k].fromLane)
672  << " rtc2=" << rightTurnConflict(from, queryCon, *i, connected[k])
673  << " mc=" << mergeConflict(from, queryCon, *i, connected[k], false)
674  << " oltc=" << oppositeLeftTurnConflict(from, queryCon, *i, connected[k], false)
675  << " itc=" << indirectLeftTurnConflict(from, queryCon, *i, connected[k], zipper)
676  << " rorc=" << myJunction->rightOnRedConflict(c.tlLinkIndex, connected[k].tlLinkIndex)
677  << " tlscc=" << myJunction->tlsContConflict(from, c, *i, connected[k])
678  << "\n";
679  }
680 #endif
681  const bool hasLaneConflict = (!(checkLaneFoes || checkLaneFoesByClass(queryCon, *i, connected[k])
682  || checkLaneFoesByCooperation(from, queryCon, *i, connected[k]))
683  || laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane));
684  if (((myForbids[idx2][idx] || (zipper && myForbids[idx][idx2])) && hasLaneConflict)
685  || rightTurnConflict(from, queryCon, *i, connected[k])
686  || mergeConflict(from, queryCon, *i, connected[k], zipper)
687  || oppositeLeftTurnConflict(from, queryCon, *i, connected[k], zipper)
688  || indirectLeftTurnConflict(from, queryCon, *i, connected[k], zipper)
689  || myJunction->rightOnRedConflict(c.tlLinkIndex, connected[k].tlLinkIndex)
690  || (myJunction->tlsContConflict(from, c, *i, connected[k]) && hasLaneConflict
691  && !OptionsCont::getOptions().getBool("tls.ignore-internal-junction-jam"))
692  ) {
693  result += '1';
694  } else {
695  result += '0';
696  }
697  }
698  }
699  }
700  }
701  return result;
702 }
703 
704 
705 std::string
706 NBRequest::getFoesString(NBEdge* from, NBEdge* to, int fromLane, int toLane, const bool checkLaneFoes) const {
707  const bool lefthand = OptionsCont::getOptions().getBool("lefthand");
708  // remember the case when the lane is a "dead end" in the meaning that
709  // vehicles must choose another lane to move over the following
710  // junction
711  // !!! move to forbidden
712  std::string result;
713  // crossings
714  auto crossings = myJunction->getCrossings();
715  for (std::vector<NBNode::Crossing*>::const_reverse_iterator i = crossings.rbegin(); i != crossings.rend(); i++) {
716  bool foes = false;
717  for (EdgeVector::const_iterator it_e = (**i).edges.begin(); it_e != (**i).edges.end(); ++it_e) {
718  if ((*it_e) == from || (*it_e) == to) {
719  foes = true;
720  break;
721  }
722  }
723  result += foes ? '1' : '0';
724  }
725  NBEdge::Connection queryCon = from->getConnection(fromLane, to, toLane);
726  // normal connections
727  for (EdgeVector::const_reverse_iterator i = myIncoming.rbegin();
728  i != myIncoming.rend(); i++) {
729 
730  for (int j = (int)(*i)->getNumLanes() - 1; j >= 0; --j) {
731  std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
732  int size = (int) connected.size();
733  for (int k = size; k-- > 0;) {
734  const bool hasLaneConflict = (!(checkLaneFoes || checkLaneFoesByClass(queryCon, *i, connected[k])
735  || checkLaneFoesByCooperation(from, queryCon, *i, connected[k]))
736  || laneConflict(from, to, toLane, *i, connected[k].toEdge, connected[k].toLane));
737  if ((foes(from, to, (*i), connected[k].toEdge) && hasLaneConflict)
738  || rightTurnConflict(from, queryCon, *i, connected[k])
739  || myJunction->turnFoes(from, to, fromLane, *i, connected[k].toEdge, connected[k].fromLane, lefthand)
740  || mergeConflict(from, queryCon, *i, connected[k], true)
741  || oppositeLeftTurnConflict(from, queryCon, *i, connected[k], true)
742  || indirectLeftTurnConflict(from, queryCon, *i, connected[k], true)
743  ) {
744  result += '1';
745  } else {
746  result += '0';
747  }
748  }
749  }
750  }
751  return result;
752 }
753 
754 
755 bool
757  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon) const {
758  return (!con.mayDefinitelyPass &&
759  (NBNode::rightTurnConflict(from, con.toEdge, con.fromLane, prohibitorFrom, prohibitorCon.toEdge, prohibitorCon.fromLane)
760  // reverse conflicht (override)
761  || (prohibitorCon.mayDefinitelyPass &&
762  NBNode::rightTurnConflict(prohibitorFrom, prohibitorCon.toEdge, prohibitorCon.fromLane, from, con.toEdge, con.fromLane))));
763 
764 
765 }
766 
767 
768 bool
770  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const {
771  if (from == prohibitorFrom
772  && con.toEdge == prohibitorCon.toEdge
773  && con.toLane == prohibitorCon.toLane
774  && con.fromLane != prohibitorCon.fromLane
776  if (foes) {
777  return true;
778  }
779  if (prohibitorCon.mayDefinitelyPass) {
780  return true;
781  }
782  if (con.mayDefinitelyPass) {
783  return false;
784  }
785  const bool bike = from->getPermissions(con.fromLane) == SVC_BICYCLE;
786  const bool prohibitorBike = prohibitorFrom->getPermissions(prohibitorCon.fromLane) == SVC_BICYCLE;
787  if (myOutgoing.size() == 1) {
788  // at on-ramp like situations, right lane should yield
789  return bike || (con.fromLane < prohibitorCon.fromLane && !prohibitorBike);
790  } else {
791  // priority depends on direction:
792  // for right turns the rightmost lane gets priority
793  // otherwise the left lane
794  LinkDirection dir = myJunction->getDirection(from, con.toEdge);
795  if (dir == LinkDirection::RIGHT || dir == LinkDirection::PARTRIGHT) {
796  return con.fromLane > prohibitorCon.fromLane;
797  } else {
798  if (myIncoming.size() == 1) {
799  // at off-ramp like situations, right lane should pass unless it's a bicycle lane
800  return bike || (con.fromLane > prohibitorCon.fromLane && !prohibitorBike);
801  } else {
802  return con.fromLane < prohibitorCon.fromLane;
803  }
804  }
805  }
806 
807  } else {
808  return false;
809  }
810 }
811 
812 
813 bool
815  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const {
816  LinkDirection dir = myJunction->getDirection(from, con.toEdge);
817  // XXX lefthand issue (solve via #4256)
818  if (dir != LinkDirection::LEFT && dir != LinkDirection::PARTLEFT) {
819  return false;
820  }
821  dir = myJunction->getDirection(prohibitorFrom, prohibitorCon.toEdge);
822  if (dir != LinkDirection::LEFT && dir != LinkDirection::PARTLEFT) {
823  return false;
824  }
825  if (from == prohibitorFrom || NBRequest::foes(from, con.toEdge, prohibitorFrom, prohibitorCon.toEdge)) {
826  // not an opposite pair
827  return false;
828  };
829 
830  const double width1 = MIN2(from->getLaneWidth(con.fromLane) / 2, OptionsCont::getOptions().getFloat("internal-junctions.vehicle-width") / 2);
831  const double width2 = prohibitorCon.toEdge->getLaneWidth(prohibitorCon.toLane) / 2;
832  PositionVector shape = con.shape;
833  shape.append(con.viaShape);
834  PositionVector otherShape = prohibitorCon.shape;
835  otherShape.append(prohibitorCon.viaShape);
836  if (shape.size() == 0 || otherShape.size() == 0) {
837  // no internal lanes built
838  return false;
839  }
840  const double minDV = NBEdge::firstIntersection(shape, otherShape, width1, width2);
841  if (minDV < shape.length() - POSITION_EPS && minDV > POSITION_EPS) {
842  // break symmetry using edge id
843  return foes || from->getID() < prohibitorFrom->getID();
844  } else {
845  return false;
846  }
847 }
848 
849 bool
851  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon, bool foes) const {
852  if (from == prohibitorFrom) {
853  if (con.indirectLeft) {
854  LinkDirection dir = myJunction->getDirection(prohibitorFrom, prohibitorCon.toEdge);
855  return (dir == LinkDirection::STRAIGHT);
856  } else if (foes && prohibitorCon.indirectLeft) {
857  LinkDirection dir = myJunction->getDirection(from, con.toEdge);
858  return (dir == LinkDirection::STRAIGHT);
859  }
860  }
861  return false;
862 }
863 
864 bool
866  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon) const {
867  if (con.toEdge != prohibitorCon.toEdge) {
868  return false;
869  }
870  SVCPermissions svc = con.toEdge->getPermissions(con.toLane);
871  SVCPermissions svc2 = prohibitorFrom->getPermissions(prohibitorCon.fromLane) & prohibitorCon.toEdge->getPermissions(prohibitorCon.toLane);
872  // check for lane level conflict if the only common classes are bicycles or pedestrians
873  return (svc & svc2 & ~(SVC_BICYCLE | SVC_PEDESTRIAN)) == 0;
874 }
875 
876 
877 bool
879  const NBEdge* prohibitorFrom, const NBEdge::Connection& prohibitorCon) const {
880  if (con.toEdge != prohibitorCon.toEdge) {
881  return false;
882  }
883  // if from and prohibitorFrom target distinct lanes for all their
884  // connections to the common target edge, cooperation is possible
885  // (and should always happen unless the connections cross for some byzantine reason)
886 
887  std::set<int> fromTargetLanes;
888  for (const auto& c : from->getConnections()) {
889  if (c.toEdge == con.toEdge) {
890  fromTargetLanes.insert(c.toLane);
891  }
892  }
893  for (const auto& c : prohibitorFrom->getConnections()) {
894  if (c.toEdge == con.toEdge && fromTargetLanes.count(c.toLane) != 0) {
895  //std::cout << " con=" << con->getDescription(from) << " foe=" << prohibitorCon.getDescription(prohibitorFrom)
896  // << " no cooperation (targets=" << joinToString(fromTargetLanes, ' ') << " index=" << c.toLane << "\n";
897  return false;
898  }
899  }
900  return true;
901 }
902 
903 
904 bool
905 NBRequest::laneConflict(const NBEdge* from, const NBEdge* to, int toLane,
906  const NBEdge* prohibitorFrom, const NBEdge* prohibitorTo, int prohibitorToLane) const {
907  if (to != prohibitorTo) {
908  return true;
909  }
910  // since we know that the edge2edge connections are in conflict, the only
911  // situation in which the lane2lane connections can be conflict-free is, if
912  // they target the same edge but do not cross each other
913  double angle = NBHelpers::relAngle(
914  from->getAngleAtNode(from->getToNode()), to->getAngleAtNode(to->getFromNode()));
915  if (angle == 180) {
916  angle = -180; // turnarounds are left turns
917  }
918  const double prohibitorAngle = NBHelpers::relAngle(
919  prohibitorFrom->getAngleAtNode(prohibitorFrom->getToNode()), to->getAngleAtNode(to->getFromNode()));
920  const bool rightOfProhibitor = prohibitorFrom->isTurningDirectionAt(to)
921  || (angle > prohibitorAngle && !from->isTurningDirectionAt(to));
922  return rightOfProhibitor ? toLane >= prohibitorToLane : toLane <= prohibitorToLane;
923 }
924 
925 int
926 NBRequest::getIndex(const NBEdge* const from, const NBEdge* const to) const {
927  EdgeVector::const_iterator fp = std::find(myIncoming.begin(), myIncoming.end(), from);
928  EdgeVector::const_iterator tp = std::find(myOutgoing.begin(), myOutgoing.end(), to);
929  if (fp == myIncoming.end() || tp == myOutgoing.end()) {
930  return -1;
931  }
932  // compute the index
933  return (int)(distance(myIncoming.begin(), fp) * myOutgoing.size() + distance(myOutgoing.begin(), tp));
934 }
935 
936 
937 std::ostream&
938 operator<<(std::ostream& os, const NBRequest& r) {
939  int variations = r.numLinks();
940  for (int i = 0; i < variations; i++) {
941  os << i << ' ';
942  for (int j = 0; j < variations; j++) {
943  if (r.myForbids[i][j]) {
944  os << '1';
945  } else {
946  os << '0';
947  }
948  }
949  os << std::endl;
950  }
951  os << std::endl;
952  return os;
953 }
954 
955 
956 bool
957 NBRequest::mustBrake(const NBEdge* const from, const NBEdge* const to, int fromLane, int toLane, bool includePedCrossings) const {
958  NBEdge::Connection con(fromLane, const_cast<NBEdge*>(to), toLane);
959  const int linkIndex = myJunction->getConnectionIndex(from, con);
960  if (linkIndex >= 0 && (int)myResponse.size() > linkIndex) {
961  std::string response = getResponse(linkIndex);
962  if (!includePedCrossings) {
963  response = response.substr(0, response.size() - myJunction->getCrossings().size());
964  }
965  if (response.find_first_of("1") == std::string::npos) {
966  return false;
967  } else if (!myJunction->isTLControlled()) {
968  return true;
969  }
970  // if the link must respond it could also be due to a tlsConflict. This
971  // must not carry over the the off-state response so we continue with
972  // the regular check
973  }
974  // get the indices
975  int idx2 = getIndex(from, to);
976  if (idx2 == -1) {
977  return false;
978  }
979  // go through all (existing) connections;
980  // check whether any of these forbids the one to determine
981  assert(idx2 < (int)(myIncoming.size()*myOutgoing.size()));
982  for (int idx1 = 0; idx1 < numLinks(); idx1++) {
983  //assert(myDone[idx1][idx2]);
984  if (myDone[idx1][idx2] && myForbids[idx1][idx2]) {
985  return true;
986  }
987  }
988  // maybe we need to brake for a pedestrian crossing
989  if (includePedCrossings) {
990  auto crossings = myJunction->getCrossings();
991  for (std::vector<NBNode::Crossing*>::const_reverse_iterator i = crossings.rbegin(); i != crossings.rend(); i++) {
992  if (mustBrakeForCrossing(myJunction, from, to, **i)) {
993  return true;
994  }
995  }
996  }
997  // maybe we need to brake due to a right-turn conflict with straight-going
998  // bicycles
999  NBEdge::Connection queryCon = from->getConnection(fromLane, to, toLane);
1000  LinkDirection dir = myJunction->getDirection(from, to);
1001  if (dir == LinkDirection::RIGHT || dir == LinkDirection::PARTRIGHT) {
1002  for (const NBEdge::Connection& fromCon : from->getConnections()) {
1003  if (rightTurnConflict(from, queryCon, from, fromCon)) {
1004  return true;
1005  }
1006  }
1007  }
1008  // maybe we need to brake due to a merge conflict
1009  for (EdgeVector::const_reverse_iterator i = myIncoming.rbegin(); i != myIncoming.rend(); i++) {
1010  int noLanes = (*i)->getNumLanes();
1011  for (int j = noLanes; j-- > 0;) {
1012  std::vector<NBEdge::Connection> connected = (*i)->getConnectionsFromLane(j);
1013  const int size = (int) connected.size();
1014  for (int k = size; k-- > 0;) {
1015  if ((*i) == from && fromLane != j
1016  && mergeConflict(from, queryCon, *i, connected[k], myJunction->getType() == SumoXMLNodeType::ZIPPER)) {
1017  return true;
1018  }
1019  }
1020  }
1021  }
1022  // maybe we need to brake due to a zipper conflict
1024  for (int idx1 = 0; idx1 < numLinks(); idx1++) {
1025  //assert(myDone[idx1][idx2]);
1026  if (myDone[idx1][idx2] && myForbids[idx2][idx1]) {
1027  return true;
1028  }
1029  }
1030  }
1031  return false;
1032 }
1033 
1034 
1035 bool
1036 NBRequest::mustBrakeForCrossing(const NBNode* node, const NBEdge* const from, const NBEdge* const to, const NBNode::Crossing& crossing) {
1037  const LinkDirection dir = node->getDirection(from, to);
1038  const bool mustYield = dir == LinkDirection::LEFT || dir == LinkDirection::RIGHT;
1039  if (crossing.priority || mustYield) {
1040  for (EdgeVector::const_iterator it_e = crossing.edges.begin(); it_e != crossing.edges.end(); ++it_e) {
1041  // left and right turns must yield to unprioritized crossings only on their destination edge
1042  if (((*it_e) == from && crossing.priority) || (*it_e) == to) {
1043  return true;
1044  }
1045  }
1046  }
1047  return false;
1048 }
1049 
1050 
1051 bool
1052 NBRequest::mustBrake(const NBEdge* const possProhibitorFrom, const NBEdge* const possProhibitorTo,
1053  const NBEdge* const possProhibitedFrom, const NBEdge* const possProhibitedTo) const {
1054  // get the indices
1055  int idx1 = getIndex(possProhibitorFrom, possProhibitorTo);
1056  int idx2 = getIndex(possProhibitedFrom, possProhibitedTo);
1057  return (myForbids[idx2][idx1]);
1058 }
1059 
1060 
1061 void
1063  // check if any errors occurred on build the link prohibitions
1064  if (myNotBuild != 0) {
1065  WRITE_WARNING(toString(myNotBuild) + " of " + toString(myNotBuild + myGoodBuilds) + " prohibitions were not build.");
1066  }
1067 }
1068 
1069 
1070 void
1072  // map from edge to number of incoming connections
1073  std::map<NBEdge*, int> incomingCount; // initialized to 0
1074  // map from edge to indices of approached lanes
1075  std::map<NBEdge*, std::set<int> > approachedLanes;
1076  // map from edge to list of incoming edges
1077  std::map<NBEdge*, EdgeVector> incomingEdges;
1078  for (EdgeVector::const_iterator it_e = myIncoming.begin(); it_e != myIncoming.end(); it_e++) {
1079  const std::vector<NBEdge::Connection> connections = (*it_e)->getConnections();
1080  for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); ++it_c) {
1081  incomingCount[it_c->toEdge]++;
1082  approachedLanes[it_c->toEdge].insert(it_c->toLane);
1083  incomingEdges[it_c->toEdge].push_back(*it_e);
1084  }
1085  }
1086  for (std::map<NBEdge*, int>::iterator it = incomingCount.begin(); it != incomingCount.end(); ++it) {
1087  NBEdge* to = it->first;
1088  // we cannot test against to->getNumLanes() since not all lanes may be used
1089  if ((int)approachedLanes[to].size() >= it->second) {
1090  EdgeVector& incoming = incomingEdges[to];
1091  // make these connections mutually unconflicting
1092  for (EdgeVector::iterator it_e1 = incoming.begin(); it_e1 != incoming.end(); ++it_e1) {
1093  for (EdgeVector::iterator it_e2 = incoming.begin(); it_e2 != incoming.end(); ++it_e2) {
1094  myForbids[getIndex(*it_e1, to)][getIndex(*it_e2, to)] = false;
1095  }
1096  }
1097  }
1098  }
1099 }
1100 
1101 
1102 bool
1104  for (int i = 0; i < (int)myFoes.size(); i++) {
1105  if (hasConflictAtLink(i)) {
1106  return true;
1107  }
1108  }
1109  return false;
1110 }
1111 
1112 bool
1113 NBRequest::hasConflictAtLink(int linkIndex) const {
1114  return myFoes[linkIndex].find_first_of("1") != std::string::npos;
1115 }
1116 
1117 int
1119  return (int)(myIncoming.size() * myOutgoing.size() + myJunction->getCrossings().size());
1120 }
1121 
1122 
1123 /****************************************************************************/
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
std::map< NBConnection, NBConnectionVector > NBConnectionProhibits
Definition of a container for connection block dependencies Includes a list of all connections which ...
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
#define DEBUGCOND
Definition: NBRequest.cpp:44
std::ostream & operator<<(std::ostream &os, const NBRequest &r)
Definition: NBRequest.cpp:938
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_PEDESTRIAN
pedestrian
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
@ SUMO_TAG_REQUEST
description of a logic request within the junction
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
@ PARTLEFT
The link is a partial left direction.
@ RIGHT
The link is a (hard) right direction.
@ LEFT
The link is a (hard) left direction.
@ STRAIGHT
The link is a straight direction.
@ PARTRIGHT
The link is a partial right direction.
@ SUMO_ATTR_CONT
@ SUMO_ATTR_RESPONSE
@ SUMO_ATTR_INDEX
@ SUMO_ATTR_FOES
T MIN2(T a, T b)
Definition: StdDefs.h:74
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
NBEdge * getFrom() const
returns the from-edge (start of the connection)
NBEdge * getTo() const
returns the to-edge (end of the connection)
bool check(const NBEdgeCont &ec)
checks whether the edges are still valid
static void nextCCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
static void nextCW(const EdgeVector &edges, EdgeVector::const_iterator &from)
Storage for edges, including some functionality operating on multiple edges.
Definition: NBEdgeCont.h:59
The representation of a single edge during network building.
Definition: NBEdge.h:91
SVCPermissions getPermissions(int lane=-1) const
get the union of allowed classes over all lanes or for a specific lane
Definition: NBEdge.cpp:4022
double getLaneWidth() const
Returns the default width of lanes of this edge.
Definition: NBEdge.h:630
const std::string & getID() const
Definition: NBEdge.h:1465
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:541
bool isTurningDirectionAt(const NBEdge *const edge) const
Returns whether the given edge is the opposite direction to this edge.
Definition: NBEdge.cpp:3356
std::vector< Connection > getConnectionsFromLane(int lane, NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
Definition: NBEdge.cpp:1206
bool hasSignalisedConnectionTo(const NBEdge *const e) const
Check if edge has signalised connections.
Definition: NBEdge.cpp:3673
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:515
static double firstIntersection(const PositionVector &v1, const PositionVector &v2, double width1, double width2, const std::string &error="", bool secondIntersection=false)
compute the first intersection point between the given lane geometries considering their rspective wi...
Definition: NBEdge.cpp:1944
bool isConnectedTo(const NBEdge *e, const bool ignoreTurnaround=false) const
Returns the information whethe a connection to the given edge has been added (or computed)
Definition: NBEdge.cpp:1255
int getJunctionPriority(const NBNode *const node) const
Returns the junction priority (normalised for the node currently build)
Definition: NBEdge.cpp:2027
double getAngleAtNode(const NBNode *const node) const
Returns the angle of the edge's geometry at the given node.
Definition: NBEdge.cpp:2053
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition: NBEdge.h:1006
Connection getConnection(int fromLane, const NBEdge *to, int toLane) const
Returns the specified connection This method goes through "myConnections" and returns the specified o...
Definition: NBEdge.cpp:1220
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:534
static double relAngle(double angle1, double angle2)
computes the relative angle between the two angles
Definition: NBHelpers.cpp:45
A definition of a pedestrian crossing.
Definition: NBNode.h:129
bool priority
whether the pedestrians have priority
Definition: NBNode.h:150
EdgeVector edges
The edges being crossed.
Definition: NBNode.h:136
Represents a single node (junction) during network building.
Definition: NBNode.h:66
LinkDirection getDirection(const NBEdge *const incoming, const NBEdge *const outgoing, bool leftHand=false) const
Returns the representation of the described stream's direction.
Definition: NBNode.cpp:2221
int getConnectionIndex(const NBEdge *from, const NBEdge::Connection &con) const
return the index of the given connection
Definition: NBNode.cpp:3480
bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turing right on a red light
Definition: NBNode.cpp:3563
SumoXMLNodeType getType() const
Returns the type of this node.
Definition: NBNode.h:273
static bool rightTurnConflict(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorFromLane)
return whether the given laneToLane connection is a right turn which must yield to a bicycle crossing...
Definition: NBNode.cpp:1925
std::vector< Crossing * > getCrossings() const
return this junctions pedestrian crossings
Definition: NBNode.cpp:2725
bool isBentPriority() const
return whether a priority road turns at this node
Definition: NBNode.h:795
bool turnFoes(const NBEdge *from, const NBEdge *to, int fromLane, const NBEdge *from2, const NBEdge *to2, int fromLane2, bool lefthand=false) const
return whether the given laneToLane connection originate from the same edge and are in conflict due t...
Definition: NBNode.cpp:1996
bool isConstantWidthTransition() const
detects whether a given junction splits or merges lanes while keeping constant road width
Definition: NBNode.cpp:818
bool tlsContConflict(const NBEdge *from, const NBEdge::Connection &c, const NBEdge *foeFrom, const NBEdge::Connection &foe) const
whether the connection must yield if the foe remains on the intersection after its phase ends
Definition: NBNode.cpp:927
bool isTLControlled() const
Returns whether this node is controlled by any tls.
Definition: NBNode.h:319
std::vector< std::string > myResponse
Definition: NBRequest.h:278
const EdgeVector & myOutgoing
edges outgoing from the junction
Definition: NBRequest.h:262
CombinationsCont myForbids
the link X link blockings
Definition: NBRequest.h:271
int computeLaneResponse(NBEdge *from, int lane, int pos, const bool checkLaneFoes)
computes the response of a certain lane Returns the next link index within the junction
Definition: NBRequest.cpp:561
CombinationsCont myDone
the link X link is done-checks
Definition: NBRequest.h:274
const EdgeVector & myAll
all (icoming and outgoing) of the junctions edges
Definition: NBRequest.h:256
bool checkLaneFoesByCooperation(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon) const
whether the given connections must be checked for lane conflicts due to disjunct target lanes
Definition: NBRequest.cpp:878
std::vector< std::string > myFoes
precomputed right-of-way matrices for each lane-to-lane link
Definition: NBRequest.h:277
int distanceCounterClockwise(NBEdge *from, NBEdge *to)
returns the distance between the incoming (from) and the outgoing (to) edge clockwise in edges
Definition: NBRequest.cpp:359
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
Definition: NBRequest.cpp:530
bool hasConflictAtLink(int linkIndex) const
whether there are conflicting streams of traffic for the given link index
Definition: NBRequest.cpp:1113
const EdgeVector & myIncoming
edges incoming to the junction
Definition: NBRequest.h:259
NBNode * myJunction
the node the request is assigned to
Definition: NBRequest.h:253
int numLinks() const
return to total number of edge-to-edge connections of this request-logic
Definition: NBRequest.cpp:1118
const std::string & getFoes(int linkIndex) const
Definition: NBRequest.cpp:373
bool hasConflict() const
whether there are conflicting streams of traffic at this node
Definition: NBRequest.cpp:1103
std::string getFoesString(NBEdge *from, NBEdge *to, int fromLane, int toLane, const bool checkLaneFoes) const
Definition: NBRequest.cpp:706
void buildBitfieldLogic()
builds the bitset-representation of the logic
Definition: NBRequest.cpp:145
bool oppositeLeftTurnConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes) const
whether opposite left turns intersect
Definition: NBRequest.cpp:814
bool laneConflict(const NBEdge *from, const NBEdge *to, int toLane, const NBEdge *prohibitorFrom, const NBEdge *prohibitorTo, int prohibitorToLane) const
return whether the given laneToLane connections prohibit each other under the assumption that the edg...
Definition: NBRequest.cpp:905
void resetSignalised()
Definition: NBRequest.cpp:432
bool indirectLeftTurnConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes) const
whether straight and indirect left turn are in conflict
Definition: NBRequest.cpp:850
int getIndex(const NBEdge *const from, const NBEdge *const to) const
Returns the index to the internal combination container for the given edge combination.
Definition: NBRequest.cpp:926
static bool mustBrakeForCrossing(const NBNode *node, const NBEdge *const from, const NBEdge *const to, const NBNode::Crossing &crossing)
Returns the information whether the described flow must brake for the given crossing.
Definition: NBRequest.cpp:1036
void computeRightOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
computes the relationships between links outgoing right of the given link *‍/
Definition: NBRequest.cpp:161
bool mergeConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon, bool foes) const
whether multple connections from the same edge target the same lane
Definition: NBRequest.cpp:769
void writeLogic(OutputDevice &into) const
Definition: NBRequest.cpp:389
NBRequest(const NBEdgeCont &ec, NBNode *junction, const EdgeVector &all, const EdgeVector &incoming, const EdgeVector &outgoing, const NBConnectionProhibits &loadedProhibits)
Definition: NBRequest.cpp:56
void computeLogic(const bool checkLaneFoes)
writes the XML-representation of the logic as a bitset-logic XML representation
Definition: NBRequest.cpp:411
std::string getResponseString(const NBEdge *const from, const NBEdge::Connection &c, const bool checkLaneFoes) const
Writes the response of a certain link.
Definition: NBRequest.cpp:610
std::pair< int, int > getSizes() const
returns the number of the junction's lanes and the number of the junction's links in respect.
Definition: NBRequest.cpp:492
bool mustBrake(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
Definition: NBRequest.cpp:1052
const std::string & getResponse(int linkIndex) const
Definition: NBRequest.cpp:381
int computeCrossingResponse(const NBNode::Crossing &crossing, int pos)
computes the response of a certain crossing Returns the next link index within the junction
Definition: NBRequest.cpp:576
void setBlocking(NBEdge *from1, NBEdge *to1, NBEdge *from2, NBEdge *to2)
Definition: NBRequest.cpp:197
void computeLeftOutgoingLinkCrossings(NBEdge *from, NBEdge *to)
computes the relationships between links outgoing left of the given link
Definition: NBRequest.cpp:179
bool checkLaneFoesByClass(const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon) const
whether the given connections must be checked for lane conflicts due to the vClasses involved
Definition: NBRequest.cpp:865
void resetCooperating()
reset foes it the number of lanes matches (or exceeds) the number of incoming connections for an edge
Definition: NBRequest.cpp:1071
~NBRequest()
destructor
Definition: NBRequest.cpp:141
bool foes(const NBEdge *const from1, const NBEdge *const to1, const NBEdge *const from2, const NBEdge *const to2) const
Returns the information whether the given flows cross.
Definition: NBRequest.cpp:511
static int myNotBuild
Definition: NBRequest.h:282
bool rightTurnConflict(const NBEdge *from, const NBEdge::Connection &con, const NBEdge *prohibitorFrom, const NBEdge::Connection &prohibitorCon) const
whether the given connections crosses the foe connection from the same lane and must yield
Definition: NBRequest.cpp:756
static void reportWarnings()
reports warnings if any occurred
Definition: NBRequest.cpp:1062
static int myGoodBuilds
Definition: NBRequest.h:282
std::vector< bool > LinkInfoCont
definition of a container to store boolean informations about a link into
Definition: NBRequest.h:265
std::vector< bool > myHaveVia
Definition: NBRequest.h:279
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
OutputDevice & writePadding(const std::string &val)
writes padding (ignored for binary output)
Definition: OutputDevice.h:311
A list of positions.
void append(const PositionVector &v, double sameThreshold=2.0)
double length() const
Returns the length.
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:197
bool indirectLeft
Whether this connection is an indirect left turn.
Definition: NBEdge.h:270
int fromLane
The lane the connections starts at.
Definition: NBEdge.h:222
int toLane
The lane the connections yields in.
Definition: NBEdge.h:228
NBEdge * toEdge
The edge the connections yields in.
Definition: NBEdge.h:225
bool mayDefinitelyPass
Information about being definitely free to drive (on-ramps)
Definition: NBEdge.h:240
PositionVector viaShape
shape of via
Definition: NBEdge.h:291
std::string getDescription(const NBEdge *parent) const
get string describing this connection
Definition: NBEdge.cpp:92
PositionVector shape
shape of Connection
Definition: NBEdge.h:279
int tlLinkIndex
The index of this connection within the controlling traffic light.
Definition: NBEdge.h:234