Eclipse SUMO - Simulation of Urban MObility
MSSOTLTrafficLightLogic.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2013-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 base abstract class for SOTL logics
21/****************************************************************************/
22#pragma once
23#include <config.h>
24
28#include "MSSOTLDefinitions.h"
30#include "MSSOTLE2Sensors.h"
31
32
33// ===========================================================================
34// class declarations
35// ===========================================================================
36class MSPushButton;
37
38
39// ===========================================================================
40// class definitions
41// ===========================================================================
42
56public:
57 // typedef int CTS;
58
70 MSSOTLTrafficLightLogic(MSTLLogicControl& tlcontrol, const std::string& id,
71 const std::string& programID, const TrafficLightType logicType, const Phases& phases, int step,
72 SUMOTime delay,
73 const Parameterised::Map& parameters);
74
87 MSSOTLTrafficLightLogic(MSTLLogicControl& tlcontrol, const std::string& id,
88 const std::string& programID, const TrafficLightType logicType, const Phases& phases, int step,
89 SUMOTime delay,
90 const Parameterised::Map& parameters,
91 MSSOTLSensors* sensors);
92
95
102 void init(NLDetectorBuilder& nb);
103
104 /*
105 * This member implements the base operations for all SOTL logics.
106 * SOTL politics are implementated through decidePhase() member
107 * @see MSTrafficLightLogic::trySwitch
108 */
110
111protected:
112
113 typedef std::map<const std::string, std::vector<MSPushButton*> > PhasePushButtons;
115
116 void logStatus();
117 /*
118 * This member has to contain the switching logic for SOTL policies
119 */
120
121 virtual int decideNextPhase();
122
123 virtual bool canRelease() = 0;
124
126
127 /*
128 * Count the number of vehicles approaching the target lanes for the given phase.
129 * If the phase in not a target phase the function member will return 0.
130 * @param[in] The target phase index
131 */
133
134 /*
135 * Every target step except the one from the current chain is checked.
136 * This is because the current chain is not eligible to be directly
137 * targeted again, it would be unfair.
138 * @return True if at least a target phase has passed the threshold for input cars-timesteps
139 */
140 bool isThresholdPassed();
141
146 bool isPushButtonPressed();
147
149 return StringUtils::toInt(getParameter("THRESHOLD", "10"));
150 }
151
153 return StringUtils::toDouble(getParameter("THRESHOLDSPEED", "2"));
154 }
155
157 return StringUtils::toDouble(getParameter("INSENSORSLENGTH", "100"));
158 }
159
161 return StringUtils::toDouble(getParameter("OUTSENSORSLENGTH", "80"));
162 }
163
164 /*
165 * Every target step except the one from the current chain is checked.
166 * This is because the current chain is not eligible to be directly
167 * targeted again, it would be unfair.
168 * @return The index of the phase with the maximum value of cars-timesteps
169 */
171
173 return mySensors;
174 }
175
180 return myCountSensors;
181 }
182 /*
183 * Computes how much time will pass after decideNextPhase will be executed again
184 */
186 if (getCurrentPhaseDef().isTransient()) {
188
189 }
190 return DELTA_T;
191
192 }
193
194
195private:
196 /*
197 * Pointer to the sensor logic regarding the junction controlled by this SOTLTrafficLightLogic
198 */
200
201 /*
202 * Pointer to the sensor logic regarding the count of the vehicles that pass into a tl.
203 */
205
206 /*
207 * When true means the class has responsibilities to intantiate and delete the SOTLSensors instance,
208 * otherwise MSSOTLTrafficLightLogic::init and MSSOTLTrafficLightLogic::~MSSOTLTrafficLightLogic have not to affect SOTLSensors instance lifecycle
209 */
211
212 // The map to store the cars*timesteps for each target phase
213 std::map<int, SUMOTime> targetPhasesCTS;
214
215 //The map to store the time each target phase have been checked last
216 //This helps to compute the timesteps to get the cars*timesteps value
217 std::map<int, SUMOTime> lastCheckForTargetPhase;
218
219 //Map to store how many selection rounds have been done from the last selection of the phase
220 std::map<int, int> targetPhasesLastSelection;
221
223 //return 2 * targetPhasesCTS.size() - 1;
224 return (int)targetPhasesCTS.size() - 1;
225 }
226
227 /*
228 * This member keeps track which is the current steps chain, i.e.
229 * which is the last target phase executed (even if it is currently executed)
230 * (a steps chain starts always with a target phase)
231 */
233
235 /*
236 * @brief Check for phases compliancy
237 */
238 void checkPhases();
239
240 /*
241 * Find the first target phase and set the current step on it
242 */
243 void setToATargetPhase();
244
245 /*
246 * This function member helps to set up the map keeping track of target phases and associated timesteps
247 */
248 void setupCTS();
249
250 /*
251 * Updates the cars-timesteps counters for each target phase except the one belonging to the current steps chain
252 */
253 void updateCTS();
254
255 /*
256 * To reset the cars-timesteps counter when a target phase is newly selected
257 * If phaseStep is not a target phase nothing happens
258 */
259 void resetCTS(int phaseStep);
260 /*
261 * TEST
262 */
264
265 /*
266 * Traffic threshold calculation mode:
267 * 0-> cars times seconds
268 * 1-> estimated cars times seconds
269 * 2-> queue length
270 */
271 int getMode() {
272 return StringUtils::toInt(getParameter("MODE", "0"));
273 }
274 /*
275 * Decay threshold that should be used in case of penetration rate != 100%
276 * 0-> not active
277 * 1-> active
278 */
280 return StringUtils::toBool(getParameter("DECAY_THRESHOLD", "0"));
281 }
282
284 return StringUtils::toDouble(getParameter("DECAY_CONSTANT", "-0.001"));
285 }
286
287};
long long int SUMOTime
Definition: GUI.h:36
SUMOTime DELTA_T
Definition: SUMOTime.cpp:37
TrafficLightType
The definition of a single phase of a tls logic.
SUMOTime duration
The duration of the phase.
A fixed traffic light logic.
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
A self-organizing traffic light logic.
std::map< int, SUMOTime > lastCheckForTargetPhase
SUMOTime trySwitch()
Switches to the next phase.
virtual bool canRelease()=0
std::map< const std::string, std::vector< MSPushButton * > > PhasePushButtons
MSSOTLE2Sensors * getCountSensors()
Return the sensors that count the passage of vehicles in and out of the tl.
int countVehicles(MSPhaseDefinition phase)
std::map< int, SUMOTime > targetPhasesCTS
virtual SUMOTime computeReturnTime()
std::map< int, int > targetPhasesLastSelection
MSSOTLTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const TrafficLightType logicType, const Phases &phases, int step, SUMOTime delay, const Parameterised::Map &parameters)
Constructor without sensors passed.
void init(NLDetectorBuilder &nb)
Initialises the tls with sensors on incoming and outgoing lanes Sensors are built in the simulation a...
A class that stores and controls tls and switching of their programs.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
Builds detectors for microsim.
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter