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