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