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