Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSTrafficLightLogic.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-2025 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/****************************************************************************/
20// The parent class for traffic light logics
21/****************************************************************************/
22#include <config.h>
23
24#include <cassert>
25#include <string>
26#include <iostream>
27#include <map>
28#include <microsim/MSLink.h>
29#include <microsim/MSLane.h>
32#include <microsim/MSNet.h>
33#include <microsim/MSEdge.h>
34#include <microsim/MSGlobals.h>
35#include <mesosim/MESegment.h>
36#include "MSTLLogicControl.h"
37#include "MSTrafficLightLogic.h"
38
39
40// ===========================================================================
41// static value definitions
42// ===========================================================================
44
45
46#define SHORT_EDGE ((SUMOVTypeParameter::getDefault().length + SUMOVTypeParameter::getDefault().minGap) * 2)
47
48// ===========================================================================
49// member method definitions
50// ===========================================================================
51/* -------------------------------------------------------------------------
52 * member method definitions
53 * ----------------------------------------------------------------------- */
55 MSTrafficLightLogic* tlLogic, SUMOTime nextSwitch) :
56 myTLControl(tlcontrol), myTLLogic(tlLogic),
57 myAssumedNextSwitch(nextSwitch), myAmValid(true) {
58 // higher than default command priority of 0
59 priority = std::numeric_limits<int>::max();
60}
61
62
64
65
66
69 // check whether this command has been descheduled
70 if (!myAmValid) {
71 return 0;
72 }
73 int step1 = myTLLogic->getCurrentPhaseIndex();
74 SUMOTime next = myTLLogic->trySwitch();
75 while (next == 0) {
76 // skip phase and switch again
77 next = myTLLogic->trySwitch();
78 }
79 int step2 = myTLLogic->getCurrentPhaseIndex();
80 if (step1 != step2) {
81 if (myTLLogic->isActive()) {
82 // execute any action connected to this tls
83 const MSTLLogicControl::TLSLogicVariants& vars = myTLControl.get(myTLLogic->getID());
84 // set link priorities
85 myTLLogic->setTrafficLightSignals(t);
86 // execute switch actions
88 }
89 }
90 myAssumedNextSwitch += next;
91 return next;
92}
93
94
95void
97 if (tlLogic == myTLLogic) {
98 myAmValid = false;
99 myAssumedNextSwitch = -1;
100 }
101}
102
103
106 if (myTLLogic->getDefaultCycleTime() == DELTA_T) {
107 // MSRailSignal
108 return newTime;
109 } else {
110 UNUSED_PARAMETER(currentTime);
111 UNUSED_PARAMETER(execTime);
112 // XXX changeStepAndDuration (computed as in NLJunctionControlBuilder::closeTrafficLightLogic
113 return newTime;
114 }
115}
116
117/* -------------------------------------------------------------------------
118 * member method definitions
119 * ----------------------------------------------------------------------- */
121 const std::string& programID, const SUMOTime offset, const TrafficLightType logicType, const SUMOTime delay,
122 const Parameterised::Map& parameters) :
123 Named(id), Parameterised(parameters),
124 myProgramID(programID),
125 myOffset(offset),
126 myLogicType(logicType),
129 myAmActive(true) {
130 mySwitchCommand = new SwitchCommand(tlcontrol, this, delay);
132}
133
134
135void
137 const Phases& phases = getPhases();
138 if (phases.size() > 0 && (MSGlobals::gUseMesoSim || MSGlobals::gTLSPenalty > 0)) {
140 }
141 if (phases.size() > 1) {
142 bool haveWarnedAboutUnusedStates = false;
143 for (int i = 0; i < (int)phases.size(); ++i) {
144 // warn about unused states
145 std::vector<int> nextPhases;
146 nextPhases.push_back((i + 1) % phases.size());
147 bool iNextDefault = true;
148 if (phases[i]->nextPhases.size() > 0) {
149 nextPhases = phases[i]->nextPhases;
150 iNextDefault = false;
151 }
152 for (int iNext : nextPhases) {
153 if (iNext < 0 || iNext >= (int)phases.size()) {
154 throw ProcessError("Invalid nextPhase " + toString(iNext) + " in tlLogic '" + getID()
155 + "', program '" + getProgramID() + "' with " + toString(phases.size()) + " phases");
156 }
157 if (iNext == i && (int)nextPhases.size() == 1 && (int)phases.size() > 1) {
158 WRITE_WARNINGF("Phase % only loops backs to itself in tlLogic '%', program '%'.", i, getID(), getProgramID());
159 }
160 const std::string optionalFrom = iNextDefault ? "" : " from phase " + toString(i);
161 const std::string& state1 = phases[i]->getState();
162 const std::string& state2 = phases[iNext]->getState();
163 if (state1.size() != state2.size()) {
164 throw ProcessError("Mismatching phase state length in tlLogic '" + getID()
165 + "', program '" + getProgramID() + "' in phases " + toString(i) + " and " + toString(iNext));
166 }
167 if (!haveWarnedAboutUnusedStates && state1.size() > myLanes.size() + myIgnoredIndices.size()) {
168 WRITE_WARNINGF(TL("Unused states in tlLogic '%', program '%' in phase % after tl-index %"),
169 getID(), getProgramID(), i, (int)myLanes.size() - 1);
170 haveWarnedAboutUnusedStates = true;
171 }
172 // detect illegal states
173 const std::string::size_type illegal = state1.find_first_not_of(SUMOXMLDefinitions::ALLOWED_TLS_LINKSTATES);
174 if (std::string::npos != illegal) {
175 throw ProcessError("Illegal character '" + toString(state1[illegal]) + "' in tlLogic '" + getID()
176 + "', program '" + getProgramID() + "' in phase " + toString(i));
177 }
178 // warn about transitions from green to red without intermediate yellow
179 bool haveWarned = false;
180 for (int j = 0; j < (int)MIN3(state1.size(), state2.size(), myLanes.size()) && !haveWarned; ++j) {
181 if ((LinkState)state2[j] == LINKSTATE_TL_RED
182 && ((LinkState)state1[j] == LINKSTATE_TL_GREEN_MAJOR
183 || (LinkState)state1[j] == LINKSTATE_TL_GREEN_MINOR)) {
184 for (LaneVector::const_iterator it = myLanes[j].begin(); it != myLanes[j].end(); ++it) {
185 if ((*it)->getPermissions() != SVC_PEDESTRIAN) {
187 WRITE_WARNINGF(TL("Missing yellow phase in tlLogic '%', program '%' for tl-index % when switching% to phase %."),
188 getID(), getProgramID(), j, optionalFrom, iNext);
189 // one warning per program is enough
190 haveWarned = true;
191 }
192 break;
193 }
194 }
195 }
196 }
197 }
198 }
199 }
200 // warn about links that never get the green light
201 std::vector<bool> foundGreen(phases.front()->getState().size(), false);
202 for (int i = 0; i < (int)phases.size(); ++i) {
203 const std::string& state = phases[i]->getState();
204 for (int j = 0; j < (int)state.size(); ++j) {
205 LinkState ls = (LinkState)state[j];
207 foundGreen[j] = true;
208 }
209 }
210 }
211 std::vector<bool> usedIndices(phases.front()->getState().size(), false);
212 for (auto lv : myLinks) {
213 for (const MSLink* link : lv) {
214 if (link->getTLIndex() >= 0) {
215 usedIndices[link->getTLIndex()] = true;
216 }
217 }
218 }
219 for (int j = 0; j < (int)foundGreen.size(); ++j) {
220 if (!foundGreen[j] && usedIndices[j]) {
221 WRITE_WARNINGF(TL("Missing green phase in tlLogic '%', program '%' for tl-index %."), getID(), getProgramID(), j);
222 break;
223 }
224 }
225 // check direct conflict (two green links targeting the same lane)
226 const int numLinks = (int)myLinks.size();
227 std::set<const MSLane*> unsafeGreen;
228 int firstUnsafePhase = -1;
229 const MSLane* firstUnsafeLane = nullptr;
230 int firstUnsafeOrigins = 0;
231 int unsafeGreenPhases = 0;
232 for (int i = 0; i < (int)phases.size(); ++i) {
233 std::map<const MSLane*, int, ComparatorNumericalIdLess> greenLanes;
234 const std::string& state = phases[i]->getState();
235 for (int j = 0; j < numLinks; ++j) {
236 if (state[j] == LINKSTATE_TL_GREEN_MAJOR) {
237 for (const MSLink* link : myLinks[j]) {
238 if (link->isInternalJunctionLink()) {
239 // links from an internal junction have implicit priority in case of conflict
240 continue;
241 }
242 greenLanes[link->getLane()] += 1;
243 }
244 }
245 }
246 bool unsafe = false;
247 for (auto item : greenLanes) {
248 if (item.second > 1) {
249 if (unsafeGreenPhases == 0 && !unsafe) {
250 firstUnsafePhase = i;
251 firstUnsafeLane = item.first;
252 firstUnsafeOrigins = item.second;
253 }
254 unsafe = true;
255 unsafeGreen.insert(item.first);
256 }
257 }
258 if (unsafe) {
259 unsafeGreenPhases++;
260 }
261 }
262 if (unsafeGreenPhases > 0) {
263 const std::string furtherAffected = unsafeGreen.size() > 1 || unsafeGreenPhases > 1 ? TLF(" Overall % lanes in % phases are unsafe.", unsafeGreen.size(), unsafeGreenPhases) : "";
264 WRITE_WARNINGF(TL("Unsafe green phase % in tlLogic '%', program '%'. Lane '%' is targeted by % 'G'-links. (use 'g' instead)%"),
265 firstUnsafePhase, getID(), getProgramID(), firstUnsafeLane->getID(), firstUnsafeOrigins, furtherAffected);
266 }
267
268 // check incompatible junction logic
269 // this can happen if the network was built with a very different signal
270 // plan from the one currently being used.
271 // Connections that never had a common green phase during network building may
272 // have a symmetric response relation to avoid certain kinds of jam but this
273 // can lead to deadlock if a different program gives minor green to both
274 // connections at the same time
275 // Note: mutual conflict between 'g' and 'G' is expected for traffic_light_right_on_red
276
277 const bool mustCheck = MSNet::getInstance()->hasInternalLinks();
278 // The checks only runs for definitions from additional file and this is sufficient.
279 // The distinction is implicit because original logics are loaded earlier and at that time hasInternalLinks is always false
280 // Also, when the network has no internal links, mutual conflicts are not built by netconvert
281 //std::cout << "init tlLogic=" << getID() << " prog=" << getProgramID() << " links=" << myLinks.size() << " internal=" << MSNet::getInstance()->hasInternalLinks() << "\n";
282 if (mustCheck && phases.size() > 0) {
283 // see NBNode::tlsConflict
284 std::set<const MSJunction*> controlledJunctions;
285 for (int j = 0; j < numLinks; ++j) {
286 for (int k = 0; k < (int)myLinks[j].size(); ++k) {
287 MSLink* link = myLinks[j][k];
288 assert(link->getJunction() != nullptr);
289 controlledJunctions.insert(link->getJunction());
290 }
291 }
292 const std::string minor = "gos";
293 for (const MSJunction* junction : controlledJunctions) {
294 const MSJunctionLogic* logic = junction->getLogic();
295 if (logic != nullptr) {
296 // find symmetrical response
297 const int logicSize = logic->getLogicSize();
298 bool foundProblem = false;
299 std::vector<int> tlIndex;
300 for (int u = 0; u < logicSize && !foundProblem; u++) {
301 const MSLogicJunction::LinkBits& response = logic->getResponseFor(u);
302 for (int v = 0; v < logicSize && !foundProblem; v++) {
303 if (response.test(v)) {
304 if (logic->getResponseFor(v).test(u)) {
305 // get tls link index for links u and v
306 if (tlIndex.size() == 0) {
307 // init tlindex for all links once
308 tlIndex.resize(logicSize, -1);
309 for (int j = 0; j < numLinks; ++j) {
310 for (int k = 0; k < (int)myLinks[j].size(); ++k) {
311 MSLink* link = myLinks[j][k];
312 if (link->getJunction() == junction) {
313 if (link->fromInternalLane()) {
314 // internal links may have their own control (i.e. for indirect left turn) but they also have their own conflict matrix
315 continue;
316 }
317 if (link->isCont() && link->getViaLane() != nullptr && link->getViaLane()->getLinkCont()[0]->getTLIndex() >= 0) {
318 // if the internal junction link is controlled, the first-part indices are not deadlock-relevant
319 continue;
320 }
321 tlIndex[link->getIndex()] = link->getTLIndex();
322 }
323 }
324 }
325 }
326 const int tlu = tlIndex[u];
327 const int tlv = tlIndex[v];
328 if (tlu >= 0 && tlv >= 0) {
329 int phaseIndex = 0;
330 for (MSPhaseDefinition* p : phases) {
331 if (minor.find(p->getState()[tlu]) != std::string::npos
332 && minor.find(p->getState()[tlv]) != std::string::npos) {
333 WRITE_WARNING(TLF("Program '%' at tlLogic '%' is incompatible with logic at junction '%' (mutual conflict between link indices %,% tl indices %,% phase %).\n"
334 " To avoid deadlock/collisions, either: rebuild the signal plan with a newer version of netconvert/netedit\n"
335 " or rebuild the network with option '--tls.ignore-internal-junction-jam' or include the program when building.",
336 getProgramID(), getID(), junction->getID(), u, v, tlu, tlv, phaseIndex));
337 // only one warning per program
338 foundProblem = true;
339 break;
340 }
341 phaseIndex++;
342 }
343 }
344 }
345 }
346 }
347 }
348 }
349 }
350 }
351 myNumLinks = (int)myLinks.size();
352}
353
354
356 // no need to do something about mySwitchCommand here,
357 // it is handled by the event control
358}
359
360
361// ----------- Handling of controlled links
362void
364 // !!! should be done within the loader (checking necessary)
365 myLinks.reserve(pos + 1);
366 while ((int)myLinks.size() <= pos) {
367 myLinks.push_back(LinkVector());
368 }
369 myLinks[pos].push_back(link);
370 //
371 myLanes.reserve(pos + 1);
372 while ((int)myLanes.size() <= pos) {
373 myLanes.push_back(LaneVector());
374 }
375 myLanes[pos].push_back(lane);
376 link->setTLState((LinkState) getCurrentPhaseDef().getState()[pos], MSNet::getInstance()->getCurrentTimeStep());
377}
378
379
380void
386
387
388std::map<MSLink*, LinkState>
390 std::map<MSLink*, LinkState> ret;
391 for (LinkVectorVector::const_iterator i1 = myLinks.begin(); i1 != myLinks.end(); ++i1) {
392 const LinkVector& l = (*i1);
393 for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
394 ret[*i2] = (*i2)->getState();
395 }
396 }
397 return ret;
398}
399
400
401bool
403 // get the current traffic light signal combination
404 const std::string& state = getCurrentPhaseDef().getState();
405 // go through the links
406 for (int i = 0; i < (int)myLinks.size(); i++) {
407 const LinkVector& currGroup = myLinks[i];
408 LinkState ls = (LinkState) state[i];
409 for (LinkVector::const_iterator j = currGroup.begin(); j != currGroup.end(); j++) {
410 (*j)->setTLState(ls, t);
411 }
412 }
413 return true;
414}
415
416
417void
418MSTrafficLightLogic::resetLinkStates(const std::map<MSLink*, LinkState>& vals) const {
419 for (LinkVectorVector::const_iterator i1 = myLinks.begin(); i1 != myLinks.end(); ++i1) {
420 const LinkVector& l = (*i1);
421 for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
422 assert(vals.find(*i2) != vals.end());
423 (*i2)->setTLState(vals.find(*i2)->second, MSNet::getInstance()->getCurrentTimeStep());
424 }
425 }
426}
427
428
429// ----------- Static Information Retrieval
430int
432 int index = 0;
433 for (LinkVectorVector::const_iterator i1 = myLinks.begin(); i1 != myLinks.end(); ++i1, ++index) {
434 const LinkVector& l = (*i1);
435 for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
436 if ((*i2) == link) {
437 return index;
438 }
439 }
440 }
441 return -1;
442}
443
444
445
446// ----------- Dynamic Information Retrieval
451
452
455 if (simStep == -1) {
456 simStep = SIMSTEP;
457 }
458 return simStep - getCurrentPhaseDef().myLastSwitch;
459}
460
461
462// ----------- Changing phases and phase durations
463void
467
468
469void
473
474
477 return;
478 }
479 // set mesoscopic time penalties
480 const Phases& phases = getPhases();
481 const int numLinks = (int)myLinks.size();
482 // warning already given if not all states are used
483 assert(numLinks <= (int)phases.front()->getState().size());
484 SUMOTime duration = 0;
485 std::vector<double> firstRedDuration(numLinks, 0);
486 std::vector<double> redDuration(numLinks, 0);
487 std::vector<double> totalRedDuration(numLinks, 0);
488 std::vector<double> penalty(numLinks, 0);
489 for (int i = 0; i < (int)phases.size(); ++i) {
490 const std::string& state = phases[i]->getState();
491 duration += phases[i]->duration;
492 // warn about transitions from green to red without intermediate yellow
493 for (int j = 0; j < numLinks; ++j) {
494 double& red = redDuration[j];
495 if ((LinkState)state[j] == LINKSTATE_TL_RED
496 || (LinkState)state[j] == LINKSTATE_TL_REDYELLOW) {
497 red += STEPS2TIME(phases[i]->duration);
498 totalRedDuration[j] += STEPS2TIME(phases[i]->duration);
499 } else if (red > 0) {
500 if (firstRedDuration[j] == 0) {
501 // store for handling wrap-around
502 firstRedDuration[j] = red;
503 } else {
504 // vehicle may arive in any second or the red duration
505 // compute the sum over [0,red]
506 penalty[j] += 0.5 * (red * red + red);
507 }
508 red = 0;
509 }
510 }
511 }
512 // final phase and wrap-around to first phase
513 for (int j = 0; j < numLinks; ++j) {
514 double red = redDuration[j] + firstRedDuration[j];
515 if (red) {
516 penalty[j] += 0.5 * (red * red + red);
517 }
518 }
519 double tlsPenalty = MSGlobals::gTLSPenalty;
520 const double durationSeconds = STEPS2TIME(duration);
521 std::set<const MSJunction*> controlledJunctions;
522 std::set<const MSEdge*> shortEdges;;
523 for (int j = 0; j < numLinks; ++j) {
524 for (int k = 0; k < (int)myLinks[j].size(); ++k) {
525 MSLink* link = myLinks[j][k];
526 MSEdge& edge = link->getLaneBefore()->getEdge();
529 tlsPenalty = edgeType.tlsPenalty;
530 double greenFraction = (durationSeconds - totalRedDuration[j]) / durationSeconds;
531 if (edgeType.tlsFlowPenalty == 0) {
532 greenFraction = 1;
533 } else {
534 greenFraction = MAX2(MIN2(greenFraction / edgeType.tlsFlowPenalty, 1.0), 0.01);
535 }
536 if (greenFraction == 0.01) {
537 WRITE_WARNINGF(TL("Green fraction is only 1% for link % in tlLogic '%', program '%'."), "%", j, getID(), getProgramID());
538 }
539 link->setGreenFraction(greenFraction);
540 if (tlsPenalty > 0 && edge.getLength() < SHORT_EDGE && shortEdges.count(&edge) == 0) {
541 shortEdges.insert(&edge);
542 WRITE_WARNINGF(TL("Edge '%' is shorter than %m (%m) and will cause incorrect flow reduction with option --meso-tls-penalty"), edge.getID(), SHORT_EDGE, edge.getLength());
543 }
544 }
545 link->setMesoTLSPenalty(TIME2STEPS(tlsPenalty * penalty[j] / durationSeconds));
546 controlledJunctions.insert(link->getLane()->getEdge().getFromJunction()); // MSLink::myJunction is not yet initialized
547 //std::cout << " tls=" << getID() << " i=" << j << " link=" << link->getDescription() << " p=" << penalty[j] << " fr=" << firstRedDuration[j] << " r=" << redDuration[j] << " tr=" << totalRedDuration[j] << " durSecs=" << durationSeconds << " tlsPen=" << STEPS2TIME(link->getMesoTLSPenalty()) << " gF=" << myLinks[j][k]->getGreenFraction() << "\n";
548 }
549 }
550 // initialize empty-net travel times
551 // XXX refactor after merging sharps (links know their incoming edge)
552 for (std::set<const MSJunction*>::iterator it = controlledJunctions.begin(); it != controlledJunctions.end(); ++it) {
553 const ConstMSEdgeVector incoming = (*it)->getIncoming();
554 for (ConstMSEdgeVector::const_iterator it_e = incoming.begin(); it_e != incoming.end(); ++it_e) {
555 const_cast<MSEdge*>(*it_e)->recalcCache();
556 }
557 }
558
559}
560
561
562void
566
571
572
577
578
579bool
583
584
585void
587 myAmActive = true;
588 // updated the traffic light logic stored in the link
589 for (const LinkVector& currGroup : myLinks) {
590 for (MSLink* link : currGroup) {
591 link->setTLLogic(this);
592 }
593 }
594}
595
596
597void
601
602bool
604 if (linkIndex >= 0 && linkIndex < getNumLinks()) {
605 for (const MSPhaseDefinition* p : getPhases()) {
606 const std::string& s = p->getState();
607 assert(linkIndex < (int)s.size());
608 if (s[linkIndex] == LINKSTATE_TL_GREEN_MAJOR) {
609 return true;
610 }
611 }
612 }
613 return false;
614
615}
616
617
620 const MSPhaseDefinition& p = step < 0 ? getCurrentPhaseDef() : getPhase(step);
621 return p.minDuration;
622}
623
626 const MSPhaseDefinition& p = step < 0 ? getCurrentPhaseDef() : getPhase(step);
627 return p.maxDuration;
628}
629
632 const MSPhaseDefinition& p = step < 0 ? getCurrentPhaseDef() : getPhase(step);
633 return p.earliestEnd;
634}
635
638 const MSPhaseDefinition& p = step < 0 ? getCurrentPhaseDef() : getPhase(step);
639 return p.latestEnd;
640}
641
642
643void
644MSTrafficLightLogic::loadState(MSTLLogicControl& tlcontrol, SUMOTime t, int step, SUMOTime spentDuration) {
645 const SUMOTime remaining = getPhase(step).duration - spentDuration;
646 changeStepAndDuration(tlcontrol, t, step, remaining);
647 setTrafficLightSignals(t - spentDuration);
648}
649
650
653 SUMOTime result = 0;
654 for (const MSPhaseDefinition* p : phases) {
655 result += p->duration;
656 }
657 return result;
658}
659
660
661
662/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
#define SHORT_EDGE
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:288
#define WRITE_WARNING(msg)
Definition MsgHandler.h:287
#define TL(string)
Definition MsgHandler.h:305
#define TLF(string,...)
Definition MsgHandler.h:307
SUMOTime DELTA_T
Definition SUMOTime.cpp:38
#define STEPS2TIME(x)
Definition SUMOTime.h:55
#define SIMSTEP
Definition SUMOTime.h:61
#define TIME2STEPS(x)
Definition SUMOTime.h:57
@ SVC_PEDESTRIAN
pedestrian
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
@ LINKSTATE_TL_REDYELLOW
The link has red light (must brake) but indicates upcoming green.
@ LINKSTATE_STOP
This is an uncontrolled, minor link, has to stop.
@ LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
@ LINKSTATE_TL_OFF_BLINKING
The link is controlled by a tls which is off and blinks, has to brake.
@ LINKSTATE_TL_RED
The link has red light (must brake)
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
@ LINKSTATE_TL_OFF_NOSIGNAL
The link is controlled by a tls which is off, not blinking, may pass.
T MIN3(T a, T b, T c)
Definition StdDefs.h:93
T MIN2(T a, T b)
Definition StdDefs.h:80
T MAX2(T a, T b)
Definition StdDefs.h:86
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
int priority
Definition Command.h:87
A road/street connecting two junctions.
Definition MSEdge.h:77
void recalcCache()
Recalculates the cached values.
Definition MSEdge.cpp:120
double getLength() const
return the length of the edge
Definition MSEdge.h:685
const MSJunction * getFromJunction() const
Definition MSEdge.h:414
const std::string & getEdgeType() const
Returns the type of the edge.
Definition MSEdge.h:319
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static bool gUseMesoSim
Definition MSGlobals.h:106
static double gTLSPenalty
scaled (minimum) time penalty for passing a tls link when routing
Definition MSGlobals.h:157
The base class for an intersection.
Definition MSJunction.h:58
virtual const MSLogicJunction::LinkBits & getResponseFor(int linkIndex) const
Returns the response for the given link.
int getLogicSize() const
Representation of a lane in the micro simulation.
Definition MSLane.h:84
MSEdge & getEdge() const
Returns the lane's edge.
Definition MSLane.h:769
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
Definition MSLane.h:729
std::bitset< SUMO_MAX_CONNECTIONS > LinkBits
Container for link response and foes.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
virtual bool isSelected(const MSTrafficLightLogic *) const
return wheter the given logic (or rather its wrapper) is selected in the GUI
Definition MSNet.h:598
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition MSNet.h:477
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition MSNet.h:326
const MESegment::MesoEdgeType & getMesoType(const std::string &typeID)
Returns edge type specific meso parameters if no type specific parameters have been loaded,...
Definition MSNet.cpp:367
bool hasInternalLinks() const
return whether the network contains internal links
Definition MSNet.h:786
The definition of a single phase of a tls logic.
SUMOTime maxDuration
The maximum duration of the phase.
SUMOTime latestEnd
The maximum time within the cycle for switching (for coordinated actuation)
SUMOTime minDuration
The minimum duration of the phase.
SUMOTime myLastSwitch
Stores the timestep of the last on-switched of the phase.
const std::string & getState() const
Returns the state within this phase.
SUMOTime duration
The duration of the phase.
SUMOTime earliestEnd
The minimum time within the cycle for switching (for coordinated actuation)
Storage for all programs of a single tls.
A class that stores and controls tls and switching of their programs.
Class realising the switch between the traffic light phases.
void deschedule(MSTrafficLightLogic *tlLogic)
Marks this swicth as invalid (if the phase duration has changed, f.e.)
SUMOTime shiftTime(SUMOTime currentTime, SUMOTime execTime, SUMOTime newTime)
Reschedule or deschedule the command when quick-loading state.
SwitchCommand(MSTLLogicControl &tlcontrol, MSTrafficLightLogic *tlLogic, SUMOTime nextSwitch)
Constructor.
SUMOTime getNextSwitchTime() const
Returns the assumed next switch time.
SUMOTime execute(SUMOTime currentTime)
Executes the regarded junction's "trySwitch"- method.
The parent class for traffic light logics.
virtual void adaptLinkInformationFrom(const MSTrafficLightLogic &logic)
Applies information about controlled links and lanes from the given logic.
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.
SUMOTime myOffset
the offset parameter of the current program
int getLinkIndex(const MSLink *const link) const
Returns the index of the given link.
virtual SUMOTime mapTimeInCycle(SUMOTime t) const
map the given time into the current cycle
void setCurrentDurationIncrement(SUMOTime delay)
Delays current phase by the given delay.
SUMOTime computeCycleTime(const Phases &phases)
std::map< MSLink *, LinkState > collectLinkStates() const
Returns the (uncontrolled) states of the controlled links.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
virtual ~MSTrafficLightLogic()
Destructor.
virtual SUMOTime getLatestEnd(int step=-1) const
MSTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const SUMOTime offset, const TrafficLightType logicType, const SUMOTime delay, const Parameterised::Map &parameters)
Constructor.
std::vector< SUMOTime > myOverridingTimes
A list of duration overrides.
virtual SUMOTime getMinDur(int step=-1) const
void ignoreLinkIndex(int pos)
ignore pedestrian crossing index in mesosim
virtual void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration)=0
Changes the current phase and her duration.
static const LaneVector myEmptyLaneVector
An empty lane vector.
const TrafficLightType myLogicType
The type of the logic.
bool isSelected() const
whether this logic is selected in the GUI
virtual const MSPhaseDefinition & getPhase(int givenstep) const =0
Returns the definition of the phase from the given position within the plan.
SUMOTime myDefaultCycleTime
The cycle time (without changes)
SUMOTime getTimeInCycle() const
return time within the current cycle
const std::string & getProgramID() const
Returns this tl-logic's id.
const std::string myProgramID
The id of the logic.
TrafficLightType getLogicType() const
Returns the type of the logic.
virtual SUMOTime getEarliestEnd(int step=-1) const
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index.
SwitchCommand * mySwitchCommand
The current switch command.
int myNumLinks
number of controlled links
int getNumLinks() const
return the number of controlled link indices
virtual const Phases & getPhases() const =0
Returns the phases of this tls program.
SUMOTime myCurrentDurationIncrement
A value for enlarge the current duration.
virtual SUMOTime getMaxDur(int step=-1) const
virtual bool getsMajorGreen(int linkIndex) const
whether the given link index ever turns 'G'
void resetLinkStates(const std::map< MSLink *, LinkState > &vals) const
Resets the states of controlled links.
virtual void loadState(MSTLLogicControl &tlcontrol, SUMOTime t, int step, SUMOTime spentDuration)
restores the tls state
virtual void activateProgram()
called when switching programs
void addOverridingDuration(SUMOTime duration)
Changes the duration of the next phase.
bool myAmActive
whether the current program is active
SUMOTime getNextSwitchTime() const
Returns the assumed next switch time.
std::set< int > myIgnoredIndices
list of indices that are ignored in mesoscopic simulatino
SUMOTime getSpentDuration(SUMOTime simStep=-1) const
Returns the duration spent in the current phase.
bool setTrafficLightSignals(SUMOTime t) const
Applies the current signal states to controlled links.
virtual void addLink(MSLink *link, MSLane *lane, int pos)
Adds a link on building.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
std::vector< MSLink * > LinkVector
Definition of the list of links that are subjected to this tls.
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index.
void initMesoTLSPenalties()
initialize optional meso penalties
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
Builds detectors for microsim.
Base class for objects which have an id.
Definition Named.h:54
const std::string & getID() const
Returns the id.
Definition Named.h:74
An upper class for objects with additional parameters.
std::map< std::string, std::string > Map
parameters map
static const std::string ALLOWED_TLS_LINKSTATES
all allowed characters for phase state
#define UNUSED_PARAMETER(x)
edge type specific meso parameters
Definition MESegment.h:57