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