Eclipse SUMO - Simulation of Urban MObility
NBLoadedTLDef.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-2020 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 // A loaded (complete) traffic light logic
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include <vector>
26 #include <set>
27 #include <cassert>
28 #include <iterator>
30 #include <utils/common/ToString.h>
32 #include "NBTrafficLightLogic.h"
34 #include "NBLoadedTLDef.h"
35 #include "NBNode.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
41 /* -------------------------------------------------------------------------
42  * NBLoadedTLDef::SignalGroup-methods
43  * ----------------------------------------------------------------------- */
45  : Named(id) {}
46 
48 
49 void
51  assert(c.getFromLane() < 0 || c.getFrom()->getNumLanes() > c.getFromLane());
52  myConnections.push_back(c);
53 }
54 
55 
56 void
58  myPhases.push_back(PhaseDef(time, color));
59 }
60 
61 
62 void
64  myTRedYellow = tRedYellow;
65  myTYellow = tYellow;
66 }
67 
68 
69 void
71  std::sort(myPhases.begin(), myPhases.end(), [](const PhaseDef & p1, const PhaseDef & p2) {
72  return p1.myTime < p2.myTime;
73  });
74 }
75 
76 
77 void
79  if (myTYellow < 0) {
80  // was not set before (was not loaded)
81  myTYellow = tyellow;
82  } else if (forced && myTYellow < tyellow) {
83  WRITE_WARNING("TYellow of signal group '" + getID() + "' was less than the computed one; patched (was:" + toString(myTYellow) + ", is:" + time2string(tyellow) + ")");
84  myTYellow = tyellow;
85  }
86 }
87 
88 
89 std::vector<SUMOTime>
91  // within the phase container, we should have the green and red phases add their times
92  std::vector<SUMOTime> ret;
93  for (const PhaseDef& p : myPhases) {
94  ret.push_back(p.myTime);
95  }
96  // further, we possibly should set the yellow phases
97  if (myTYellow > 0) {
98  for (const PhaseDef& p : myPhases) {
99  if (p.myColor == TLCOLOR_RED) {
100  ret.push_back((p.myTime + myTYellow) % cycleDuration);
101  }
102  }
103  }
104  return ret;
105 }
106 
107 
108 int
110  return (int) myConnections.size();
111 }
112 
113 
114 bool
116  assert(myPhases.size() != 0);
117  for (std::vector<PhaseDef>::const_reverse_iterator i = myPhases.rbegin(); i != myPhases.rend(); i++) {
118  SUMOTime nextTime = (*i).myTime;
119  if (time >= nextTime) {
120  return (*i).myColor == TLCOLOR_GREEN;
121  }
122  }
123  return (*(myPhases.end() - 1)).myColor == TLCOLOR_GREEN;
124 }
125 
126 
127 bool
129  bool has_red_now = !mayDrive(time);
130  bool had_green = mayDrive(time - myTYellow);
131  return has_red_now && had_green;
132 }
133 
134 
135 const NBConnection&
137  assert(pos < (int)myConnections.size());
138  return myConnections[pos];
139 }
140 
141 
142 bool
144  for (NBConnectionVector::const_iterator i = myConnections.begin(); i != myConnections.end(); i++) {
145  if ((*i).getFrom() == from) {
146  return true;
147  }
148  }
149  return false;
150 }
151 
152 
153 void
155  NBConnectionVector newConns;
156  for (NBConnectionVector::iterator i = myConnections.begin(); i != myConnections.end();) {
157  if ((*i).getFrom() == which) {
158  NBConnection conn((*i).getFrom(), (*i).getTo());
159  i = myConnections.erase(i);
160  for (EdgeVector::const_iterator j = by.begin(); j != by.end(); j++) {
161  NBConnection curr(conn);
162  if (!curr.replaceFrom(which, *j)) {
163  throw ProcessError("Could not replace edge '" + which->getID() + "' by '" + (*j)->getID() + "'.\nUndefined...");
164  }
165  newConns.push_back(curr);
166  }
167  } else {
168  i++;
169  }
170  }
171  copy(newConns.begin(), newConns.end(),
172  back_inserter(myConnections));
173 }
174 
175 
176 bool
178  for (NBConnectionVector::const_iterator i = myConnections.begin(); i != myConnections.end(); i++) {
179  if ((*i).getTo() == to) {
180  return true;
181  }
182  }
183  return false;
184 }
185 
186 
187 void
189  NBConnectionVector newConns;
190  for (NBConnectionVector::iterator i = myConnections.begin(); i != myConnections.end();) {
191  if ((*i).getTo() == which) {
192  NBConnection conn((*i).getFrom(), (*i).getTo());
193  i = myConnections.erase(i);
194  for (EdgeVector::const_iterator j = by.begin(); j != by.end(); j++) {
195  NBConnection curr(conn);
196  if (!curr.replaceTo(which, *j)) {
197  throw ProcessError("Could not replace edge '" + which->getID() + "' by '" + (*j)->getID() + "'.\nUndefined...");
198  }
199  newConns.push_back(curr);
200  }
201  } else {
202  i++;
203  }
204  }
205  copy(newConns.begin(), newConns.end(),
206  back_inserter(myConnections));
207 }
208 
209 
210 void
211 NBLoadedTLDef::SignalGroup::remap(NBEdge* removed, int removedLane,
212  NBEdge* by, int byLane) {
213  for (NBConnectionVector::iterator i = myConnections.begin(); i != myConnections.end(); i++) {
214  if ((*i).getTo() == removed
215  &&
216  ((*i).getToLane() == removedLane
217  ||
218  (*i).getToLane() == -1)) {
219  (*i).replaceTo(removed, removedLane, by, byLane);
220 
221  } else if ((*i).getTo() == removed && removedLane == -1) {
222  (*i).replaceTo(removed, by);
223  }
224 
225  if ((*i).getFrom() == removed
226  &&
227  ((*i).getFromLane() == removedLane
228  ||
229  (*i).getFromLane() == -1)) {
230  (*i).replaceFrom(removed, removedLane, by, byLane);
231 
232  } else if ((*i).getFrom() == removed && removedLane == -1) {
233  (*i).replaceFrom(removed, by);
234  }
235  }
236 }
237 
238 
239 /* -------------------------------------------------------------------------
240  * NBLoadedTLDef::Phase-methods
241  * ----------------------------------------------------------------------- */
242 NBLoadedTLDef::NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id,
243  const std::vector<NBNode*>& junctions, SUMOTime offset, TrafficLightType type) :
244  NBTrafficLightDefinition(id, junctions, DefaultProgramID, offset, type),
245  myEdgeCont(&ec) {
246 }
247 
248 
249 NBLoadedTLDef::NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, NBNode* junction, SUMOTime offset, TrafficLightType type) :
250  NBTrafficLightDefinition(id, junction, DefaultProgramID, offset, type),
251  myEdgeCont(&ec) {
252 }
253 
254 
255 NBLoadedTLDef::NBLoadedTLDef(const NBEdgeCont& ec, const std::string& id, SUMOTime offset, TrafficLightType type) :
256  NBTrafficLightDefinition(id, DefaultProgramID, offset, type),
257  myEdgeCont(&ec) {
258 }
259 
260 
262  for (SignalGroupCont::iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); ++i) {
263  delete (*i).second;
264  }
265 }
266 
267 
269 NBLoadedTLDef::myCompute(int brakingTimeSeconds) {
271  NBLoadedTLDef::SignalGroupCont::const_iterator i;
272  // compute the switching times and count the signals
273  std::set<SUMOTime> switchTimes;
274  int numSignals = 0;
275  for (const auto& i : mySignalGroups) {
276  NBLoadedTLDef::SignalGroup* const group = i.second;
277  // needed later
278  group->sortPhases();
279  // patch the yellow time for this group
280  group->patchTYellow(TIME2STEPS(brakingTimeSeconds), OptionsCont::getOptions().getBool("tls.yellow.patch-small"));
281  // copy the now valid times into the container
282  // both the given red and green phases are added and also the
283  // yellow times
284  const std::vector<SUMOTime> gtimes = group->getTimes(myCycleDuration);
285  switchTimes.insert(gtimes.begin(), gtimes.end());
286  numSignals += group->getLinkNo();
287  }
288 
289  // build the phases
290  NBTrafficLightLogic* logic = new NBTrafficLightLogic(getID(), getProgramID(), numSignals, myOffset, myType);
291  SUMOTime prev = -1;
292  for (const SUMOTime l : switchTimes) {
293  if (prev != -1) {
294  logic->addStep(l - prev, buildPhaseState(prev));
295  }
296  prev = l;
297  }
298  logic->addStep(myCycleDuration + (*switchTimes.begin()) - prev, buildPhaseState(prev));
299  // check whether any warnings were printed
300  if (MsgHandler::getWarningInstance()->wasInformed()) {
301  WRITE_WARNING("During computation of traffic light '" + getID() + "'.");
302  }
303  logic->closeBuilding();
304 
305  // initialize myNeedsContRelation
306  myNeedsContRelation.clear();
307  const bool controlledWithin = !OptionsCont::getOptions().getBool("tls.uncontrolled-within");
308  const std::vector<NBTrafficLightLogic::PhaseDefinition> phases = logic->getPhases();
309  for (std::vector<NBTrafficLightLogic::PhaseDefinition>::const_iterator it = phases.begin(); it != phases.end(); it++) {
310  const std::string state = (*it).state;
311  for (NBConnectionVector::const_iterator it1 = myControlledLinks.begin(); it1 != myControlledLinks.end(); it1++) {
312  const NBConnection& c1 = *it1;
313  const int i1 = c1.getTLIndex();
314  if (i1 == NBConnection::InvalidTlIndex || state[i1] != 'g' || c1.getFrom() == nullptr || c1.getTo() == nullptr) {
315  continue;
316  }
317  for (NBConnectionVector::const_iterator it2 = myControlledLinks.begin(); it2 != myControlledLinks.end(); it2++) {
318  const NBConnection& c2 = *it2;
319  const int i2 = c2.getTLIndex();
321  && i2 != i1
322  && (state[i2] == 'G' || state[i2] == 'g')
323  && c2.getFrom() != nullptr && c2.getTo() != nullptr) {
324  const bool rightTurnConflict = NBNode::rightTurnConflict(
325  c1.getFrom(), c1.getTo(), c1.getFromLane(), c2.getFrom(), c2.getTo(), c2.getFromLane());
326  if (forbids(c2.getFrom(), c2.getTo(), c1.getFrom(), c1.getTo(), true, controlledWithin) || rightTurnConflict) {
327  myNeedsContRelation.insert(StreamPair(c1.getFrom(), c1.getTo(), c2.getFrom(), c2.getTo()));
328  }
329  }
330  }
331  }
332  }
334 
335  return logic;
336 }
337 
338 
339 void
341  // assign the tl-indices to the edge connections
342  for (NBConnectionVector::const_iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) {
343  const NBConnection& c = *it;
346  }
347  }
348 }
349 
350 
351 std::string
353  int pos = 0;
354  std::string state;
355  // set the green and yellow information first;
356  // the information whether other have to break needs those masks
357  // completely filled
358  for (SignalGroupCont::const_iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); i++) {
359  SignalGroup* group = (*i).second;
360  int linkNo = group->getLinkNo();
361  bool mayDrive = group->mayDrive(time);
362  bool hasYellow = group->hasYellow(time);
363  char c = 'r';
364  if (mayDrive) {
365  c = 'g';
366  }
367  if (hasYellow) {
368  c = 'y';
369  }
370  for (int j = 0; j < linkNo; j++) {
371  const NBConnection& conn = group->getConnection(j);
372  NBConnection assConn(conn);
373  // assert that the connection really exists
374  if (assConn.check(*myEdgeCont)) {
375  state = state + c;
376  ++pos;
377  }
378  }
379  }
380  // set the braking mask
381  pos = 0;
382  for (SignalGroupCont::const_iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); i++) {
383  SignalGroup* group = (*i).second;
384  int linkNo = group->getLinkNo();
385  for (int j = 0; j < linkNo; j++) {
386  const NBConnection& conn = group->getConnection(j);
387  NBConnection assConn(conn);
388  if (assConn.check(*myEdgeCont)) {
389  if (!mustBrake(assConn, state, pos)) {
390  if (state[pos] == 'g') {
391  state[pos] = 'G';
392  }
393  if (state[pos] == 'y') {
394  state[pos] = 'Y';
395  }
396  }
397  pos++;
398  }
399  }
400  }
401  return state;
402 }
403 
404 
405 bool
407  const std::string& state,
408  int strmpos) const {
409  // check whether the stream has red
410  if (state[strmpos] != 'g' && state[strmpos] != 'G') {
411  return true;
412  }
413 
414  // check whether another stream which has green is a higher
415  // priorised foe to the given
416  int pos = 0;
417  for (SignalGroupCont::const_iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); i++) {
418  SignalGroup* group = (*i).second;
419  // get otherlinks that have green
420  int linkNo = group->getLinkNo();
421  for (int j = 0; j < linkNo; j++) {
422  // get the current connection (possible foe)
423  const NBConnection& other = group->getConnection(j);
424  NBConnection possProhibitor(other);
425  // if the connction ist still valid ...
426  if (possProhibitor.check(*myEdgeCont)) {
427  // ... do nothing if it starts at the same edge
428  if (possProhibited.getFrom() == possProhibitor.getFrom()) {
429  pos++;
430  continue;
431  }
432  if (state[pos] == 'g' || state[pos] == 'G') {
433  if (NBTrafficLightDefinition::mustBrake(possProhibited, possProhibitor, true)) {
434  return true;
435  }
436  }
437  pos++;
438  }
439  }
440  }
441  return false;
442 }
443 
444 
445 void
447  // assign participating nodes to the request
448  collectNodes();
449  // collect the information about participating edges and links
450  collectEdges();
451  collectLinks();
452 }
453 
454 void
456  myControlledNodes.clear();
457  SignalGroupCont::const_iterator m;
458  for (m = mySignalGroups.begin(); m != mySignalGroups.end(); m++) {
459  SignalGroup* group = (*m).second;
460  int linkNo = group->getLinkNo();
461  for (int j = 0; j < linkNo; j++) {
462  const NBConnection& conn = group->getConnection(j);
463  NBEdge* edge = conn.getFrom();
464  NBNode* node = edge->getToNode();
465  myControlledNodes.push_back(node);
466  }
467  }
469 }
470 
471 
472 void
474  myControlledLinks.clear();
475  // build the list of links which are controled by the traffic light
476  for (EdgeVector::iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
477  NBEdge* incoming = *i;
478  int noLanes = incoming->getNumLanes();
479  for (int j = 0; j < noLanes; j++) {
480  std::vector<NBEdge::Connection> elv = incoming->getConnectionsFromLane(j);
481  for (std::vector<NBEdge::Connection>::iterator k = elv.begin(); k != elv.end(); k++) {
482  NBEdge::Connection el = *k;
483  if (el.toEdge != nullptr) {
484  myControlledLinks.push_back(NBConnection(incoming, j, el.toEdge, el.toLane));
485  }
486  }
487  }
488  }
489 
490  // assign tl-indices to myControlledLinks
491  int pos = 0;
492  for (SignalGroupCont::const_iterator m = mySignalGroups.begin(); m != mySignalGroups.end(); m++) {
493  SignalGroup* group = (*m).second;
494  int linkNo = group->getLinkNo();
495  for (int j = 0; j < linkNo; j++) {
496  const NBConnection& conn = group->getConnection(j);
497  assert(conn.getFromLane() < 0 || (int) conn.getFrom()->getNumLanes() > conn.getFromLane());
498  NBConnection tst(conn);
499  tst.setTLIndex(pos);
500  if (tst.check(*myEdgeCont)) {
501  if (tst.getFrom()->mayBeTLSControlled(tst.getFromLane(), tst.getTo(), tst.getToLane())) {
502  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) {
503  NBConnection& c = *it;
505  && tst.getFrom() == c.getFrom() && tst.getTo() == c.getTo()
506  && (tst.getFromLane() < 0 || tst.getFromLane() == c.getFromLane())
507  && (tst.getToLane() < 0 || tst.getToLane() == c.getToLane())) {
508  c.setTLIndex(pos);
509  }
510  }
511  //std::cout << getID() << " group=" << (*m).first << " tst=" << tst << "\n";
512  pos++;
513  }
514  } else {
515  WRITE_WARNING("Could not set signal on connection (signal: " + getID() + ", group: " + group->getID() + ")");
516  }
517  }
518  }
519 }
520 
521 
522 bool
523 NBLoadedTLDef::addToSignalGroup(const std::string& groupid,
524  const NBConnection& connection) {
525  if (mySignalGroups.find(groupid) == mySignalGroups.end()) {
526  return false;
527  }
528  mySignalGroups[groupid]->addConnection(connection);
529  NBNode* n1 = connection.getFrom()->getToNode();
530  if (n1 != nullptr) {
531  addNode(n1);
532  n1->addTrafficLight(this);
533  }
534  NBNode* n2 = connection.getTo()->getFromNode();
535  if (n2 != nullptr) {
536  addNode(n2);
537  n2->addTrafficLight(this);
538  }
539  return true;
540 }
541 
542 
543 bool
544 NBLoadedTLDef::addToSignalGroup(const std::string& groupid,
545  const NBConnectionVector& connections) {
546  bool ok = true;
547  for (NBConnectionVector::const_iterator i = connections.begin(); i != connections.end(); i++) {
548  ok &= addToSignalGroup(groupid, *i);
549  }
550  return ok;
551 }
552 
553 
554 void
555 NBLoadedTLDef::addSignalGroup(const std::string& id) {
556  assert(mySignalGroups.find(id) == mySignalGroups.end());
557  mySignalGroups[id] = new SignalGroup(id);
558 }
559 
560 
561 void
562 NBLoadedTLDef::addSignalGroupPhaseBegin(const std::string& groupid, SUMOTime time,
563  TLColor color) {
564  assert(mySignalGroups.find(groupid) != mySignalGroups.end());
565  mySignalGroups[groupid]->addPhaseBegin(time, color);
566 }
567 
568 void
569 NBLoadedTLDef::setSignalYellowTimes(const std::string& groupid,
570  SUMOTime myTRedYellow, SUMOTime myTYellow) {
571  assert(mySignalGroups.find(groupid) != mySignalGroups.end());
572  mySignalGroups[groupid]->setYellowTimes(myTRedYellow, myTYellow);
573 }
574 
575 
576 void
578  myCycleDuration = cycleDur;
579 }
580 
581 
582 void
584  const EdgeVector& incoming,
585  const EdgeVector& outgoing) {
586  for (SignalGroupCont::const_iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); i++) {
587  SignalGroup* group = (*i).second;
588  if (group->containsIncoming(removed)) {
589  group->remapIncoming(removed, incoming);
590  }
591  if (group->containsOutgoing(removed)) {
592  group->remapOutgoing(removed, outgoing);
593  }
594  }
595 }
596 
597 
598 void
599 NBLoadedTLDef::replaceRemoved(NBEdge* removed, int removedLane,
600  NBEdge* by, int byLane, bool incoming) {
601  for (SignalGroupCont::const_iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); i++) {
602  SignalGroup* group = (*i).second;
603  if ((incoming && group->containsIncoming(removed)) || (!incoming && group->containsOutgoing(removed))) {
604  group->remap(removed, removedLane, by, byLane);
605  }
606  }
607 }
608 
609 
610 void
613  throw ProcessError("myNeedsContRelation was not propperly initialized\n");
614  }
615 }
616 
617 
618 int
622  if (logic != nullptr) {
623  return logic->getNumLinks() - 1;
624  } else {
625  return -1;
626  }
627 }
628 
629 
630 /****************************************************************************/
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:276
std::vector< NBConnection > NBConnectionVector
Definition of a connection vector.
std::vector< NBEdge * > EdgeVector
container for (sorted) edges
Definition: NBCont.h:34
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
long long int SUMOTime
Definition: SUMOTime.h:31
TrafficLightType
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:67
virtual void clear(bool resetInformed=true)
Clears information whether an error occurred previously and print aggregated message summary.
Definition: MsgHandler.cpp:159
NBEdge * getFrom() const
returns the from-edge (start of the connection)
int getFromLane() const
returns the from-lane
bool replaceTo(NBEdge *which, NBEdge *by)
replaces the to-edge by the one given
int getTLIndex() const
returns the index within the controlling tls or InvalidTLIndex if this link is unontrolled
Definition: NBConnection.h:91
static const int InvalidTlIndex
Definition: NBConnection.h:123
bool replaceFrom(NBEdge *which, NBEdge *by)
replaces the from-edge by the one given
void setTLIndex(int tlIndex)
Definition: NBConnection.h:99
int getToLane() const
returns the to-lane
NBEdge * getTo() const
returns the to-edge (end of the connection)
bool check(const NBEdgeCont &ec)
checks whether the edges are still valid
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
const std::string & getID() const
Definition: NBEdge.h:1423
NBNode * getToNode() const
Returns the destination node of the edge.
Definition: NBEdge.h:516
bool setControllingTLInformation(const NBConnection &c, const std::string &tlID)
Returns if the link could be set as to be controlled.
Definition: NBEdge.cpp:3070
std::vector< Connection > getConnectionsFromLane(int lane, NBEdge *to=nullptr, int toLane=-1) const
Returns connections from a given lane.
Definition: NBEdge.cpp:1152
int getNumLanes() const
Returns the number of lanes.
Definition: NBEdge.h:490
bool mayBeTLSControlled(int fromLane, NBEdge *toEdge, int toLane) const
return true if certain connection must be controlled by TLS
Definition: NBEdge.cpp:3059
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:509
Definition of a single, loaded phase.
A single signal group, may control several connections.
Definition: NBLoadedTLDef.h:44
void remapOutgoing(NBEdge *which, const EdgeVector &by)
Replaces the given outgoing edge by the others given.
SignalGroup(const std::string &id)
Constructor.
void addPhaseBegin(SUMOTime time, TLColor color)
Sets the begin of a phase.
void addConnection(const NBConnection &c)
Inserts a controlled connection.
std::vector< SUMOTime > getTimes(SUMOTime cycleDuration) const
Returns the times at which the signal switches.
bool mayDrive(SUMOTime time) const
Returns whether vehicles on controlled links may drive at the given time.
void patchTYellow(SUMOTime tyellow, bool forced)
Sets the yellow time.
bool hasYellow(SUMOTime time) const
Returns whether controlled links have yellow at the given time.
const NBConnection & getConnection(int pos) const
Returns the connection at the given index.
void remap(NBEdge *removed, int removedLane, NBEdge *by, int byLane)
Replaces a removed edge/lane.
bool containsIncoming(NBEdge *from) const
Returns whether this signal controls the given edge.
void setYellowTimes(SUMOTime tRedYellowe, SUMOTime tYellow)
Sets the times for redyellow and yellow.
void sortPhases()
Sorts the phases.
bool containsOutgoing(NBEdge *to) const
Returns whether this signal controls a connection where the given edge is the destination.
void remapIncoming(NBEdge *which, const EdgeVector &by)
Replaces the given incoming edge by the others given.
int getLinkNo() const
Returns the number of links (connection) controlled by this signal.
void setParticipantsInformation()
Builds the list of participating nodes/edges/links.
void collectNodes()
Collects the nodes participating in this traffic light.
void replaceRemoved(NBEdge *removed, int removedLane, NBEdge *by, int byLane, bool incoming)
Replaces a removed edge/lane.
bool addToSignalGroup(const std::string &groupid, const NBConnection &connection)
Adds a connection to a signal group.
int getMaxIndex()
Returns the maximum index controlled by this traffic light.
std::string buildPhaseState(const SUMOTime time) const
Builds the phase for a given time.
~NBLoadedTLDef()
Destructor.
void addSignalGroupPhaseBegin(const std::string &groupid, SUMOTime time, TLColor color)
Sets the information about the begin of a phase.
SUMOTime myCycleDuration
The duration of a single cycle.
const NBEdgeCont * myEdgeCont
void setSignalYellowTimes(const std::string &groupid, SUMOTime tRedYellow, SUMOTime tYellow)
Sets the times the light is yellow or red/yellow.
NBLoadedTLDef(const NBEdgeCont &ec, const std::string &id, const std::vector< NBNode * > &junctions, SUMOTime offset, TrafficLightType type)
Constructor.
void addSignalGroup(const std::string &id)
Adds a signal group.
void setCycleDuration(SUMOTime cycleDur)
Sets the duration of a cycle.
SignalGroupCont mySignalGroups
Controlled signal groups.
NBTrafficLightLogic * myCompute(int brakingTimeSeconds)
Computes the traffic light logic finally in dependence to the type.
void setTLControllingInformation() const
Informs edges about being controlled by a tls.
void collectLinks()
Collects the links participating in this traffic light.
bool mustBrake(const NBConnection &possProhibited, const std::string &state, int strmpos) const
Returns the information whether a connection must brake, given a phase.
void initNeedsContRelation() const
void remapRemoved(NBEdge *removed, const EdgeVector &incoming, const EdgeVector &outgoing)
Replaces occurences of the removed edge in incoming/outgoing edges of all definitions.
Used for sorting the cells by the begin time they describe.
Definition: NBNode.h:745
Represents a single node (junction) during network building.
Definition: NBNode.h:66
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:1819
void addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
Definition: NBNode.cpp:364
The base class for traffic light logic definitions.
const std::string & getProgramID() const
Returns the ProgramID.
TLColor
An enumeration of possible tl-signal states.
@ TLCOLOR_GREEN
Signal shows green.
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
EdgeVector myIncomingEdges
The list of incoming edges.
virtual void addNode(NBNode *node)
Adds a node to the traffic light logic.
TrafficLightType myType
The algorithm type for the traffic light.
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.
SUMOTime myOffset
The offset in the program.
virtual void collectEdges()
Build the list of participating edges.
A SUMO-compliant built logic for a traffic light.
void closeBuilding(bool checkVarDurations=true)
closes the building process
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
int getNumLinks()
Returns the number of participating links.
void addStep(SUMOTime duration, const std::string &state, const std::vector< int > &next=std::vector< int >(), const std::string &name="", int index=-1)
Adds a phase to the logic.
Base class for objects which have an id.
Definition: Named.h:53
const std::string & getID() const
Returns the id.
Definition: Named.h:73
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
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:188
int toLane
The lane the connections yields in.
Definition: NBEdge.h:215
NBEdge * toEdge
The edge the connections yields in.
Definition: NBEdge.h:212
data structure for caching needsCont information