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