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-2022 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 
57 
59 
60 
61 
64  // check whether this command has been descheduled
65  if (!myAmValid) {
66  return 0;
67  }
68  int step1 = myTLLogic->getCurrentPhaseIndex();
69  SUMOTime next = myTLLogic->trySwitch();
70  int step2 = myTLLogic->getCurrentPhaseIndex();
71  if (step1 != step2) {
72  if (myTLLogic->isActive()) {
73  // execute any action connected to this tls
74  const MSTLLogicControl::TLSLogicVariants& vars = myTLControl.get(myTLLogic->getID());
75  // set link priorities
76  myTLLogic->setTrafficLightSignals(t);
77  // execute switch actions
79  }
80  }
81  myAssumedNextSwitch += next;
82  return next;
83 }
84 
85 
86 void
88  if (tlLogic == myTLLogic) {
89  myAmValid = false;
90  myAssumedNextSwitch = -1;
91  }
92 }
93 
96  if (myTLLogic->getDefaultCycleTime() == DELTA_T) {
97  // MSRailSignal
98  return newTime;
99  } else {
100  UNUSED_PARAMETER(currentTime);
101  UNUSED_PARAMETER(execTime);
102  // XXX changeStepAndDuration (computed as in NLJunctionControlBuilder::closeTrafficLightLogic
103  return newTime;
104  }
105 }
106 
107 /* -------------------------------------------------------------------------
108  * member method definitions
109  * ----------------------------------------------------------------------- */
111  const std::string& programID, const SUMOTime offset, const TrafficLightType logicType, const SUMOTime delay,
112  const std::map<std::string, std::string>& parameters) :
113  Named(id), Parameterised(parameters),
114  myProgramID(programID),
115  myOffset(offset),
116  myLogicType(logicType),
119  myAmActive(true) {
120  mySwitchCommand = new SwitchCommand(tlcontrol, this, delay);
122 }
123 
124 
125 void
127  const Phases& phases = getPhases();
128  if (phases.size() > 0 && MSGlobals::gUseMesoSim) {
130  }
131  if (phases.size() > 1) {
132  bool haveWarnedAboutUnusedStates = false;
133  std::vector<bool> foundGreen(phases.front()->getState().size(), false);
134  for (int i = 0; i < (int)phases.size(); ++i) {
135  // warn about unused states
136  std::vector<int> nextPhases;
137  nextPhases.push_back((i + 1) % phases.size());
138  bool iNextDefault = true;
139  if (phases[i]->nextPhases.size() > 0) {
140  nextPhases = phases[i]->nextPhases;
141  iNextDefault = false;
142  }
143  for (int iNext : nextPhases) {
144  if (iNext < 0 || iNext >= (int)phases.size()) {
145  throw ProcessError("Invalid nextPhase " + toString(iNext) + " in tlLogic '" + getID()
146  + "', program '" + getProgramID() + "' with " + toString(phases.size()) + " phases");
147  }
148  const std::string optionalFrom = iNextDefault ? "" : " from phase " + toString(i);
149  const std::string& state1 = phases[i]->getState();
150  const std::string& state2 = phases[iNext]->getState();
151  if (state1.size() != state2.size()) {
152  throw ProcessError("Mismatching phase state length in tlLogic '" + getID()
153  + "', program '" + getProgramID() + "' in phases " + toString(i) + " and " + toString(iNext));
154  }
155  if (!haveWarnedAboutUnusedStates && state1.size() > myLanes.size() + myIgnoredIndices.size()) {
156  WRITE_WARNING("Unused states in tlLogic '" + getID()
157  + "', program '" + getProgramID() + "' in phase " + toString(i)
158  + " after tl-index " + toString((int)myLanes.size() - 1));
159  haveWarnedAboutUnusedStates = true;
160  }
161  // detect illegal states
162  const std::string::size_type illegal = state1.find_first_not_of(SUMOXMLDefinitions::ALLOWED_TLS_LINKSTATES);
163  if (std::string::npos != illegal) {
164  throw ProcessError("Illegal character '" + toString(state1[illegal]) + "' in tlLogic '" + getID()
165  + "', program '" + getProgramID() + "' in phase " + toString(i));
166  }
167  // warn about transitions from green to red without intermediate yellow
168  bool haveWarned = false;
169  for (int j = 0; j < (int)MIN3(state1.size(), state2.size(), myLanes.size()) && !haveWarned; ++j) {
170  if ((LinkState)state2[j] == LINKSTATE_TL_RED
171  && ((LinkState)state1[j] == LINKSTATE_TL_GREEN_MAJOR
172  || (LinkState)state1[j] == LINKSTATE_TL_GREEN_MINOR)) {
173  for (LaneVector::const_iterator it = myLanes[j].begin(); it != myLanes[j].end(); ++it) {
174  if ((*it)->getPermissions() != SVC_PEDESTRIAN) {
176  WRITE_WARNING("Missing yellow phase in tlLogic '" + getID()
177  + "', program '" + getProgramID() + "' for tl-index " + toString(j)
178  + " when switching" + optionalFrom + " to phase " + toString(iNext));
179  // one warning per program is enough
180  haveWarned = true;
181  }
182  break;
183  }
184  }
185  }
186  }
187  // warn about links that never get the green light
188  for (int j = 0; j < (int)state1.size(); ++j) {
189  LinkState ls = (LinkState)state1[j];
191  foundGreen[j] = true;
192  }
193  }
194  }
195  }
196  for (int j = 0; j < (int)foundGreen.size(); ++j) {
197  if (!foundGreen[j]) {
199  WRITE_WARNING("Missing green phase in tlLogic '" + getID()
200  + "', program '" + getProgramID() + "' for tl-index " + toString(j));
201  }
202  break;
203  }
204  }
205  }
206  // check incompatible junction logic
207  // this can happen if the network was built with a very different signal
208  // plan from the one currently being used.
209  // Cconnections that never had a common green phase during network building may
210  // have a symmetric response relation to avoid certain kinds of jam but this
211  // can lead to deadlock if a different program gives minor green to both
212  // connections at the same time
213  // Note: mutual conflict between 'g' and 'G' is expected for traffic_light_right_on_red
214 
215  const bool mustCheck = MSNet::getInstance()->hasInternalLinks();
216  // The checks only runs for definitions from additional file and this is sufficient.
217  // The distinction is implicit because original logics are loaded earlier and at that time hasInternalLinks is alwas false
218  // Also, when the network has no internal links, mutual conflicts are not built by netconvert
219  //std::cout << "init tlLogic=" << getID() << " prog=" << getProgramID() << " links=" << myLinks.size() << " internal=" << MSNet::getInstance()->hasInternalLinks() << "\n";
220  if (mustCheck && phases.size() > 0) {
221  // see NBNode::tlsConflict
222  std::set<const MSJunction*> controlledJunctions;
223  const int numLinks = (int)myLinks.size();
224  for (int j = 0; j < numLinks; ++j) {
225  for (int k = 0; k < (int)myLinks[j].size(); ++k) {
226  MSLink* link = myLinks[j][k];
227  assert(link->getJunction() != nullptr);
228  controlledJunctions.insert(link->getJunction());
229  }
230  }
231  const std::string minor = "gos";
232  for (const MSJunction* junction : controlledJunctions) {
233  const MSJunctionLogic* logic = junction->getLogic();
234  if (logic != nullptr) {
235  // find symmetrical response
236  const int logicSize = logic->getLogicSize();
237  std::vector<int> tlIndex;
238  for (int u = 0; u < logicSize; u++) {
239  const MSLogicJunction::LinkBits& response = logic->getResponseFor(u);
240  for (int v = 0; v < logicSize; v++) {
241  if (response.test(v)) {
242  if (logic->getResponseFor(v).test(u)) {
243  // get tls link index for links u and v
244  if (tlIndex.size() == 0) {
245  // init tlindex for all links once
246  tlIndex.resize(logicSize, -1);
247  for (int j = 0; j < numLinks; ++j) {
248  for (int k = 0; k < (int)myLinks[j].size(); ++k) {
249  MSLink* link = myLinks[j][k];
250  if (link->getJunction() == junction) {
251  tlIndex[link->getIndex()] = link->getTLIndex();
252  }
253  }
254  }
255  }
256  const int tlu = tlIndex[u];
257  const int tlv = tlIndex[v];
258  if (tlu >= 0 && tlv >= 0) {
259  int phaseIndex = 0;
260  for (MSPhaseDefinition* p : phases) {
261  if (minor.find(p->getState()[tlu]) != std::string::npos
262  && minor.find(p->getState()[tlv]) != std::string::npos) {
263  WRITE_ERROR("Program '" + getProgramID() + "' at tlLogic '" + getID() + "' is incompatible with logic at junction '" + junction->getID() + "'"
264  + " (mututal conflict between link indices " + toString(u) + "," + toString(v)
265  + " tl indices " + toString(tlu) + "," + toString(tlv) + " phase " + toString(phaseIndex) + ")."
266  + "\n Rebuild the network with option '--tls.ignore-internal-junction-jam or include the program when building.");
267  return;
268  }
269  phaseIndex++;
270  }
271  }
272  }
273  }
274  }
275  }
276  }
277  }
278  }
279  myNumLinks = (int)myLinks.size();
280 }
281 
282 
284  // no need to do something about mySwitchCommand here,
285  // it is handled by the event control
286 }
287 
288 
289 // ----------- Handling of controlled links
290 void
292  // !!! should be done within the loader (checking necessary)
293  myLinks.reserve(pos + 1);
294  while ((int)myLinks.size() <= pos) {
295  myLinks.push_back(LinkVector());
296  }
297  myLinks[pos].push_back(link);
298  //
299  myLanes.reserve(pos + 1);
300  while ((int)myLanes.size() <= pos) {
301  myLanes.push_back(LaneVector());
302  }
303  myLanes[pos].push_back(lane);
304  link->setTLState((LinkState) getCurrentPhaseDef().getState()[pos], MSNet::getInstance()->getCurrentTimeStep());
305 }
306 
307 
308 void
310  myLinks = logic.myLinks;
311  myLanes = logic.myLanes;
313 }
314 
315 
316 std::map<MSLink*, LinkState>
318  std::map<MSLink*, LinkState> ret;
319  for (LinkVectorVector::const_iterator i1 = myLinks.begin(); i1 != myLinks.end(); ++i1) {
320  const LinkVector& l = (*i1);
321  for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
322  ret[*i2] = (*i2)->getState();
323  }
324  }
325  return ret;
326 }
327 
328 
329 bool
331  // get the current traffic light signal combination
332  const std::string& state = getCurrentPhaseDef().getState();
333  // go through the links
334  for (int i = 0; i < (int)myLinks.size(); i++) {
335  const LinkVector& currGroup = myLinks[i];
336  LinkState ls = (LinkState) state[i];
337  for (LinkVector::const_iterator j = currGroup.begin(); j != currGroup.end(); j++) {
338  (*j)->setTLState(ls, t);
339  }
340  }
341  return true;
342 }
343 
344 
345 void
346 MSTrafficLightLogic::resetLinkStates(const std::map<MSLink*, LinkState>& vals) const {
347  for (LinkVectorVector::const_iterator i1 = myLinks.begin(); i1 != myLinks.end(); ++i1) {
348  const LinkVector& l = (*i1);
349  for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
350  assert(vals.find(*i2) != vals.end());
351  (*i2)->setTLState(vals.find(*i2)->second, MSNet::getInstance()->getCurrentTimeStep());
352  }
353  }
354 }
355 
356 
357 // ----------- Static Information Retrieval
358 int
359 MSTrafficLightLogic::getLinkIndex(const MSLink* const link) const {
360  int index = 0;
361  for (LinkVectorVector::const_iterator i1 = myLinks.begin(); i1 != myLinks.end(); ++i1, ++index) {
362  const LinkVector& l = (*i1);
363  for (LinkVector::const_iterator i2 = l.begin(); i2 != l.end(); ++i2) {
364  if ((*i2) == link) {
365  return index;
366  }
367  }
368  }
369  return -1;
370 }
371 
372 
373 
374 // ----------- Dynamic Information Retrieval
375 SUMOTime
377  return mySwitchCommand != nullptr ? mySwitchCommand->getNextSwitchTime() : -1;
378 }
379 
380 
381 SUMOTime
383  if (simStep == -1) {
384  simStep = SIMSTEP;
385  }
386  const SUMOTime nextSwitch = getNextSwitchTime();
387  if (nextSwitch == -1) {
388  return -1;
389  } else {
390  const SUMOTime remaining = nextSwitch - simStep;
391  return getCurrentPhaseDef().duration - remaining;
392  }
393 }
394 
395 
396 // ----------- Changing phases and phase durations
397 void
399  myOverridingTimes.push_back(duration);
400 }
401 
402 
403 void
406 }
407 
408 
410  // set mesoscopic time penalties
411  const Phases& phases = getPhases();
412  const int numLinks = (int)myLinks.size();
413  // warning already given if not all states are used
414  assert(numLinks <= (int)phases.front()->getState().size());
415  SUMOTime duration = 0;
416  std::vector<double> redDuration(numLinks, 0);
417  std::vector<double> totalRedDuration(numLinks, 0);
418  std::vector<double> penalty(numLinks, 0);
419  for (int i = 0; i < (int)phases.size(); ++i) {
420  const std::string& state = phases[i]->getState();
421  duration += phases[i]->duration;
422  // warn about transitions from green to red without intermediate yellow
423  for (int j = 0; j < numLinks; ++j) {
424  if ((LinkState)state[j] == LINKSTATE_TL_RED
425  || (LinkState)state[j] == LINKSTATE_TL_REDYELLOW) {
426  redDuration[j] += STEPS2TIME(phases[i]->duration);
427  totalRedDuration[j] += STEPS2TIME(phases[i]->duration);
428  } else if (redDuration[j] > 0) {
429  penalty[j] += 0.5 * (redDuration[j] * redDuration[j] + redDuration[j]);
430  redDuration[j] = 0;
431  }
432  }
433  }
435  for (int j = 0; j < numLinks; ++j) {
436  if (redDuration[j] > 0) {
437  penalty[j] += 0.5 * (redDuration[j] * redDuration[j] + redDuration[j]);
438  redDuration[j] = 0;
439  }
440  }
441  const double durationSeconds = STEPS2TIME(duration);
442  std::set<const MSJunction*> controlledJunctions;
443  for (int j = 0; j < numLinks; ++j) {
444  for (int k = 0; k < (int)myLinks[j].size(); ++k) {
445  MSLink* link = myLinks[j][k];
446  MSEdge& edge = link->getLaneBefore()->getEdge();
448  double greenFraction = (durationSeconds - totalRedDuration[j]) / durationSeconds;
449  if (edgeType.tlsFlowPenalty == 0) {
450  greenFraction = 1;
451  } else {
452  greenFraction = MAX2(MIN2(greenFraction / edgeType.tlsFlowPenalty, 1.0), 0.01);
453  }
454  if (greenFraction == 0.01) {
455  WRITE_WARNINGF("Green fraction is only 1% for link % in tlLogic '%', program '%'.", "%", j, getID(), getProgramID());
456  }
457  link->setMesoTLSPenalty(TIME2STEPS(edgeType.tlsPenalty * penalty[j] / durationSeconds));
458  link->setGreenFraction(greenFraction);
459  controlledJunctions.insert(link->getLane()->getEdge().getFromJunction()); // MSLink::myJunction is not yet initialized
460  //std::cout << " tls=" << getID() << " i=" << j << " link=" << link->getViaLaneOrLane()->getID() << " penalty=" << penalty[j] / durationSeconds << " durSecs=" << durationSeconds << " greenTime=" << " gF=" << myLinks[j][k]->getGreenFraction() << "\n";
461  }
462  }
463  // initialize empty-net travel times
464  // XXX refactor after merging sharps (links know their incoming edge)
465  for (std::set<const MSJunction*>::iterator it = controlledJunctions.begin(); it != controlledJunctions.end(); ++it) {
466  const ConstMSEdgeVector incoming = (*it)->getIncoming();
467  for (ConstMSEdgeVector::const_iterator it_e = incoming.begin(); it_e != incoming.end(); ++it_e) {
468  const_cast<MSEdge*>(*it_e)->recalcCache();
469  }
470  }
471 
472 }
473 
474 
475 void
477  myIgnoredIndices.insert(pos);
478 }
479 
480 SUMOTime
482  return mapTimeInCycle(SIMSTEP);
483 }
484 
485 
486 SUMOTime
488  return (t - myOffset) % myDefaultCycleTime;
489 }
490 
491 
492 bool
494  return MSNet::getInstance()->isSelected(this);
495 }
496 
497 
498 void
500  myAmActive = true;
501 }
502 
503 
504 void
506  myAmActive = false;
507 }
508 
509 bool
511  if (linkIndex >= 0 && linkIndex < getNumLinks()) {
512  for (const MSPhaseDefinition* p : getPhases()) {
513  const std::string& s = p->getState();
514  assert(linkIndex < (int)s.size());
515  if (s[linkIndex] == LINKSTATE_TL_GREEN_MAJOR) {
516  return true;
517  }
518  }
519  }
520  return false;
521 
522 }
523 
524 /****************************************************************************/
std::vector< const MSEdge * > ConstMSEdgeVector
Definition: MSEdge.h:74
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:281
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:288
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
SUMOTime DELTA_T
Definition: SUMOTime.cpp:37
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
#define SIMSTEP
Definition: SUMOTime.h:59
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
long long int SUMOTime
Definition: SUMOTime.h:32
@ 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_TL_GREEN_MAJOR
The link has green light, may pass.
@ LINKSTATE_TL_RED
The link has red light (must brake)
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
T MIN3(T a, T b, T c)
Definition: StdDefs.h:87
T MIN2(T a, T b)
Definition: StdDefs.h:74
T MAX2(T a, T b)
Definition: StdDefs.h:80
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
A road/street connecting two junctions.
Definition: MSEdge.h:77
void recalcCache()
Recalculates the cached values.
Definition: MSEdge.cpp:116
const MSJunction * getFromJunction() const
Definition: MSEdge.h:397
const std::string & getEdgeType() const
Returns the type of the edge.
Definition: MSEdge.h:313
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static bool gUseMesoSim
Definition: MSGlobals.h:94
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:82
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:674
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:174
virtual bool isSelected(const MSTrafficLightLogic *) const
return wheter the given logic (or rather it's wrapper) is selected in the GUI
Definition: MSNet.h:584
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:318
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:469
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:354
bool hasInternalLinks() const
return whether the network contains internal links
Definition: MSNet.h:768
The definition of a single phase of a tls logic.
const std::string & getState() const
Returns the state within this phase.
SUMOTime duration
The duration of the phase.
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.
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.
MSTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const SUMOTime offset, const TrafficLightType logicType, const SUMOTime delay, const std::map< std::string, std::string > &parameters)
Constructor.
virtual void deactivateProgram()
std::vector< SUMOTime > myOverridingTimes
A list of duration overrides.
void ignoreLinkIndex(int pos)
ignore pedestrian crossing index in mesosim
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
SUMOTime myDefaultCycleTime
The cycle time (without changes)
SUMOTime getTimeInCycle() const
return time within the current cycle
const std::string myProgramID
The id of the logic.
TrafficLightType getLogicType() const
Returns the type of the logic.
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
SUMOTime myCurrentDurationIncrement
A value for enlarge the current duration.
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 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 const Phases & getPhases() const =0
Returns the phases of this tls program.
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
const std::string & getProgramID() const
Returns this tl-logic's id.
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
static const std::string ALLOWED_TLS_LINKSTATES
all allowed characters for phase state
edge type specific meso parameters
Definition: MESegment.h:55