Eclipse SUMO - Simulation of Urban MObility
MSTrafficLightLogic.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-2023 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// ===========================================================================
47// member method definitions
48// ===========================================================================
49/* -------------------------------------------------------------------------
50 * member method definitions
51 * ----------------------------------------------------------------------- */
53 MSTrafficLightLogic* tlLogic, SUMOTime nextSwitch) :
54 myTLControl(tlcontrol), myTLLogic(tlLogic),
55 myAssumedNextSwitch(nextSwitch), myAmValid(true) {
56 // higher than default command priority of 0
57 priority = 1;
58}
59
60
62
63
64
67 // check whether this command has been descheduled
68 if (!myAmValid) {
69 return 0;
70 }
71 int step1 = myTLLogic->getCurrentPhaseIndex();
72 SUMOTime next = myTLLogic->trySwitch();
73 while (next == 0) {
74 // skip phase and switch again
75 next = myTLLogic->trySwitch();
76 }
77 int step2 = myTLLogic->getCurrentPhaseIndex();
78 if (step1 != step2) {
79 if (myTLLogic->isActive()) {
80 // execute any action connected to this tls
81 const MSTLLogicControl::TLSLogicVariants& vars = myTLControl.get(myTLLogic->getID());
82 // set link priorities
83 myTLLogic->setTrafficLightSignals(t);
84 // execute switch actions
86 }
87 }
88 myAssumedNextSwitch += next;
89 return next;
90}
91
92
93void
95 if (tlLogic == myTLLogic) {
96 myAmValid = false;
97 myAssumedNextSwitch = -1;
98 }
99}
100
103 if (myTLLogic->getDefaultCycleTime() == DELTA_T) {
104 // MSRailSignal
105 return newTime;
106 } else {
107 UNUSED_PARAMETER(currentTime);
108 UNUSED_PARAMETER(execTime);
109 // XXX changeStepAndDuration (computed as in NLJunctionControlBuilder::closeTrafficLightLogic
110 return newTime;
111 }
112}
113
114/* -------------------------------------------------------------------------
115 * member method definitions
116 * ----------------------------------------------------------------------- */
118 const std::string& programID, const SUMOTime offset, const TrafficLightType logicType, const SUMOTime delay,
119 const Parameterised::Map& parameters) :
120 Named(id), Parameterised(parameters),
121 myProgramID(programID),
122 myOffset(offset),
123 myLogicType(logicType),
126 myAmActive(true) {
127 mySwitchCommand = new SwitchCommand(tlcontrol, this, delay);
129}
130
131
132void
134 const Phases& phases = getPhases();
135 if (phases.size() > 0 && (MSGlobals::gUseMesoSim || MSGlobals::gTLSPenalty > 0)) {
137 }
138 if (phases.size() > 1) {
139 bool haveWarnedAboutUnusedStates = false;
140 std::vector<bool> foundGreen(phases.front()->getState().size(), false);
141 for (int i = 0; i < (int)phases.size(); ++i) {
142 // warn about unused states
143 std::vector<int> nextPhases;
144 nextPhases.push_back((i + 1) % phases.size());
145 bool iNextDefault = true;
146 if (phases[i]->nextPhases.size() > 0) {
147 nextPhases = phases[i]->nextPhases;
148 iNextDefault = false;
149 }
150 for (int iNext : nextPhases) {
151 if (iNext < 0 || iNext >= (int)phases.size()) {
152 throw ProcessError("Invalid nextPhase " + toString(iNext) + " in tlLogic '" + getID()
153 + "', program '" + getProgramID() + "' with " + toString(phases.size()) + " phases");
154 }
155 const std::string optionalFrom = iNextDefault ? "" : " from phase " + toString(i);
156 const std::string& state1 = phases[i]->getState();
157 const std::string& state2 = phases[iNext]->getState();
158 if (state1.size() != state2.size()) {
159 throw ProcessError("Mismatching phase state length in tlLogic '" + getID()
160 + "', program '" + getProgramID() + "' in phases " + toString(i) + " and " + toString(iNext));
161 }
162 if (!haveWarnedAboutUnusedStates && state1.size() > myLanes.size() + myIgnoredIndices.size()) {
163 WRITE_WARNINGF(TL("Unused states in tlLogic '%', program '%' in phase % after tl-index %"),
164 getID(), getProgramID(), i, (int)myLanes.size() - 1);
165 haveWarnedAboutUnusedStates = true;
166 }
167 // detect illegal states
168 const std::string::size_type illegal = state1.find_first_not_of(SUMOXMLDefinitions::ALLOWED_TLS_LINKSTATES);
169 if (std::string::npos != illegal) {
170 throw ProcessError("Illegal character '" + toString(state1[illegal]) + "' in tlLogic '" + getID()
171 + "', program '" + getProgramID() + "' in phase " + toString(i));
172 }
173 // warn about transitions from green to red without intermediate yellow
174 bool haveWarned = false;
175 for (int j = 0; j < (int)MIN3(state1.size(), state2.size(), myLanes.size()) && !haveWarned; ++j) {
176 if ((LinkState)state2[j] == LINKSTATE_TL_RED
177 && ((LinkState)state1[j] == LINKSTATE_TL_GREEN_MAJOR
178 || (LinkState)state1[j] == LINKSTATE_TL_GREEN_MINOR)) {
179 for (LaneVector::const_iterator it = myLanes[j].begin(); it != myLanes[j].end(); ++it) {
180 if ((*it)->getPermissions() != SVC_PEDESTRIAN) {
182 WRITE_WARNINGF(TL("Missing yellow phase in tlLogic '%', program '%' for tl-index % when switching% to phase %."),
183 getID(), getProgramID(), j, optionalFrom, iNext);
184 // one warning per program is enough
185 haveWarned = true;
186 }
187 break;
188 }
189 }
190 }
191 }
192 // warn about links that never get the green light
193 for (int j = 0; j < (int)state1.size(); ++j) {
194 LinkState ls = (LinkState)state1[j];
196 foundGreen[j] = true;
197 }
198 }
199 }
200 }
201 for (int j = 0; j < (int)foundGreen.size(); ++j) {
202 if (!foundGreen[j]) {
204 WRITE_WARNINGF(TL("Missing green phase in tlLogic '%', program '%' for tl-index %."), getID(), getProgramID(), j);
205 }
206 break;
207 }
208 }
209 }
210 // check incompatible junction logic
211 // this can happen if the network was built with a very different signal
212 // plan from the one currently being used.
213 // Connections that never had a common green phase during network building may
214 // have a symmetric response relation to avoid certain kinds of jam but this
215 // can lead to deadlock if a different program gives minor green to both
216 // connections at the same time
217 // Note: mutual conflict between 'g' and 'G' is expected for traffic_light_right_on_red
218
219 const bool mustCheck = MSNet::getInstance()->hasInternalLinks();
220 // The checks only runs for definitions from additional file and this is sufficient.
221 // The distinction is implicit because original logics are loaded earlier and at that time hasInternalLinks is always false
222 // Also, when the network has no internal links, mutual conflicts are not built by netconvert
223 //std::cout << "init tlLogic=" << getID() << " prog=" << getProgramID() << " links=" << myLinks.size() << " internal=" << MSNet::getInstance()->hasInternalLinks() << "\n";
224 if (mustCheck && phases.size() > 0) {
225 // see NBNode::tlsConflict
226 std::set<const MSJunction*> controlledJunctions;
227 const int numLinks = (int)myLinks.size();
228 for (int j = 0; j < numLinks; ++j) {
229 for (int k = 0; k < (int)myLinks[j].size(); ++k) {
230 MSLink* link = myLinks[j][k];
231 assert(link->getJunction() != nullptr);
232 controlledJunctions.insert(link->getJunction());
233 }
234 }
235 const std::string minor = "gos";
236 for (const MSJunction* junction : controlledJunctions) {
237 const MSJunctionLogic* logic = junction->getLogic();
238 if (logic != nullptr) {
239 // find symmetrical response
240 const int logicSize = logic->getLogicSize();
241 std::vector<int> tlIndex;
242 for (int u = 0; u < logicSize; u++) {
243 const MSLogicJunction::LinkBits& response = logic->getResponseFor(u);
244 for (int v = 0; v < logicSize; v++) {
245 if (response.test(v)) {
246 if (logic->getResponseFor(v).test(u)) {
247 // get tls link index for links u and v
248 if (tlIndex.size() == 0) {
249 // init tlindex for all links once
250 tlIndex.resize(logicSize, -1);
251 for (int j = 0; j < numLinks; ++j) {
252 for (int k = 0; k < (int)myLinks[j].size(); ++k) {
253 MSLink* link = myLinks[j][k];
254 if (link->getJunction() == junction) {
255 tlIndex[link->getIndex()] = link->getTLIndex();
256 }
257 }
258 }
259 }
260 const int tlu = tlIndex[u];
261 const int tlv = tlIndex[v];
262 if (tlu >= 0 && tlv >= 0) {
263 int phaseIndex = 0;
264 for (MSPhaseDefinition* p : phases) {
265 if (minor.find(p->getState()[tlu]) != std::string::npos
266 && minor.find(p->getState()[tlv]) != std::string::npos) {
267 WRITE_ERRORF(TL("Program '%' at tlLogic '%' is incompatible with logic at junction '%' (mutual conflict between link indices %,% tl indices %,% phase %).\n"
268 " Rebuild the network with option '--tls.ignore-internal-junction-jam' or include the program when building."),
269 getProgramID(), getID(), junction->getID(), u, v, tlu, tlv, phaseIndex);
270 return;
271 }
272 phaseIndex++;
273 }
274 }
275 }
276 }
277 }
278 }
279 }
280 }
281 }
282 myNumLinks = (int)myLinks.size();
283}
284
285
287 // no need to do something about mySwitchCommand here,
288 // it is handled by the event control
289}
290
291
292// ----------- Handling of controlled links
293void
295 // !!! should be done within the loader (checking necessary)
296 myLinks.reserve(pos + 1);
297 while ((int)myLinks.size() <= pos) {
298 myLinks.push_back(LinkVector());
299 }
300 myLinks[pos].push_back(link);
301 //
302 myLanes.reserve(pos + 1);
303 while ((int)myLanes.size() <= pos) {
304 myLanes.push_back(LaneVector());
305 }
306 myLanes[pos].push_back(lane);
307 link->setTLState((LinkState) getCurrentPhaseDef().getState()[pos], MSNet::getInstance()->getCurrentTimeStep());
308}
309
310
311void
313 myLinks = logic.myLinks;
314 myLanes = logic.myLanes;
316}
317
318
319std::map<MSLink*, LinkState>
321 std::map<MSLink*, LinkState> ret;
322 for (LinkVectorVector::const_iterator i1 = myLinks.begin(); i1 != myLinks.end(); ++i1) {
323 const LinkVector& l = (*i1);
324 for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
325 ret[*i2] = (*i2)->getState();
326 }
327 }
328 return ret;
329}
330
331
332bool
334 // get the current traffic light signal combination
335 const std::string& state = getCurrentPhaseDef().getState();
336 // go through the links
337 for (int i = 0; i < (int)myLinks.size(); i++) {
338 const LinkVector& currGroup = myLinks[i];
339 LinkState ls = (LinkState) state[i];
340 for (LinkVector::const_iterator j = currGroup.begin(); j != currGroup.end(); j++) {
341 (*j)->setTLState(ls, t);
342 }
343 }
344 return true;
345}
346
347
348void
349MSTrafficLightLogic::resetLinkStates(const std::map<MSLink*, LinkState>& vals) const {
350 for (LinkVectorVector::const_iterator i1 = myLinks.begin(); i1 != myLinks.end(); ++i1) {
351 const LinkVector& l = (*i1);
352 for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
353 assert(vals.find(*i2) != vals.end());
354 (*i2)->setTLState(vals.find(*i2)->second, MSNet::getInstance()->getCurrentTimeStep());
355 }
356 }
357}
358
359
360// ----------- Static Information Retrieval
361int
363 int index = 0;
364 for (LinkVectorVector::const_iterator i1 = myLinks.begin(); i1 != myLinks.end(); ++i1, ++index) {
365 const LinkVector& l = (*i1);
366 for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
367 if ((*i2) == link) {
368 return index;
369 }
370 }
371 }
372 return -1;
373}
374
375
376
377// ----------- Dynamic Information Retrieval
380 return mySwitchCommand != nullptr ? mySwitchCommand->getNextSwitchTime() : -1;
381}
382
383
386 if (simStep == -1) {
387 simStep = SIMSTEP;
388 }
389 return simStep - getCurrentPhaseDef().myLastSwitch;
390}
391
392
393// ----------- Changing phases and phase durations
394void
396 myOverridingTimes.push_back(duration);
397}
398
399
400void
403}
404
405
407 // set mesoscopic time penalties
408 const Phases& phases = getPhases();
409 const int numLinks = (int)myLinks.size();
410 // warning already given if not all states are used
411 assert(numLinks <= (int)phases.front()->getState().size());
412 SUMOTime duration = 0;
413 std::vector<double> firstRedDuration(numLinks, 0);
414 std::vector<double> redDuration(numLinks, 0);
415 std::vector<double> totalRedDuration(numLinks, 0);
416 std::vector<double> penalty(numLinks, 0);
417 for (int i = 0; i < (int)phases.size(); ++i) {
418 const std::string& state = phases[i]->getState();
419 duration += phases[i]->duration;
420 // warn about transitions from green to red without intermediate yellow
421 for (int j = 0; j < numLinks; ++j) {
422 double& red = redDuration[j];
423 if ((LinkState)state[j] == LINKSTATE_TL_RED
424 || (LinkState)state[j] == LINKSTATE_TL_REDYELLOW) {
425 red += STEPS2TIME(phases[i]->duration);
426 totalRedDuration[j] += STEPS2TIME(phases[i]->duration);
427 } else if (red > 0) {
428 if (firstRedDuration[j] == 0) {
429 // store for handling wrap-around
430 firstRedDuration[j] = red;
431 } else {
432 // vehicle may arive in any second or the red duration
433 // compute the sum over [0,red]
434 penalty[j] += 0.5 * (red * red + red);
435 }
436 red = 0;
437 }
438 }
439 }
440 // final phase and wrap-around to first phase
441 for (int j = 0; j < numLinks; ++j) {
442 double red = redDuration[j] + firstRedDuration[j];
443 if (red) {
444 penalty[j] += 0.5 * (red * red + red);
445 }
446 }
447 double tlsPenalty = MSGlobals::gTLSPenalty;
448 const double durationSeconds = STEPS2TIME(duration);
449 std::set<const MSJunction*> controlledJunctions;
450 for (int j = 0; j < numLinks; ++j) {
451 for (int k = 0; k < (int)myLinks[j].size(); ++k) {
452 MSLink* link = myLinks[j][k];
453 MSEdge& edge = link->getLaneBefore()->getEdge();
456 tlsPenalty = edgeType.tlsPenalty;
457 double greenFraction = (durationSeconds - totalRedDuration[j]) / durationSeconds;
458 if (edgeType.tlsFlowPenalty == 0) {
459 greenFraction = 1;
460 } else {
461 greenFraction = MAX2(MIN2(greenFraction / edgeType.tlsFlowPenalty, 1.0), 0.01);
462 }
463 if (greenFraction == 0.01) {
464 WRITE_WARNINGF(TL("Green fraction is only 1% for link % in tlLogic '%', program '%'."), "%", j, getID(), getProgramID());
465 }
466 link->setGreenFraction(greenFraction);
467 }
468 link->setMesoTLSPenalty(TIME2STEPS(tlsPenalty * penalty[j] / durationSeconds));
469 controlledJunctions.insert(link->getLane()->getEdge().getFromJunction()); // MSLink::myJunction is not yet initialized
470 //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";
471 }
472 }
473 // initialize empty-net travel times
474 // XXX refactor after merging sharps (links know their incoming edge)
475 for (std::set<const MSJunction*>::iterator it = controlledJunctions.begin(); it != controlledJunctions.end(); ++it) {
476 const ConstMSEdgeVector incoming = (*it)->getIncoming();
477 for (ConstMSEdgeVector::const_iterator it_e = incoming.begin(); it_e != incoming.end(); ++it_e) {
478 const_cast<MSEdge*>(*it_e)->recalcCache();
479 }
480 }
481
482}
483
484
485void
487 myIgnoredIndices.insert(pos);
488}
489
492 return mapTimeInCycle(SIMSTEP);
493}
494
495
498 return (t - myOffset) % myDefaultCycleTime;
499}
500
501
502bool
504 return MSNet::getInstance()->isSelected(this);
505}
506
507
508void
510 myAmActive = true;
511}
512
513
514void
516 myAmActive = false;
517}
518
519bool
521 if (linkIndex >= 0 && linkIndex < getNumLinks()) {
522 for (const MSPhaseDefinition* p : getPhases()) {
523 const std::string& s = p->getState();
524 assert(linkIndex < (int)s.size());
525 if (s[linkIndex] == LINKSTATE_TL_GREEN_MAJOR) {
526 return true;
527 }
528 }
529 }
530 return false;
531
532}
533
534
537 const MSPhaseDefinition& p = step < 0 ? getCurrentPhaseDef() : getPhase(step);
538 return p.minDuration;
539}
540
543 const MSPhaseDefinition& p = step < 0 ? getCurrentPhaseDef() : getPhase(step);
544 return p.maxDuration;
545}
546
549 const MSPhaseDefinition& p = step < 0 ? getCurrentPhaseDef() : getPhase(step);
550 return p.earliestEnd;
551}
552
555 const MSPhaseDefinition& p = step < 0 ? getCurrentPhaseDef() : getPhase(step);
556 return p.latestEnd;
557}
558
559
560void
561MSTrafficLightLogic::loadState(MSTLLogicControl& tlcontrol, SUMOTime t, int step, SUMOTime spentDuration) {
562 const SUMOTime remaining = getPhase(step).duration - spentDuration;
563 changeStepAndDuration(tlcontrol, t, step, remaining);
564 setTrafficLightSignals(t - spentDuration);
565}
566
567
570 SUMOTime result = 0;
571 for (const MSPhaseDefinition* p : phases) {
572 result += p->duration;
573 }
574 return result;
575}
576
577
578
579/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:268
#define WRITE_ERRORF(...)
Definition: MsgHandler.h:277
#define TL(string)
Definition: MsgHandler.h:284
SUMOTime DELTA_T
Definition: SUMOTime.cpp:37
#define STEPS2TIME(x)
Definition: SUMOTime.h:54
#define SIMSTEP
Definition: SUMOTime.h:60
#define TIME2STEPS(x)
Definition: SUMOTime.h:56
@ SVC_PEDESTRIAN
pedestrian
TrafficLightType
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.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
T MIN3(T a, T b, T c)
Definition: StdDefs.h:89
T MIN2(T a, T b)
Definition: StdDefs.h:76
T MAX2(T a, T b)
Definition: StdDefs.h:82
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:118
const MSJunction * getFromJunction() const
Definition: MSEdge.h:411
const std::string & getEdgeType() const
Returns the type of the edge.
Definition: MSEdge.h:316
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static bool gUseMesoSim
Definition: MSGlobals.h:103
static double gTLSPenalty
scaled (minimum) time penalty for passing a tls link when routing
Definition: MSGlobals.h:154
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:745
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:183
virtual bool isSelected(const MSTrafficLightLogic *) const
return wheter the given logic (or rather it's wrapper) is selected in the GUI
Definition: MSNet.h:586
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:471
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:320
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:365
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:776
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
virtual void deactivateProgram()
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.
Definition: Parameterised.h:41
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
static const std::string ALLOWED_TLS_LINKSTATES
all allowed characters for phase state
edge type specific meso parameters
Definition: MESegment.h:55