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