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