Eclipse SUMO - Simulation of Urban MObility
NBTrafficLightDefinition.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 /****************************************************************************/
20 // The base class for traffic light logic definitions
21 /****************************************************************************/
22 #include <config.h>
23 
24 #include <vector>
25 #include <string>
26 #include <algorithm>
27 #include <cassert>
28 #include <iterator>
30 #include <utils/common/ToString.h>
34 #include "NBTrafficLightLogic.h"
35 #include "NBOwnTLDef.h"
36 #include "NBContHelper.h"
37 
38 //#define DEBUG_RIGHT_OF_WAY
39 #define DEBUGCOND true
40 
41 // ===========================================================================
42 // static members
43 // ===========================================================================
44 const std::string NBTrafficLightDefinition::DefaultProgramID = "0";
45 const std::string NBTrafficLightDefinition::DummyID = "dummy";
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
52  const std::vector<NBNode*>& junctions, const std::string& programID,
53  SUMOTime offset, TrafficLightType type) :
54  Named(id),
55  myControlledNodes(junctions),
56  mySubID(programID), myOffset(offset),
57  myType(type),
58  myNeedsContRelationReady(false),
59  myRightOnRedConflictsReady(false) {
60  std::vector<NBNode*>::iterator i = myControlledNodes.begin();
61  while (i != myControlledNodes.end()) {
62  for (std::vector<NBNode*>::iterator j = i + 1; j != myControlledNodes.end();) {
63  if (*i == *j) {
64  j = myControlledNodes.erase(j);
65  } else {
66  j++;
67  }
68  }
69  i++;
70  }
72  for (NBNode* const node : junctions) {
73  node->addTrafficLight(this);
74  }
75 }
76 
77 
79  NBNode* junction, const std::string& programID, SUMOTime offset, TrafficLightType type) :
80  Named(id),
81  mySubID(programID),
82  myOffset(offset),
83  myType(type),
84  myNeedsContRelationReady(false),
85  myRightOnRedConflictsReady(false) {
86  addNode(junction);
87 }
88 
89 
90 NBTrafficLightDefinition::NBTrafficLightDefinition(const std::string& id, const std::string& programID,
91  SUMOTime offset, TrafficLightType type) :
92  Named(id),
93  mySubID(programID),
94  myOffset(offset),
95  myType(type),
96  myNeedsContRelationReady(false),
97  myRightOnRedConflictsReady(false) {
98 }
99 
100 
102 
103 
106  // it is not really a traffic light if no incoming edge exists
107  if (amInvalid()) {
108  // make a copy of myControlledNodes because it will be modified;
109  std::vector<NBNode*> nodes = myControlledNodes;
110  for (auto it : nodes) {
111  it->removeTrafficLight(this);
112  }
113  WRITE_WARNING("The traffic light '" + getID() + "' does not control any links; it will not be build.");
114  return nullptr;
115  }
116  // compute the time needed to brake
117  int brakingTime = computeBrakingTime(oc.getFloat("tls.yellow.min-decel"));
118  // perform the computation depending on whether the traffic light
119  // definition was loaded or shall be computed new completely
120  if (!oc.isDefault("tls.yellow.time")) {
121  brakingTime = oc.getInt("tls.yellow.time");
122  }
123  NBTrafficLightLogic* ret = myCompute(brakingTime);
125  return ret;
126 }
127 
128 
129 bool
131  return myControlledLinks.size() == 0;
132 }
133 
134 
135 int
137  if (myIncomingEdges.size() == 0) {
138  // don't crash
139  return 3;
140  }
141  const double vmax = NBContHelper::maxSpeed(myIncomingEdges);
142  if (vmax < 71 / 3.6) {
143  // up to 50kmh: 3 seconds , 60km/h: 4, 70kmh: 5
144  // @note: these are German regulations, other countries may differ
145  return 3 + (int)MAX2(0.0, (floor((vmax - 50 / 3.6) * 0.37)));
146  } else {
147  // above 70km/h we use a function that grows according to the "natural"
148  // formula (vmax / 2 * minDecel) but continues smoothly where the german
149  // rules leave of
150  return (int)(1.8 + vmax / 2 / minDecel);
151  }
152 }
153 
154 
155 void
157  // collect the information about participating edges and links
158  collectEdges();
159  collectLinks();
160 }
161 
162 std::set<NBEdge*>
163 NBTrafficLightDefinition::collectReachable(EdgeVector outer, const EdgeVector& within, bool checkControlled) {
164  std::set<NBEdge*> reachable;
165  while (outer.size() > 0) {
166  NBEdge* from = outer.back();
167  outer.pop_back();
168  std::vector<NBEdge::Connection>& cons = from->getConnections();
169  for (std::vector<NBEdge::Connection>::iterator k = cons.begin(); k != cons.end(); k++) {
170  NBEdge* to = (*k).toEdge;
171  if (reachable.count(to) == 0 &&
172  (find(within.begin(), within.end(), to) != within.end()) &&
173  (!checkControlled || from->mayBeTLSControlled((*k).fromLane, to, (*k).toLane))) {
174  reachable.insert(to);
175  outer.push_back(to);
176  }
177  }
178  }
179  return reachable;
180 }
181 
182 
183 void
185  myIncomingEdges.clear();
186  myEdgesWithin.clear();
187  EdgeVector myOutgoing;
188  // collect the edges from the participating nodes
189  for (std::vector<NBNode*>::iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
190  const EdgeVector& incoming = (*i)->getIncomingEdges();
191  copy(incoming.begin(), incoming.end(), back_inserter(myIncomingEdges));
192  const EdgeVector& outgoing = (*i)->getOutgoingEdges();
193  copy(outgoing.begin(), outgoing.end(), back_inserter(myOutgoing));
194  }
195  EdgeVector outer;
196  // check which of the edges are completely within the junction
197  // add them to the list of edges lying within the node
198  for (NBEdge* edge : myIncomingEdges) {
199  edge->setInsideTLS(false); // reset
200  // an edge lies within the logic if it is outgoing as well as incoming
201  EdgeVector::iterator k = std::find(myOutgoing.begin(), myOutgoing.end(), edge);
202  if (k != myOutgoing.end()) {
203  myEdgesWithin.push_back(edge);
204  } else {
205  outer.push_back(edge);
206  }
207  }
208  // collect edges that are reachable from the outside via controlled connections
209  std::set<NBEdge*> reachable = collectReachable(outer, myEdgesWithin, true);
210  // collect edges that are reachable from the outside regardless of controllability
211  std::set<NBEdge*> reachable2 = collectReachable(outer, myEdgesWithin, false);
212 
213  const bool uncontrolledWithin = OptionsCont::getOptions().getBool("tls.uncontrolled-within");
214  for (EdgeVector::iterator j = myEdgesWithin.begin(); j != myEdgesWithin.end(); ++j) {
215  NBEdge* edge = *j;
216  // edges that are marked as 'inner' will not get their own phase when
217  // computing traffic light logics (unless they cannot be reached from the outside at all)
218  if (reachable.count(edge) == 1) {
219  edge->setInsideTLS(true);
220  // legacy behavior
221  if (uncontrolledWithin && myControlledInnerEdges.count(edge->getID()) == 0) {
222  myIncomingEdges.erase(find(myIncomingEdges.begin(), myIncomingEdges.end(), edge));
223  }
224  }
225  if (reachable2.count(edge) == 0 && edge->getFirstNonPedestrianLaneIndex(NBNode::FORWARD, true) >= 0
226  && getID() != DummyID) {
227  WRITE_WARNING("Unreachable edge '" + edge->getID() + "' within tlLogic '" + getID() + "'");
228  }
229  }
230 }
231 
232 
233 bool
234 NBTrafficLightDefinition::mustBrake(const NBEdge* const from, const NBEdge* const to) const {
235  std::vector<NBNode*>::const_iterator i =
236  find_if(myControlledNodes.begin(), myControlledNodes.end(),
238  assert(i != myControlledNodes.end());
239  NBNode* node = *i;
240  if (!node->hasOutgoing(to)) {
241  return true; // !!!
242  }
243  // @todo recheck relevance of lane indices
244  return node->mustBrake(from, to, -1, -1, true);
245 }
246 
247 
248 bool
249 NBTrafficLightDefinition::mustBrake(const NBEdge* const possProhibitedFrom,
250  const NBEdge* const possProhibitedTo,
251  const NBEdge* const possProhibitorFrom,
252  const NBEdge* const possProhibitorTo,
253  bool regardNonSignalisedLowerPriority) const {
254  return forbids(possProhibitorFrom, possProhibitorTo,
255  possProhibitedFrom, possProhibitedTo,
256  regardNonSignalisedLowerPriority);
257 }
258 
259 
260 bool
262  const NBConnection& possProhibitor,
263  bool regardNonSignalisedLowerPriority) const {
264  return forbids(possProhibitor.getFrom(), possProhibitor.getTo(),
265  possProhibited.getFrom(), possProhibited.getTo(),
266  regardNonSignalisedLowerPriority);
267 }
268 
269 
270 bool
271 NBTrafficLightDefinition::forbids(const NBEdge* const possProhibitorFrom,
272  const NBEdge* const possProhibitorTo,
273  const NBEdge* const possProhibitedFrom,
274  const NBEdge* const possProhibitedTo,
275  bool regardNonSignalisedLowerPriority,
276  bool sameNodeOnly) const {
277  if (possProhibitorFrom == nullptr || possProhibitorTo == nullptr || possProhibitedFrom == nullptr || possProhibitedTo == nullptr) {
278  return false;
279  }
280  // retrieve both nodes
281  std::vector<NBNode*>::const_iterator incoming =
282  find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_incoming_finder(possProhibitorFrom));
283  std::vector<NBNode*>::const_iterator outgoing =
284  find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_outgoing_finder(possProhibitedTo));
285  assert(incoming != myControlledNodes.end());
286  NBNode* incnode = *incoming;
287  NBNode* outnode = *outgoing;
288  EdgeVector::const_iterator i;
289 
290 #ifdef DEBUG_RIGHT_OF_WAY
291  if (DEBUGCOND) {
292  std::cout << "foribds tls=" << getID() << " from=" << possProhibitedFrom->getID() << " to=" << possProhibitedTo->getID() << " foeFrom=" << possProhibitorFrom->getID() << " foeTo=" << possProhibitorTo->getID() << " rnslp=" << regardNonSignalisedLowerPriority << " sameNodeOnly=" << sameNodeOnly;
293  }
294 #endif
295  if (incnode != outnode) {
296  if (sameNodeOnly) {
297 #ifdef DEBUG_RIGHT_OF_WAY
298  if (DEBUGCOND) {
299  std::cout << " differentNodes: allows (no check)\n";
300  }
301 #endif
302  return false;
303  }
304  // the links are located at different nodes
305  const EdgeVector& ev1 = possProhibitedTo->getConnectedEdges();
306  // go through the following edge,
307  // check whether one of these connections is prohibited
308  for (i = ev1.begin(); i != ev1.end(); ++i) {
309  std::vector<NBNode*>::const_iterator outgoing2 =
311  if (outgoing2 == myControlledNodes.end()) {
312  continue;
313  }
314  NBNode* outnode2 = *outgoing2;
315  if (incnode != outnode2) {
316  continue;
317  }
318  if (incnode->getDirection(possProhibitedTo, *i) != LinkDirection::STRAIGHT) {
319  continue;
320  }
321  bool ret1 = incnode->foes(possProhibitorFrom, possProhibitorTo,
322  possProhibitedTo, *i);
323  bool ret2 = incnode->forbids(possProhibitorFrom, possProhibitorTo,
324  possProhibitedTo, *i,
325  regardNonSignalisedLowerPriority);
326  bool ret = ret1 || ret2;
327  if (ret) {
328 #ifdef DEBUG_RIGHT_OF_WAY
329  if (DEBUGCOND) {
330  std::cout << " differentNodes: forbids\n";
331  }
332 #endif
333  return true;
334  }
335  }
336 
337  const EdgeVector& ev2 = possProhibitorTo->getConnectedEdges();
338  // go through the following edge,
339  // check whether one of these connections is prohibited
340  for (i = ev2.begin(); i != ev2.end(); ++i) {
341  std::vector<NBNode*>::const_iterator incoming2 =
342  find_if(myControlledNodes.begin(), myControlledNodes.end(), NBContHelper::node_with_incoming_finder(possProhibitorTo));
343  if (incoming2 == myControlledNodes.end()) {
344  continue;
345  }
346  NBNode* incnode2 = *incoming2;
347  if (incnode2 != outnode) {
348  continue;
349  }
350  if (incnode2->getDirection(possProhibitorTo, *i) != LinkDirection::STRAIGHT) {
351  continue;
352  }
353  bool ret1 = incnode2->foes(possProhibitorTo, *i,
354  possProhibitedFrom, possProhibitedTo);
355  bool ret2 = incnode2->forbids(possProhibitorTo, *i,
356  possProhibitedFrom, possProhibitedTo,
357  regardNonSignalisedLowerPriority);
358  bool ret = ret1 || ret2;
359  if (ret) {
360 #ifdef DEBUG_RIGHT_OF_WAY
361  if (DEBUGCOND) {
362  std::cout << " differentNodes: forbids (2)\n";
363  }
364 #endif
365  return true;
366  }
367  }
368 #ifdef DEBUG_RIGHT_OF_WAY
369  if (DEBUGCOND) {
370  std::cout << " differentNodes: allows\n";
371  }
372 #endif
373  return false;
374  }
375  // both links are located at the same node
376  // check using this node's information
377  const bool result = incnode->forbids(possProhibitorFrom, possProhibitorTo,
378  possProhibitedFrom, possProhibitedTo,
379  regardNonSignalisedLowerPriority);
380 #ifdef DEBUG_RIGHT_OF_WAY
381  if (DEBUGCOND) {
382  std::cout << " sameNodes: " << (result ? "forbids" : "allows") << "\n";
383  }
384 #endif
385  return result;
386 }
387 
388 
389 bool
390 NBTrafficLightDefinition::foes(const NBEdge* const from1, const NBEdge* const to1,
391  const NBEdge* const from2, const NBEdge* const to2) const {
392  if (to1 == nullptr || to2 == nullptr) {
393  return false;
394  }
395  // retrieve both nodes (it is possible that a connection
396  std::vector<NBNode*>::const_iterator incoming =
397  find_if(myControlledNodes.begin(), myControlledNodes.end(),
399  std::vector<NBNode*>::const_iterator outgoing =
400  find_if(myControlledNodes.begin(), myControlledNodes.end(),
402  assert(incoming != myControlledNodes.end());
403  NBNode* incnode = *incoming;
404  NBNode* outnode = *outgoing;
405  if (incnode != outnode) {
406  return false;
407  }
408  return incnode->foes(from1, to1, from2, to2);
409 }
410 
411 
412 void
414  if (std::find(myControlledNodes.begin(), myControlledNodes.end(), node) == myControlledNodes.end()) {
415  myControlledNodes.push_back(node);
417  }
418  node->addTrafficLight(this);
419 }
420 
421 
422 void
424  std::vector<NBNode*>::iterator i = std::find(myControlledNodes.begin(), myControlledNodes.end(), node);
425  if (i != myControlledNodes.end()) {
426  myControlledNodes.erase(i);
427  }
428  // !!! remove in node?
429 }
430 
431 
432 void
433 NBTrafficLightDefinition::addControlledInnerEdges(const std::vector<std::string>& edges) {
434  myControlledInnerEdges.insert(edges.begin(), edges.end());
435 }
436 
437 
438 std::vector<std::string>
440  return std::vector<std::string>(myControlledInnerEdges.begin(), myControlledInnerEdges.end());
441 }
442 
443 
444 const EdgeVector&
446  return myIncomingEdges;
447 }
448 
449 
450 void
452  int tlIndex = 0;
453  // build the list of links which are controled by the traffic light
454  std::vector<int> indirectLeft;
455  for (EdgeVector::iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
456  NBEdge* incoming = *i;
457  int noLanes = incoming->getNumLanes();
458  for (int j = 0; j < noLanes; j++) {
459  std::vector<NBEdge::Connection> connected = incoming->getConnectionsFromLane(j);
460  for (std::vector<NBEdge::Connection>::iterator k = connected.begin(); k != connected.end(); k++) {
461  const NBEdge::Connection& el = *k;
462  if (incoming->mayBeTLSControlled(el.fromLane, el.toEdge, el.toLane)) {
463  if (el.toEdge != nullptr && el.toLane >= (int) el.toEdge->getNumLanes()) {
464  throw ProcessError("Connection '" + incoming->getID() + "_" + toString(j) + "->" + el.toEdge->getID() + "_" + toString(el.toLane) + "' yields in a not existing lane.");
465  }
466  if (incoming->getToNode()->getType() == SumoXMLNodeType::RAIL_CROSSING
467  && isRailway(incoming->getPermissions())) {
468  // railways stay uncontrolled at rail crossing but they
469  // must be registered in MSRailCrossing
470  into.push_back(NBConnection(incoming, el.fromLane, el.toEdge, el.toLane, -1));
471  } else if (incoming->getToNode()->getType() == SumoXMLNodeType::RAIL_SIGNAL
472  && incoming->getToNode()->getDirection(incoming, el.toEdge) == LinkDirection::TURN) {
473  // turnarounds stay uncontrolled at rail signal
474  } else {
475  into.push_back(NBConnection(incoming, el.fromLane, el.toEdge, el.toLane, tlIndex++));
476  if (el.indirectLeft) {
477  indirectLeft.push_back((int)into.size() - 1);
478  }
479  }
480  }
481  }
482  }
483  }
484  if (indirectLeft.size() > 0) {
485  // assign linkIndex2 to indirect left turns
486  for (int i : indirectLeft) {
487  NBConnection& c = into[i];
488  // find straight connection with the same toEdge
489  for (const NBConnection& c2 : into) {
490  if (c2.getTo() == c.getTo() && c2.getFrom() != c.getFrom()) {
491  LinkDirection dir = c.getFrom()->getToNode()->getDirection(c2.getFrom(), c2.getTo());
492  if (dir == LinkDirection::STRAIGHT) {
493  c.setTLIndex2(c2.getTLIndex());
494  break;
495  }
496  }
497  }
498  }
499  }
500 
501  if (into.size() > 0 && tlIndex == 0) {
502  WRITE_WARNINGF("The rail crossing '%' does not have any roads.", getID());
503  }
504 }
505 
506 
507 bool
508 NBTrafficLightDefinition::needsCont(const NBEdge* fromE, const NBEdge* toE, const NBEdge* otherFromE, const NBEdge* otherToE) const {
511  assert(myNeedsContRelationReady);
512  }
513  return std::find(myNeedsContRelation.begin(), myNeedsContRelation.end(),
514  StreamPair(fromE, toE, otherFromE, otherToE)) != myNeedsContRelation.end();
515 }
516 
517 
518 void
520  if (!amInvalid()) {
522  dummy.initNeedsContRelation();
524  for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
525  (*i)->removeTrafficLight(&dummy);
526  }
527  }
529 }
530 
531 
532 bool
533 NBTrafficLightDefinition::rightOnRedConflict(int index, int foeIndex) const {
537  NBTrafficLightLogic* tllDummy = dummy.computeLogicAndConts(0, true);
538  delete tllDummy;
540  for (std::vector<NBNode*>::const_iterator i = myControlledNodes.begin(); i != myControlledNodes.end(); i++) {
541  (*i)->removeTrafficLight(&dummy);
542  }
544  //std::cout << " rightOnRedConflicts tls=" << getID() << " pro=" << getProgramID() << "\n";
545  //for (RightOnRedConflicts::const_iterator it = myRightOnRedConflicts.begin(); it != myRightOnRedConflicts.end(); ++it) {
546  // std::cout << " " << it->first << ", " << it->second << "\n";
547  //}
548  }
549  return std::find(myRightOnRedConflicts.begin(), myRightOnRedConflicts.end(), std::make_pair(index, foeIndex)) != myRightOnRedConflicts.end();
550 }
551 
552 std::string
554  return getID() + ':' + getProgramID() + '@' + toString(this);
555 }
556 
557 
558 /****************************************************************************/
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:281
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:35
#define DEBUGCOND
long long int SUMOTime
Definition: SUMOTime.h:32
bool isRailway(SVCPermissions permissions)
Returns whether an edge with the given permission is a railway edge.
TrafficLightType
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
@ TURN
The link is a 180 degree turn.
@ STRAIGHT
The link is a straight direction.
T MAX2(T a, T b)
Definition: StdDefs.h:80
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)
void setTLIndex2(int tlIndex)
Definition: NBConnection.h:102
NBEdge * getTo() const
returns the to-edge (end of the connection)
static double maxSpeed(const EdgeVector &ev)
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
void setInsideTLS(bool inside)
Marks this edge being within an intersection.
Definition: NBEdge.h:1106
int getFirstNonPedestrianLaneIndex(int direction, bool exclusive=false) const
return the first lane with permissions other than SVC_PEDESTRIAN and 0
Definition: NBEdge.cpp:4082
const std::string & getID() const
Definition: NBEdge.h:1465
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:541
std::vector< Connection > getConnectionsFromLane(int lane, NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
Definition: NBEdge.cpp:1206
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:515
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
Definition: NBEdge.cpp:3409
EdgeVector getConnectedEdges() const
Returns the list of outgoing edges unsorted.
Definition: NBEdge.cpp:1305
const std::vector< Connection > & getConnections() const
Returns the connections.
Definition: NBEdge.h:1006
Used for sorting the cells by the begin time they describe.
Definition: NBNode.h:752
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
bool mustBrake(const NBEdge *const from, const NBEdge *const to, int fromLane, int toLane, bool includePedCrossings) const
Returns the information whether the described flow must let any other flow pass.
Definition: NBNode.cpp:1892
SumoXMLNodeType getType() const
Returns the type of this node.
Definition: NBNode.h:273
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: NBNode.cpp:2061
bool hasOutgoing(const NBEdge *const e) const
Returns whether the given edge starts at this node.
Definition: NBNode.cpp:1750
static const int FORWARD
edge directions (for pedestrian related stuff)
Definition: NBNode.h:204
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: NBNode.cpp:2071
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
Definition: NBNode.cpp:365
A traffic light logics which must be computed (only nodes/edges are given)
Definition: NBOwnTLDef.h:44
NBTrafficLightLogic * computeLogicAndConts(int brakingTimeSeconds, bool onlyConts=false)
helper function for myCompute
Definition: NBOwnTLDef.cpp:252
void initNeedsContRelation() const
Definition: NBOwnTLDef.cpp:851
virtual bool rightOnRedConflict(int index, int foeIndex) const
whether the given index must yield to the foeIndex while turning right on a red light
const std::string & getProgramID() const
Returns the ProgramID.
virtual ~NBTrafficLightDefinition()
Destructor.
void addControlledInnerEdges(const std::vector< std::string > &edges)
Adds the given ids into the list of inner edges controlled by the tls.
const EdgeVector & getIncomingEdges() const
Returns the list of incoming edges (must be build first)
bool needsCont(const NBEdge *fromE, const NBEdge *toE, const NBEdge *otherFromE, const NBEdge *otherToE) const
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
virtual NBTrafficLightLogic * myCompute(int brakingTime)=0
Computes the traffic light logic finally in dependence to the type.
virtual void removeNode(NBNode *node)
Removes the given node from the list of controlled nodes.
EdgeVector myIncomingEdges
The list of incoming edges.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
std::vector< std::string > getControlledInnerEdges() const
Retrieve the ids of edges explicitly controlled by the tls.
static std::set< NBEdge * > collectReachable(EdgeVector outer, const EdgeVector &within, bool checkControlled)
RightOnRedConflicts myRightOnRedConflicts
EdgeVector myEdgesWithin
The list of edges within the area controlled by the tls.
static const std::string DummyID
id for temporary definitions
virtual void collectLinks()=0
Collects the links participating in this traffic light.
int computeBrakingTime(double minDecel) const
Computes the time vehicles may need to brake.
bool forbids(const NBEdge *const possProhibitorFrom, const NBEdge *const possProhibitorTo, const NBEdge *const possProhibitedFrom, const NBEdge *const possProhibitedTo, bool regardNonSignalisedLowerPriority, bool sameNodeOnly=false) const
Returns the information whether "prohibited" flow must let "prohibitor" flow pass.
NBTrafficLightLogic * compute(OptionsCont &oc)
Computes the traffic light logic.
NBConnectionVector myControlledLinks
The list of controlled links.
static const std::string DefaultProgramID
bool mustBrake(const NBEdge *const from, const NBEdge *const to) const
Returns the information whether the described flow must let any other flow pass.
virtual void initNeedsContRelation() const
virtual void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
void collectAllLinks(NBConnectionVector &into)
helper method for use in NBOwnTLDef and NBLoadedSUMOTLDef
NBTrafficLightDefinition(const std::string &id, const std::vector< NBNode * > &junctions, const std::string &programID, SUMOTime offset, TrafficLightType type)
Constructor.
static const SUMOTime UNSPECIFIED_DURATION
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.
std::string getDescription() const
get ID and programID together (for convenient debugging)
virtual void collectEdges()
Build the list of participating edges.
std::set< std::string > myControlledInnerEdges
Set of inner edges that shall be controlled, though.
A SUMO-compliant built logic for a traffic light.
Base class for objects which have an id.
Definition: Named.h:54
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A storage for options typed value containers)
Definition: OptionsCont.h:89
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
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
void updateParameters(const std::map< std::string, std::string > &mapArg)
Adds or updates all given parameters from the map.
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
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
data structure for caching needsCont information