Eclipse SUMO - Simulation of Urban MObility
MSActuatedTrafficLightLogic.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // An actuated (adaptive) traffic light logic
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <cassert>
28 #include <utility>
29 #include <vector>
30 #include <bitset>
34 #include <microsim/MSGlobals.h>
35 #include <microsim/MSNet.h>
36 #include "MSTrafficLightLogic.h"
38 #include <microsim/MSLane.h>
39 #include <microsim/MSEdge.h>
42 
43 //#define DEBUG_DETECTORS
44 //#define DEBUG_PHASE_SELECTION
45 #define DEBUG_COND (getID()=="C")
46 
47 // ===========================================================================
48 // parameter defaults definitions
49 // ===========================================================================
50 #define DEFAULT_MAX_GAP "3.0"
51 #define DEFAULT_PASSING_TIME "1.9"
52 #define DEFAULT_DETECTOR_GAP "2.0"
53 #define DEFAULT_INACTIVE_THRESHOLD "180"
54 #define DEFAULT_CURRENT_PRIORITY 10
55 
56 #define DEFAULT_LENGTH_WITH_GAP 7.5
57 
58 
59 // ===========================================================================
60 // method definitions
61 // ===========================================================================
63  const std::string& id, const std::string& programID,
64  const Phases& phases,
65  int step, SUMOTime delay,
66  const std::map<std::string, std::string>& parameter,
67  const std::string& basePath) :
68  MSSimpleTrafficLightLogic(tlcontrol, id, programID, TLTYPE_ACTUATED, phases, step, delay, parameter) {
69 
74  myShowDetectors = StringUtils::toBool(getParameter("show-detectors", toString(OptionsCont::getOptions().getBool("tls.actuated.show-detectors"))));
75  myFile = FileHelpers::checkForRelativity(getParameter("file", "NUL"), basePath);
77  myVehicleTypes = getParameter("vTypes", "");
78 }
79 
81 
82 void
85  assert(myLanes.size() > 0);
86  bool warn = true; // warn only once
87  const int numLinks = (int)myLinks.size();
88 
89  // Detector position should be computed based on road speed. If the position
90  // is quite far away and the minDur is short this may cause the following
91  // problems:
92  //
93  // 1) high flow failure:
94  // In a standing queue, no vehicle touches the detector.
95  // By the time the queue advances, the detector gap has been exceeded and the phase terminates prematurely
96  //
97  // 2) low flow failure
98  // The standing queue is fully between stop line and detector and there are no further vehicles.
99  // The minDur is too short to let all vehicles pass
100  //
101  // Problem 2) is not so critical because there is less potential for
102  // jamming in a low-flow situation. In contrast, problem 1) should be
103  // avoided as it has big jamming potential. We compute an upper bound for the
104  // detector distance to avoid it
105 
106 
107  // change values for setting the loops and lanestate-detectors, here
108  //SUMOTime inductLoopInterval = 1; //
109  LaneVectorVector::const_iterator i2;
110  LaneVector::const_iterator i;
111  // build the induct loops
112  std::map<const MSLane*, MSInductLoop*> laneInductLoopMap;
113  std::map<MSInductLoop*, const MSLane*> inductLoopLaneMap; // in case loops are placed further upstream
114  double maxDetectorGap = 0;
115  for (i2 = myLanes.begin(); i2 != myLanes.end(); ++i2) {
116  const LaneVector& lanes = *i2;
117  for (i = lanes.begin(); i != lanes.end(); i++) {
118  MSLane* lane = (*i);
119  if (noVehicles(lane->getPermissions())) {
120  // do not build detectors on green verges or sidewalks
121  continue;
122  }
123  if (laneInductLoopMap.find(lane) != laneInductLoopMap.end()) {
124  // only build one detector per lane
125  continue;
126  }
127  const SUMOTime minDur = getMinimumMinDuration(lane);
128  if (minDur == std::numeric_limits<SUMOTime>::max()) {
129  // only build detector if this lane is relevant for an actuated phase
130  continue;
131  }
132  double length = lane->getLength();
133  double speed = lane->getSpeedLimit();
134  double inductLoopPosition = MIN2(
135  myDetectorGap * speed,
136  (STEPS2TIME(minDur) / myPassingTime + 0.5) * DEFAULT_LENGTH_WITH_GAP);
137 
138  // check whether the lane is long enough
139  double ilpos = length - inductLoopPosition;
140  MSLane* placementLane = lane;
141  while (ilpos < 0 && placementLane->getIncomingLanes().size() == 1) {
142  placementLane = placementLane->getLogicalPredecessorLane();
143  ilpos += placementLane->getLength();
144  }
145  if (ilpos < 0) {
146  ilpos = 0;
147  }
148  // Build the induct loop and set it into the container
149  std::string id = "TLS" + myID + "_" + myProgramID + "_InductLoopOn_" + lane->getID();
150  MSInductLoop* loop = static_cast<MSInductLoop*>(nb.createInductLoop(id, placementLane, ilpos, myVehicleTypes, myShowDetectors));
151  laneInductLoopMap[lane] = loop;
152  inductLoopLaneMap[loop] = lane;
153  myInductLoops.push_back(InductLoopInfo(loop, (int)myPhases.size()));
155  maxDetectorGap = MAX2(maxDetectorGap, length - ilpos);
156 
157  if (warn && floor(floor(inductLoopPosition / DEFAULT_LENGTH_WITH_GAP) * myPassingTime) > STEPS2TIME(minDur)) {
158  // warn if the minGap is insufficient to clear vehicles between stop line and detector
159  WRITE_WARNING("At actuated tlLogic '" + getID() + "', minDur " + time2string(minDur) + " is too short for a detector gap of " + toString(inductLoopPosition) + "m.");
160  warn = false;
161  }
162  }
163  }
164  // assign loops to phase index (myInductLoopsForPhase)
165  // check1: loops may not be used for a phase if there are other connections from the same lane that may not drive in that phase
166  // greenMinor is ambiguous as vehicles may not be able to drive
167  // Under the following condition we allow actuation from minor link:
168  // check1a : the minor link is minor in all phases
169  // check1b : there is another major link from the same lane in the current phase
170  // (Under these conditions we assume that the minor link is unimportant and traffic is mostly for the major link)
171  //
172  // check1c: when the lane has only one edge, we treat greenMinor as green as there would be no actuation otherwise
173  //
174  // check2: if there are two loops on subsequent lanes (joined tls) and the second one has a red link, the first loop may not be used
175 
176  // also assign loops to link index for validation:
177  // check if all links from actuated phases (minDur != maxDur) have an inductionloop in at least one phase
178  const SVCPermissions motorized = ~(SVC_PEDESTRIAN | SVC_BICYCLE);
179  std::map<int, std::set<MSInductLoop*> > linkToLoops;
180  std::set<int> actuatedLinks;
181 
182  std::vector<bool> neverMajor(numLinks, true);
183  for (const MSPhaseDefinition* phase : myPhases) {
184  const std::string& state = phase->getState();
185  for (int i = 0; i < numLinks; i++) {
186  if (state[i] == LINKSTATE_TL_GREEN_MAJOR) {
187  neverMajor[i] = false;
188  }
189  }
190  }
191  std::vector<bool> oneLane(numLinks, false);
192  for (int i = 0; i < numLinks; i++) {
193  for (MSLane* lane : getLanesAt(i)) {
194  // only count motorized vehicle lanes
195  int numMotorized = 0;
196  for (MSLane* l : lane->getEdge().getLanes()) {
197  if ((l->getPermissions() & motorized) != 0) {
198  numMotorized++;
199  }
200  }
201  if (numMotorized == 1) {
202  oneLane[i] = true;
203  break;
204  }
205  }
206  }
207 
208 
209  for (const MSPhaseDefinition* phase : myPhases) {
210  const int phaseIndex = (int)myInductLoopsForPhase.size();
211  std::set<MSInductLoop*> loops;
212  if (phase->minDuration != phase->maxDuration) {
213  // actuated phase
214  const std::string& state = phase->getState();
215  // collect indices of all green links for the phase
216  std::set<int> greenLinks;
217  // collect green links for each induction loops (in this phase)
218  std::map<MSInductLoop*, std::set<int> > loopLinks;
219 
220  for (int i = 0; i < numLinks; i++) {
221  if (state[i] == LINKSTATE_TL_GREEN_MAJOR
222  || (state[i] == LINKSTATE_TL_GREEN_MINOR
223  && ((neverMajor[i] // check1a
224  && hasMajor(state, getLanesAt(i))) // check1b
225  || oneLane[i])) // check1c
226  ) {
227  greenLinks.insert(i);
228  actuatedLinks.insert(i);
229  }
230 #ifdef DEBUG_DETECTORS
231  //if (DEBUG_COND) {
232  // std::cout << " phase=" << phaseIndex << " i=" << i << " state=" << state[i] << " green=" << greenLinks.count(i) << " oneLane=" << oneLane[i]
233  // << " loopLanes=";
234  // for (MSLane* lane: getLanesAt(i)) {
235  // if (laneInductLoopMap.count(lane) != 0) {
236  // std::cout << lane->getID() << " ";
237  // }
238  // }
239  // std::cout << "\n";
240  //}
241 #endif
242  for (MSLane* lane : getLanesAt(i)) {
243  if (laneInductLoopMap.count(lane) != 0) {
244  loopLinks[laneInductLoopMap[lane]].insert(i);
245  }
246  }
247  }
248  for (auto& item : loopLinks) {
249  MSInductLoop* loop = item.first;
250  const MSLane* loopLane = inductLoopLaneMap[loop];
251  bool usable = true;
252  // check1
253  for (int j : item.second) {
254  if (greenLinks.count(j) == 0) {
255  usable = false;
256 #ifdef DEBUG_DETECTORS
257  if (DEBUG_COND) {
258  std::cout << " phase=" << phaseIndex << " check1: loopLane=" << loopLane->getID() << " notGreen=" << j << " oneLane[j]=" << oneLane[j] << "\n";
259  }
260 #endif
261  break;
262  }
263  }
264  // check2
265  if (usable) {
266  for (MSLink* link : loopLane->getLinkCont()) {
267  const MSLane* next = link->getLane();
268  if (laneInductLoopMap.count(next) != 0) {
269  MSInductLoop* nextLoop = laneInductLoopMap[next];
270  for (int j : loopLinks[nextLoop]) {
271  if (greenLinks.count(j) == 0) {
272  usable = false;
273 #ifdef DEBUG_DETECTORS
274  if (DEBUG_COND) std::cout << " phase=" << phaseIndex << " check2: loopLane=" << loopLane->getID()
275  << " nextLane=" << next->getID() << " nextLink=" << j << " nextState=" << state[j] << "\n";
276 #endif
277  break;
278  }
279  }
280  }
281  }
282  }
283 
284  if (usable) {
285  loops.insert(item.first);
286 #ifdef DEBUG_DETECTORS
287  //if (DEBUG_COND) std::cout << " phase=" << phaseIndex << " usableLoops=" << item.first->getID() << " links=" << joinToString(item.second, " ") << "\n";
288 #endif
289  for (int j : item.second) {
290  linkToLoops[j].insert(item.first);
291  }
292  }
293  }
294  if (loops.size() == 0) {
295  WRITE_WARNING("At actuated tlLogic '" + getID() + "', actuated phase " + toString(phaseIndex) + " has no controlling detector");
296  }
297  }
298 #ifdef DEBUG_DETECTORS
299  if (DEBUG_COND) {
300  std::cout << " phase=" << phaseIndex << " loops=" << joinNamedToString(loops, " ") << "\n";
301  }
302  //if (DEBUG_COND) {
303  // std::cout << " linkToLoops:\n";
304  // for (auto item : linkToLoops) {
305  // std::cout << " link=" << item.first << " loops=" << joinNamedToString(item.second, " ") << "\n";
306  // }
307  //}
308 #endif
309  std::vector<InductLoopInfo*> loopInfos;
310  myInductLoopsForPhase.push_back(loopInfos);
311  for (MSInductLoop* loop : loops) {
312  for (InductLoopInfo& loopInfo : myInductLoops) {
313  if (loopInfo.loop == loop) {
314  myInductLoopsForPhase.back().push_back(&loopInfo);
315  loopInfo.servedPhase[phaseIndex] = true;
316  }
317  }
318  }
319  }
320 #ifdef DEBUG_DETECTORS
321  //if (DEBUG_COND) {
322  // std::cout << "final linkToLoops:\n";
323  // for (auto item : linkToLoops) {
324  // std::cout << " link=" << item.first << " loops=" << joinNamedToString(item.second, " ") << "\n";
325  // }
326  //}
327 #endif
328  for (int i : actuatedLinks) {
329  if (linkToLoops[i].size() == 0 && myLinks[i].size() > 0
330  && (myLinks[i].front()->getLaneBefore()->getPermissions() & motorized) != 0) {
331  WRITE_WARNING("At actuated tlLogic '" + getID() + "', linkIndex " + toString(i) + " has no controlling detector");
332  }
333  }
334 }
335 
336 
337 SUMOTime
339  SUMOTime result = std::numeric_limits<SUMOTime>::max();
340  for (const MSPhaseDefinition* phase : myPhases) {
341  const std::string& state = phase->getState();
342  for (int i = 0; i < (int)state.size(); i++) {
343  if (state[i] == LINKSTATE_TL_GREEN_MAJOR || state[i] == LINKSTATE_TL_GREEN_MINOR) {
344  for (MSLane* cand : getLanesAt(i)) {
345  if (lane == cand) {
346  if (phase->minDuration != phase->maxDuration) {
347  result = MIN2(result, phase->minDuration);
348  }
349  }
350  }
351  }
352  }
353  }
354  return result;
355 }
356 
357 bool
358 MSActuatedTrafficLightLogic::hasMajor(const std::string& state, const LaneVector& lanes) const {
359  for (int i = 0; i < (int)state.size(); i++) {
360  if (state[i] == LINKSTATE_TL_GREEN_MAJOR) {
361  for (MSLane* cand : getLanesAt(i)) {
362  for (MSLane* lane : lanes) {
363  if (lane == cand) {
364  return true;
365  }
366  }
367  }
368  }
369  }
370  return false;
371 }
372 
373 
374 // ------------ Switching and setting current rows
375 void
378  for (InductLoopInfo& loopInfo : myInductLoops) {
379  loopInfo.loop->setVisible(true);
380  }
381 }
382 
383 
384 void
387  for (InductLoopInfo& loopInfo : myInductLoops) {
388  loopInfo.loop->setVisible(false);
389  }
390 }
391 
392 SUMOTime
394  // checks if the actual phase should be continued
395  // @note any vehicles which arrived during the previous phases which are now waiting between the detector and the stop line are not
396  // considere here. RiLSA recommends to set minDuration in a way that lets all vehicles pass the detector
398  const double detectionGap = gapControl();
399  const bool multiTarget = myPhases[myStep]->nextPhases.size() > 1 && myPhases[myStep]->nextPhases.front() >= 0;
400 #ifdef DEBUG_PHASE_SELECTION
401  if (DEBUG_COND) {
402  std::cout << SIMTIME << " p=" << myStep << " trySwitch dGap=" << detectionGap << " multi=" << multiTarget << "\n";
403  }
404 #endif
405  if (detectionGap < std::numeric_limits<double>::max() && !multiTarget) {
406  return duration(detectionGap);
407  }
408  // decide the next phase
409  const int origStep = myStep;
410  SUMOTime actDuration = now - myPhases[myStep]->myLastSwitch;
411  if (multiTarget) {
413  } else {
414  if (myPhases[myStep]->nextPhases.size() == 1 && myPhases[myStep]->nextPhases.front() >= 0) {
415  myStep = myPhases[myStep]->nextPhases.front();
416  } else {
417  myStep++;
418  }
419  }
420  assert(myStep <= (int)myPhases.size());
421  assert(myStep >= 0);
422  if (myStep == (int)myPhases.size()) {
423  myStep = 0;
424  }
425  //stores the time the phase started
426  if (myStep != origStep) {
427  myPhases[myStep]->myLastSwitch = now;
428  actDuration = 0;
429  }
430  // activate coloring
431  if ((myShowDetectors || multiTarget) && getCurrentPhaseDef().isGreenPhase()) {
432  for (InductLoopInfo* loopInfo : myInductLoopsForPhase[myStep]) {
433  //std::cout << SIMTIME << " p=" << myStep << " loopinfo=" << loopInfo->loop->getID() << " set lastGreen=" << STEPS2TIME(now) << "\n";
434  loopInfo->loop->setSpecialColor(&RGBColor::GREEN);
435  loopInfo->lastGreenTime = now;
436  }
437  }
438  // set the next event
439  return MAX2(TIME2STEPS(1), getCurrentPhaseDef().minDuration - actDuration);
440 }
441 
442 
443 // ------------ "actuated" algorithm methods
444 SUMOTime
445 MSActuatedTrafficLightLogic::duration(const double detectionGap) const {
446  assert(getCurrentPhaseDef().isGreenPhase());
447  assert((int)myPhases.size() > myStep);
448  const SUMOTime actDuration = MSNet::getInstance()->getCurrentTimeStep() - myPhases[myStep]->myLastSwitch;
449  // ensure that minimum duration is kept
450  SUMOTime newDuration = getCurrentPhaseDef().minDuration - actDuration;
451  // try to let the last detected vehicle pass the intersection (duration must be positive)
452  newDuration = MAX3(newDuration, TIME2STEPS(myDetectorGap - detectionGap), SUMOTime(1));
453  // cut the decimal places to ensure that phases always have integer duration
454  if (newDuration % 1000 != 0) {
455  const SUMOTime totalDur = newDuration + actDuration;
456  newDuration = (totalDur / 1000 + 1) * 1000 - actDuration;
457  }
458  // ensure that the maximum duration is not exceeded
459  newDuration = MIN2(newDuration, getCurrentPhaseDef().maxDuration - actDuration);
460  return newDuration;
461 }
462 
463 
464 double
466  //intergreen times should not be lengthend
467  assert((int)myPhases.size() > myStep);
468  double result = std::numeric_limits<double>::max();
470  return result;
471  }
472  // switch off active colors
473  if (myShowDetectors) {
474  for (InductLoopInfo& loopInfo : myInductLoops) {
475  if (loopInfo.lastGreenTime < loopInfo.loop->getLastDetectionTime()) {
476  loopInfo.loop->setSpecialColor(&RGBColor::RED);
477  } else {
478  loopInfo.loop->setSpecialColor(nullptr);
479  }
480  }
481  }
482  if (!getCurrentPhaseDef().isGreenPhase()) {
483  return result; // end current phase
484  }
485 
486  // Checks, if the maxDuration is kept. No phase should last longer than maxDuration.
487  SUMOTime actDuration = MSNet::getInstance()->getCurrentTimeStep() - myPhases[myStep]->myLastSwitch;
488  if (actDuration >= getCurrentPhaseDef().maxDuration) {
489  return result; // end current phase
490  }
491 
492  // now the gapcontrol starts
493  for (InductLoopInfo* loopInfo : myInductLoopsForPhase[myStep]) {
494  MSInductLoop* loop = loopInfo->loop;
496  const double actualGap = loop->getTimeSinceLastDetection();
497  if (actualGap < myMaxGap) {
498  result = MIN2(result, actualGap);
499  }
500  }
501  return result;
502 }
503 
504 
505 int
507  const auto& cands = myPhases[myStep]->nextPhases;
508  // decide by priority
509  // first target is the default when thre is no traffic
510  // @note: the keep the current phase, even when there is no traffic, it must be added to 'next' explicitly
511  int result = cands.front();
512  int maxPrio = 0;
513  SUMOTime actDuration = MSNet::getInstance()->getCurrentTimeStep() - myPhases[myStep]->myLastSwitch;
514  const bool canExtend = actDuration < getCurrentPhaseDef().maxDuration;
515  if (canExtend) {
516  // consider keeping the current phase until maxDur is reached
517  // (only when there is still traffic in that phase)
518  int currentPrio = getPhasePriority(myStep);
519 #ifdef DEBUG_PHASE_SELECTION
520  std::cout << SIMTIME << " p=" << myStep << " loops=" << myInductLoopsForPhase[myStep].size() << " currentPrio=" << currentPrio << "\n";
521 #endif
522  if (currentPrio > maxPrio) {
523  result = myStep;
524  maxPrio = currentPrio;
525  }
526  }
527  for (int step : cands) {
528  int target = getTarget(step);
529  int prio = getPhasePriority(target);
530 #ifdef DEBUG_PHASE_SELECTION
531  if (DEBUG_COND) {
532  std::cout << SIMTIME << " p=" << myStep << " step=" << step << " target=" << target << " loops=" << myInductLoopsForPhase[target].size() << " prio=" << prio << "\n";
533  }
534 #endif
535  if (prio > maxPrio) {
536  maxPrio = prio;
537  result = step;
538  }
539  }
540  // prevent starvation in phases that are not direct targets
541  for (const InductLoopInfo& loopInfo : myInductLoops) {
542  int prio = getDetectorPriority(loopInfo);
543  if (prio > maxPrio) {
544  result = cands.front();
545  if (result == myStep) {
546  WRITE_WARNING("At actuated tlLogic '" + getID()
547  + "', starvation at e1Detector '" + loopInfo.loop->getID()
548  + "' which cannot be reached from the default phase " + toString(myStep) + ".");
549  }
550  // use default phase to reach other phases
551 #ifdef DEBUG_PHASE_SELECTION
552  if (DEBUG_COND) {
553  std::cout << SIMTIME << " p=" << myStep << " loop=" << loopInfo.loop->getID() << " prio=" << prio << " next=" << result << "\n";
554  }
555 #endif
556  break;
557  }
558  }
559  return result;
560 }
561 
562 
563 int
565  int origStep = step;
566  // if step is a transition, find the upcoming green phase
567  while (!myPhases[step]->isGreenPhase()) {
568  if (myPhases[step]->nextPhases.size() > 0 && myPhases[step]->nextPhases.front() >= 0) {
569  if (myPhases[step]->nextPhases.size() > 1) {
570  WRITE_WARNING("At actuated tlLogic '" + getID() + "', transition phase " + toString(step) + " should not have multiple next phases");
571  }
572  step = myPhases[step]->nextPhases.front();
573  } else {
574  step++;
575  }
576  if (step == origStep) {
577  WRITE_WARNING("At actuated tlLogic '" + getID() + "', infinite transition loop from phase " + toString(origStep));
578  return 0;
579  }
580  }
581  return step;
582 }
583 
584 int
586  MSInductLoop* loop = loopInfo.loop;
587  const double actualGap = loop->getTimeSinceLastDetection();
588  if (actualGap < myMaxGap || loopInfo.lastGreenTime < loop->getLastDetectionTime()) {
589  SUMOTime inactiveTime = MSNet::getInstance()->getCurrentTimeStep() - loopInfo.lastGreenTime;
590  // @note. Inactive time could also be tracked regardless of current activity (to increase robustness in case of detection failure
591  if (inactiveTime > myInactiveThreshold) {
592 #ifdef DEBUG_PHASE_SELECTION
593  if (DEBUG_COND) {
594  std::cout << " loop=" << loop->getID() << " gap=" << loop->getTimeSinceLastDetection() << " lastGreen=" << STEPS2TIME(loopInfo.lastGreenTime)
595  << " lastDetection=" << STEPS2TIME(loop->getLastDetectionTime()) << " inactive=" << STEPS2TIME(inactiveTime) << "\n";
596  }
597 #endif
598  return (int)STEPS2TIME(inactiveTime);
599  } else {
600  // give bonus to detectors that are currently served (if that phase can stil be extended)
601  if (loopInfo.servedPhase[myStep]) {
602  SUMOTime actDuration = MSNet::getInstance()->getCurrentTimeStep() - myPhases[myStep]->myLastSwitch;
603  const bool canExtend = actDuration < getCurrentPhaseDef().maxDuration;
604  if (canExtend) {
606  } else {
607  return 0;
608  }
609  }
610  return 1;
611  }
612  }
613  return 0;
614 }
615 
616 int
618  int result = 0;
619  for (const InductLoopInfo* loopInfo : myInductLoopsForPhase[step]) {
620  result += getDetectorPriority(*loopInfo);
621  }
622  return result;
623 }
624 
625 
626 void
628  myShowDetectors = show;
629  for (InductLoopInfo& loopInfo : myInductLoops) {
630  loopInfo.loop->setVisible(myShowDetectors);
631  }
632 }
633 
634 /****************************************************************************/
635 
MSTrafficLightLogic::activateProgram
virtual void activateProgram()
called when switching programs
Definition: MSTrafficLightLogic.cpp:378
SVC_PEDESTRIAN
@ SVC_PEDESTRIAN
pedestrian
Definition: SUMOVehicleClass.h:156
MSTrafficLightLogic::myLinks
LinkVectorVector myLinks
The list of LinkVectors; each vector contains the links that belong to the same link index.
Definition: MSTrafficLightLogic.h:417
MSTrafficLightLogic::myLanes
LaneVectorVector myLanes
The list of LaneVectors; each vector contains the incoming lanes that belong to the same link index.
Definition: MSTrafficLightLogic.h:420
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:73
MSNet::getDetectorControl
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:399
StringUtils::toBool
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
Definition: StringUtils.cpp:374
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
MSNet.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSDetectorControl.h
NLDetectorBuilder::createInductLoop
virtual MSDetectorFileOutput * createInductLoop(const std::string &id, MSLane *lane, double pos, const std::string &vTypes, bool show=true)
Creates an instance of an e1 detector using the given values.
Definition: NLDetectorBuilder.cpp:378
StringUtils::toDouble
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
Definition: StringUtils.cpp:345
MSTrafficLightLogic::Phases
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
Definition: MSTrafficLightLogic.h:61
MSActuatedTrafficLightLogic::myShowDetectors
bool myShowDetectors
Whether the detectors shall be shown in the GUI.
Definition: MSActuatedTrafficLightLogic.h:167
MSActuatedTrafficLightLogic.h
MSLane::getPermissions
SVCPermissions getPermissions() const
Returns the vehicle class permissions for this lane.
Definition: MSLane.h:548
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSSimpleTrafficLightLogic::getCurrentPhaseDef
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
Definition: MSSimpleTrafficLightLogic.cpp:129
SVC_BICYCLE
@ SVC_BICYCLE
vehicle is a bicycle
Definition: SUMOVehicleClass.h:179
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
LINKSTATE_TL_GREEN_MINOR
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
Definition: SUMOXMLDefinitions.h:1141
MSInductLoop
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:63
FileHelpers::checkForRelativity
static std::string checkForRelativity(const std::string &filename, const std::string &basePath)
Returns the path from a configuration so that it is accessable from the current working directory.
Definition: FileHelpers.cpp:152
MSActuatedTrafficLightLogic::myInductLoops
std::vector< InductLoopInfo > myInductLoops
Definition: MSActuatedTrafficLightLogic.h:151
MSGlobals::gUseMesoSim
static bool gUseMesoSim
Definition: MSGlobals.h:90
MSActuatedTrafficLightLogic::InductLoopInfo
Definition: MSActuatedTrafficLightLogic.h:102
DEFAULT_PASSING_TIME
#define DEFAULT_PASSING_TIME
Definition: MSActuatedTrafficLightLogic.cpp:51
DEFAULT_INACTIVE_THRESHOLD
#define DEFAULT_INACTIVE_THRESHOLD
Definition: MSActuatedTrafficLightLogic.cpp:53
MSEdge.h
MAX3
T MAX3(T a, T b, T c)
Definition: StdDefs.h:93
MSActuatedTrafficLightLogic::~MSActuatedTrafficLightLogic
~MSActuatedTrafficLightLogic()
Destructor.
Definition: MSActuatedTrafficLightLogic.cpp:80
LINKSTATE_TL_GREEN_MAJOR
@ LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
Definition: SUMOXMLDefinitions.h:1139
MSInductLoop::getTimeSinceLastDetection
double getTimeSinceLastDetection() const
Returns the time since the last vehicle left the detector.
Definition: MSInductLoop.cpp:195
MSPhaseDefinition::maxDuration
SUMOTime maxDuration
The maximum duration of the phase.
Definition: MSPhaseDefinition.h:79
Parameterised::getParameter
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
Definition: Parameterised.cpp:72
MSActuatedTrafficLightLogic::decideNextPhase
int decideNextPhase()
select am candidate phases based on detector states
Definition: MSActuatedTrafficLightLogic.cpp:506
MSActuatedTrafficLightLogic::trySwitch
SUMOTime trySwitch()
Switches to the next phase.
Definition: MSActuatedTrafficLightLogic.cpp:393
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
MSTrafficLightLogic.h
MSActuatedTrafficLightLogic::duration
SUMOTime duration(const double detectionGap) const
Returns the minimum duration of the current phase.
Definition: MSActuatedTrafficLightLogic.cpp:445
MSTrafficLightLogic::LaneVector
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
Definition: MSTrafficLightLogic.h:70
SIMTIME
#define SIMTIME
Definition: SUMOTime.h:63
DEFAULT_DETECTOR_GAP
#define DEFAULT_DETECTOR_GAP
Definition: MSActuatedTrafficLightLogic.cpp:52
MSActuatedTrafficLightLogic::getTarget
int getTarget(int step)
get the green phase following step
Definition: MSActuatedTrafficLightLogic.cpp:564
MSActuatedTrafficLightLogic::myFile
std::string myFile
The output file for generated detectors.
Definition: MSActuatedTrafficLightLogic.h:170
MSActuatedTrafficLightLogic::myVehicleTypes
std::string myVehicleTypes
Whether detector output separates by vType.
Definition: MSActuatedTrafficLightLogic.h:176
MSActuatedTrafficLightLogic::getMinimumMinDuration
SUMOTime getMinimumMinDuration(MSLane *lane) const
get the minimum min duration for all stretchable phases that affect the given lane
Definition: MSActuatedTrafficLightLogic.cpp:338
SVCPermissions
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
Definition: SUMOVehicleClass.h:218
TIME2STEPS
#define TIME2STEPS(x)
Definition: SUMOTime.h:58
MSNet::getCurrentTimeStep
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:283
joinNamedToString
std::string joinNamedToString(const std::set< T *, C > &ns, const T_BETWEEN &between)
Definition: ToString.h:280
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
MSTrafficLightLogic::deactivateProgram
virtual void deactivateProgram()
Definition: MSTrafficLightLogic.cpp:384
MSInductLoop::setSpecialColor
virtual void setSpecialColor(const RGBColor *)
allows for special color in the gui version
Definition: MSInductLoop.h:289
MSLane::getLength
double getLength() const
Returns the lane's length.
Definition: MSLane.h:540
NLDetectorBuilder.h
MSActuatedTrafficLightLogic::InductLoopInfo::lastGreenTime
SUMOTime lastGreenTime
Definition: MSActuatedTrafficLightLogic.h:108
DEFAULT_CURRENT_PRIORITY
#define DEFAULT_CURRENT_PRIORITY
Definition: MSActuatedTrafficLightLogic.cpp:54
MSSimpleTrafficLightLogic
A fixed traffic light logic.
Definition: MSSimpleTrafficLightLogic.h:54
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
MSGlobals.h
RGBColor::RED
static const RGBColor RED
named colors
Definition: RGBColor.h:189
MSActuatedTrafficLightLogic::myFreq
SUMOTime myFreq
The frequency for aggregating detector output.
Definition: MSActuatedTrafficLightLogic.h:173
MSLane::getLinkCont
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:2110
MSTrafficLightLogic::myProgramID
const std::string myProgramID
The id of the logic.
Definition: MSTrafficLightLogic.h:411
string2time
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:44
MSLane::getLogicalPredecessorLane
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
Definition: MSLane.cpp:2543
DEBUG_COND
#define DEBUG_COND
Definition: MSActuatedTrafficLightLogic.cpp:45
DEFAULT_MAX_GAP
#define DEFAULT_MAX_GAP
Definition: MSActuatedTrafficLightLogic.cpp:50
MSLane::getEdge
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:669
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
StringUtils.h
MSActuatedTrafficLightLogic::setShowDetectors
void setShowDetectors(bool show)
Definition: MSActuatedTrafficLightLogic.cpp:627
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
MSActuatedTrafficLightLogic::InductLoopInfo::loop
MSInductLoop * loop
Definition: MSActuatedTrafficLightLogic.h:107
MSActuatedTrafficLightLogic::getDetectorPriority
int getDetectorPriority(const InductLoopInfo &loopInfo) const
Definition: MSActuatedTrafficLightLogic.cpp:585
MSActuatedTrafficLightLogic::InductLoopInfo::servedPhase
std::vector< bool > servedPhase
Definition: MSActuatedTrafficLightLogic.h:109
MSActuatedTrafficLightLogic::myInactiveThreshold
SUMOTime myInactiveThreshold
The time threshold to avoid starved phases.
Definition: MSActuatedTrafficLightLogic.h:164
MSSimpleTrafficLightLogic::myPhases
Phases myPhases
The list of phases this logic uses.
Definition: MSSimpleTrafficLightLogic.h:198
MSActuatedTrafficLightLogic::hasMajor
bool hasMajor(const std::string &state, const LaneVector &lanes) const
return whether there is a major link from the given lane in the given phase
Definition: MSActuatedTrafficLightLogic.cpp:358
MSActuatedTrafficLightLogic::myDetectorGap
double myDetectorGap
The detector distance in seconds.
Definition: MSActuatedTrafficLightLogic.h:161
noVehicles
bool noVehicles(SVCPermissions permissions)
Returns whether an edge with the given permission forbids vehicles.
Definition: SUMOVehicleClass.cpp:387
MSEdge::getLanes
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:167
MSActuatedTrafficLightLogic::init
void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
Definition: MSActuatedTrafficLightLogic.cpp:83
MSActuatedTrafficLightLogic::gapControl
double gapControl()
Return the minimum detection gap of all detectors if the current phase should be extended and double:...
Definition: MSActuatedTrafficLightLogic.cpp:465
MSDetectorControl::add
void add(SumoXMLTag type, MSDetectorFileOutput *d, const std::string &device, SUMOTime splInterval, SUMOTime begin=-1)
Adds a detector/output combination into the containers.
Definition: MSDetectorControl.cpp:63
config.h
MSTLLogicControl
A class that stores and controls tls and switching of their programs.
Definition: MSTLLogicControl.h:59
MSActuatedTrafficLightLogic::myInductLoopsForPhase
InductLoopMap myInductLoopsForPhase
A map from phase to induction loops to be used for gap control.
Definition: MSActuatedTrafficLightLogic.h:149
RGBColor::GREEN
static const RGBColor GREEN
Definition: RGBColor.h:190
MSActuatedTrafficLightLogic::MSActuatedTrafficLightLogic
MSActuatedTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const MSSimpleTrafficLightLogic::Phases &phases, int step, SUMOTime delay, const std::map< std::string, std::string > &parameter, const std::string &basePath)
Constructor.
Definition: MSActuatedTrafficLightLogic.cpp:62
MSEventControl.h
MSLane.h
MSPhaseDefinition
The definition of a single phase of a tls logic.
Definition: MSPhaseDefinition.h:51
MSActuatedTrafficLightLogic::myPassingTime
double myPassingTime
The passing time used in seconds.
Definition: MSActuatedTrafficLightLogic.h:158
MSSimpleTrafficLightLogic::myStep
int myStep
The current step.
Definition: MSSimpleTrafficLightLogic.h:201
SUMO_TAG_INDUCTION_LOOP
@ SUMO_TAG_INDUCTION_LOOP
alternative tag for e1 detector
Definition: SUMOXMLDefinitions.h:65
MSInductLoop.h
MSLane::getSpeedLimit
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
Definition: MSLane.h:532
MSTrafficLightLogic::init
virtual void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
Definition: MSTrafficLightLogic.cpp:115
MSInductLoop::getLastDetectionTime
SUMOTime getLastDetectionTime() const
return last time a vehicle was on the detector
Definition: MSInductLoop.cpp:205
Named::myID
std::string myID
The name of the object.
Definition: Named.h:133
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
MSActuatedTrafficLightLogic::myMaxGap
double myMaxGap
The maximum gap to check in seconds.
Definition: MSActuatedTrafficLightLogic.h:155
MSActuatedTrafficLightLogic::activateProgram
void activateProgram()
called when switching programs
Definition: MSActuatedTrafficLightLogic.cpp:376
MSActuatedTrafficLightLogic::deactivateProgram
void deactivateProgram()
Definition: MSActuatedTrafficLightLogic.cpp:385
NLDetectorBuilder
Builds detectors for microsim.
Definition: NLDetectorBuilder.h:55
DEFAULT_LENGTH_WITH_GAP
#define DEFAULT_LENGTH_WITH_GAP
Definition: MSActuatedTrafficLightLogic.cpp:56
TLTYPE_ACTUATED
@ TLTYPE_ACTUATED
Definition: SUMOXMLDefinitions.h:1201
MSActuatedTrafficLightLogic::getPhasePriority
int getPhasePriority(int step) const
count the number of active detectors for the given step
Definition: MSActuatedTrafficLightLogic.cpp:617
MSPhaseDefinition::minDuration
SUMOTime minDuration
The minimum duration of the phase.
Definition: MSPhaseDefinition.h:76
MSTrafficLightLogic::getLanesAt
const LaneVector & getLanesAt(int i) const
Returns the list of lanes that are controlled by the signals at the given position.
Definition: MSTrafficLightLogic.h:191