Eclipse SUMO - Simulation of Urban MObility
MSActuatedTrafficLightLogic.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2002-2020 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 // An actuated (adaptive) traffic light logic
21 /****************************************************************************/
22 #pragma once
23 #include <config.h>
24 
25 #include <utility>
26 #include <vector>
27 #include <bitset>
28 #include <map>
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class NLDetectorBuilder;
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
49 public:
60  const std::string& id, const std::string& programID,
62  int step, SUMOTime delay,
63  const std::map<std::string, std::string>& parameter,
64  const std::string& basePath);
65 
66 
71  void init(NLDetectorBuilder& nb);
72 
73 
76 
77 
78 
81 
88 
90  void activateProgram();
91  void deactivateProgram();
92 
93  bool showDetectors() const {
94  return myShowDetectors;
95  }
96 
97  void setShowDetectors(bool show);
98 
100  void setParameter(const std::string& key, const std::string& value);
101 
102 protected:
103  struct InductLoopInfo {
104  InductLoopInfo(MSInductLoop* _loop, int numPhases):
105  loop(_loop),
106  servedPhase(numPhases, false)
107  {}
110  std::vector<bool> servedPhase;
111  };
112 
114  typedef std::vector<std::vector<InductLoopInfo*> > InductLoopMap;
115 
118 
123  SUMOTime duration(const double detectionGap) const;
124 
127 
130  double gapControl();
131 
132 
134  bool hasMajor(const std::string& state, const LaneVector& lanes) const;
136 
138  int decideNextPhase();
139 
140  int getDetectorPriority(const InductLoopInfo& loopInfo) const;
141 
143  int getPhasePriority(int step) const;
144 
146  int getTarget(int step);
147 
149  bool maxLinkDurationReached();
150 
152  bool canExtendLinkGreen(int target);
153 
155  SUMOTime getLinkMinDuration(int target) const;
156 
157 protected:
160 
161  std::vector<InductLoopInfo> myInductLoops;
162 
163 
165  double myMaxGap;
166 
169 
172 
175 
178 
180  std::string myFile;
181 
184 
186  std::string myVehicleTypes;
187 
191  std::vector<SUMOTime> myLinkGreenTimes;
193  std::vector<SUMOTime> myLinkMaxGreenTimes;
195  std::vector<SUMOTime> myLinkMinGreenTimes;
196 };
long long int SUMOTime
Definition: SUMOTime.h:31
An actuated (adaptive) traffic light logic.
double myDetectorGap
The detector distance in seconds.
double myMaxGap
The maximum gap to check in seconds.
void activateProgram()
called when switching programs
int getTarget(int step)
get the green phase following step
void setParameter(const std::string &key, const std::string &value)
Sets a parameter and updates internal constants.
SUMOTime myLastTrySwitchTime
last time trySwitch was called
int getDetectorPriority(const InductLoopInfo &loopInfo) const
SUMOTime myFreq
The frequency for aggregating detector output.
SUMOTime getMinimumMinDuration(MSLane *lane) const
get the minimum min duration for all stretchable phases that affect the given lane
bool myShowDetectors
Whether the detectors shall be shown in the GUI.
std::vector< SUMOTime > myLinkMaxGreenTimes
maximum consecutive time that the given link may remain green
std::vector< std::vector< InductLoopInfo * > > InductLoopMap
Definition of a map from phases to induct loops controlling them.
std::string myVehicleTypes
Whether detector output separates by vType.
double gapControl()
Return the minimum detection gap of all detectors if the current phase should be extended and double:...
void init(NLDetectorBuilder &nb)
Initialises the tls with information about incoming lanes.
std::vector< SUMOTime > myLinkMinGreenTimes
minimum consecutive time that the given link must remain green
SUMOTime trySwitch()
Switches to the next phase.
double myPassingTime
The passing time used in seconds.
SUMOTime getLinkMinDuration(int target) const
the minimum duratin for keeping the current phase due to linkMinDur constraints
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.
bool canExtendLinkGreen(int target)
whether the target phase is acceptable in light of linkMaxDur constraints
InductLoopMap myInductLoopsForPhase
A map from phase to induction loops to be used for gap control.
int getPhasePriority(int step) const
count the number of active detectors for the given step
SUMOTime duration(const double detectionGap) const
Returns the minimum duration of the current phase.
std::vector< InductLoopInfo > myInductLoops
bool maxLinkDurationReached()
whether the current phase cannot be continued due to linkMaxDur constraints
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
std::vector< SUMOTime > myLinkGreenTimes
consecutive time that the given link index has been green
std::string myFile
The output file for generated detectors.
int decideNextPhase()
select am candidate phases based on detector states
SUMOTime myInactiveThreshold
The time threshold to avoid starved phases.
An unextended detector measuring at a fixed position on a fixed lane.
Definition: MSInductLoop.h:62
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
A fixed traffic light logic.
A class that stores and controls tls and switching of their programs.
std::vector< MSLane * > LaneVector
Definition of the list of arrival lanes subjected to this tls.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
Builds detectors for microsim.
InductLoopInfo(MSInductLoop *_loop, int numPhases)