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  myControlledNodes.clear();
484  SignalGroupCont::const_iterator m;
485  for (m = mySignalGroups.begin(); m != mySignalGroups.end(); m++) {
486  SignalGroup* group = (*m).second;
487  int linkNo = group->getLinkNo();
488  for (int j = 0; j < linkNo; j++) {
489  const NBConnection& conn = group->getConnection(j);
490  NBEdge* edge = conn.getFrom();
491  NBNode* node = edge->getToNode();
492  myControlledNodes.push_back(node);
493  }
494  }
496 }
497 
498 
499 void
501  myControlledLinks.clear();
502  // build the list of links which are controled by the traffic light
503  for (EdgeVector::iterator i = myIncomingEdges.begin(); i != myIncomingEdges.end(); i++) {
504  NBEdge* incoming = *i;
505  int noLanes = incoming->getNumLanes();
506  for (int j = 0; j < noLanes; j++) {
507  std::vector<NBEdge::Connection> elv = incoming->getConnectionsFromLane(j);
508  for (std::vector<NBEdge::Connection>::iterator k = elv.begin(); k != elv.end(); k++) {
509  NBEdge::Connection el = *k;
510  if (el.toEdge != 0) {
511  myControlledLinks.push_back(NBConnection(incoming, j, el.toEdge, el.toLane));
512  }
513  }
514  }
515  }
516 
517  // assign tl-indices to myControlledLinks
518  int pos = 0;
519  for (SignalGroupCont::const_iterator m = mySignalGroups.begin(); m != mySignalGroups.end(); m++) {
520  SignalGroup* group = (*m).second;
521  int linkNo = group->getLinkNo();
522  for (int j = 0; j < linkNo; j++) {
523  const NBConnection& conn = group->getConnection(j);
524  assert(conn.getFromLane() < 0 || (int) conn.getFrom()->getNumLanes() > conn.getFromLane());
525  NBConnection tst(conn);
526  tst.setTLIndex(pos);
527  if (tst.check(*myEdgeCont)) {
528  if (tst.getFrom()->mayBeTLSControlled(tst.getFromLane(), tst.getTo(), tst.getToLane())) {
529  for (NBConnectionVector::iterator it = myControlledLinks.begin(); it != myControlledLinks.end(); it++) {
530  NBConnection& c = *it;
532  && tst.getFrom() == c.getFrom() && tst.getTo() == c.getTo()
533  && (tst.getFromLane() < 0 || tst.getFromLane() == c.getFromLane())
534  && (tst.getToLane() < 0 || tst.getToLane() == c.getToLane())) {
535  c.setTLIndex(pos);
536  }
537  }
538  //std::cout << getID() << " group=" << (*m).first << " tst=" << tst << "\n";
539  pos++;
540  }
541  } else {
542  WRITE_WARNING("Could not set signal on connection (signal: " + getID() + ", group: " + group->getID() + ")");
543  }
544  }
545  }
546 }
547 
548 
551  for (SignalGroupCont::const_iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); i++) {
552  if ((*i).second->containsConnection(from, to)) {
553  return (*i).second;
554  }
555  }
556  return 0;
557 }
558 
559 
560 bool
561 NBLoadedTLDef::addToSignalGroup(const std::string& groupid,
562  const NBConnection& connection) {
563  if (mySignalGroups.find(groupid) == mySignalGroups.end()) {
564  return false;
565  }
566  mySignalGroups[groupid]->addConnection(connection);
567  NBNode* n1 = connection.getFrom()->getToNode();
568  if (n1 != 0) {
569  addNode(n1);
570  n1->addTrafficLight(this);
571  }
572  NBNode* n2 = connection.getTo()->getFromNode();
573  if (n2 != 0) {
574  addNode(n2);
575  n2->addTrafficLight(this);
576  }
577  return true;
578 }
579 
580 
581 bool
582 NBLoadedTLDef::addToSignalGroup(const std::string& groupid,
583  const NBConnectionVector& connections) {
584  bool ok = true;
585  for (NBConnectionVector::const_iterator i = connections.begin(); i != connections.end(); i++) {
586  ok &= addToSignalGroup(groupid, *i);
587  }
588  return ok;
589 }
590 
591 
592 void
593 NBLoadedTLDef::addSignalGroup(const std::string& id) {
594  assert(mySignalGroups.find(id) == mySignalGroups.end());
595  mySignalGroups[id] = new SignalGroup(id);
596 }
597 
598 
599 void
600 NBLoadedTLDef::addSignalGroupPhaseBegin(const std::string& groupid, SUMOTime time,
601  TLColor color) {
602  assert(mySignalGroups.find(groupid) != mySignalGroups.end());
603  mySignalGroups[groupid]->addPhaseBegin(time, color);
604 }
605 
606 void
607 NBLoadedTLDef::setSignalYellowTimes(const std::string& groupid,
608  SUMOTime myTRedYellow, SUMOTime myTYellow) {
609  assert(mySignalGroups.find(groupid) != mySignalGroups.end());
610  mySignalGroups[groupid]->setYellowTimes(myTRedYellow, myTYellow);
611 }
612 
613 
614 void
616  myCycleDuration = cycleDur;
617 }
618 
619 
620 void
622  const EdgeVector& incoming,
623  const EdgeVector& outgoing) {
624  for (SignalGroupCont::const_iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); i++) {
625  SignalGroup* group = (*i).second;
626  if (group->containsIncoming(removed)) {
627  group->remapIncoming(removed, incoming);
628  }
629  if (group->containsOutgoing(removed)) {
630  group->remapOutgoing(removed, outgoing);
631  }
632  }
633 }
634 
635 
636 void
637 NBLoadedTLDef::replaceRemoved(NBEdge* removed, int removedLane,
638  NBEdge* by, int byLane) {
639  for (SignalGroupCont::const_iterator i = mySignalGroups.begin(); i != mySignalGroups.end(); i++) {
640  SignalGroup* group = (*i).second;
641  if (group->containsIncoming(removed) || group->containsOutgoing(removed)) {
642  group->remap(removed, removedLane, by, byLane);
643  }
644  }
645 }
646 
647 
648 void
651  throw ProcessError("myNeedsContRelation was not propperly initialized\n");
652  }
653 }
654 
655 
656 /****************************************************************************/
657 
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
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:2431
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:164
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:190
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:187
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.
The representation of a single edge during network building.
Definition: NBEdge.h:71
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:657
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:66
#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: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:1385
void setTLIndex(int tlIndex)
Definition: NBConnection.h:105
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:1010
static const int InvalidTlIndex
Definition: NBConnection.h:126
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:56
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:413
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.
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:46
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 addTrafficLight(NBTrafficLightDefinition *tlDef)
Adds a traffic light to the list of traffic lights that control this node.
Definition: NBNode.cpp:310
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:41
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:75
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:52
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:100
std::vector< NBNode * > myControlledNodes
The container with participating nodes.
NBNode * getFromNode() const
Returns the origin node of the edge.
Definition: NBEdge.h:427
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 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:434
TrafficLightType
bool hasYellow(SUMOTime time) const
Returns whether controlled links have yellow at the given time.