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-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 /****************************************************************************/
16 // The base abstract class for SOTL logics
17 /****************************************************************************/
18 #ifndef MSSOTLTrafficLightLogic_h
19 #define MSSOTLTrafficLightLogic_h
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
27 
28 #include <utils/common/SUMOTime.h>
29 #include "MSSOTLDefinitions.h"
31 #include "MSSOTLE2Sensors.h"
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class MSPushButton;
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
45 
59 public:
60  // typedef int CTS;
61 
73  MSSOTLTrafficLightLogic(MSTLLogicControl& tlcontrol, const std::string& id,
74  const std::string& programID, const TrafficLightType logicType, const Phases& phases, int step,
75  SUMOTime delay,
76  const std::map<std::string, std::string>& parameters);
77 
90  MSSOTLTrafficLightLogic(MSTLLogicControl& tlcontrol, const std::string& id,
91  const std::string& programID, const TrafficLightType logicType, const Phases& phases, int step,
92  SUMOTime delay,
93  const std::map<std::string, std::string>& parameters,
94  MSSOTLSensors* sensors);
95 
98 
105  void init(NLDetectorBuilder& nb);
106 
107  /*
108  * This member implements the base operations for all SOTL logics.
109  * SOTL politics are implementated through decidePhase() member
110  * @see MSTrafficLightLogic::trySwitch
111  */
113 
114 protected:
115 
116  typedef std::map<const std::string, std::vector<MSPushButton*> > PhasePushButtons;
118 
119  void logStatus();
120  /*
121  * This member has to contain the switching logic for SOTL policies
122  */
123 
124  virtual int decideNextPhase();
125 
126  virtual bool canRelease() = 0;
127 
129 
130  /*
131  * Count the number of vehicles approaching the target lanes for the given phase.
132  * If the phase in not a target phase the function member will return 0.
133  * @param[in] The target phase index
134  */
135  int countVehicles(MSPhaseDefinition phase);
136 
137  /*
138  * Every target step except the one from the current chain is checked.
139  * This is because the current chain is not eligible to be directly
140  * targeted again, it would be unfair.
141  * @return True if at least a target phase has passed the threshold for input cars-timesteps
142  */
143  bool isThresholdPassed();
144 
149  bool isPushButtonPressed();
150 
151  int getThreshold() {
152  return StringUtils::toInt(getParameter("THRESHOLD", "10"));
153  }
154 
155  double getSpeedThreshold() {
156  return StringUtils::toDouble(getParameter("THRESHOLDSPEED", "2"));
157  }
158 
160  return StringUtils::toDouble(getParameter("INSENSORSLENGTH", "100"));
161  }
162 
164  return StringUtils::toDouble(getParameter("OUTSENSORSLENGTH", "80"));
165  }
166 
167  /*
168  * Every target step except the one from the current chain is checked.
169  * This is because the current chain is not eligible to be directly
170  * targeted again, it would be unfair.
171  * @return The index of the phase with the maximum value of cars-timesteps
172  */
174 
176  return mySensors;
177  }
178 
183  return myCountSensors;
184  }
185  /*
186  * Computes how much time will pass after decideNextPhase will be executed again
187  */
189  if (getCurrentPhaseDef().isTransient()) {
190  return getCurrentPhaseDef().duration;
191 
192  }
193  return DELTA_T;
194 
195  }
196 
197 
198 private:
199  /*
200  * Pointer to the sensor logic regarding the junction controlled by this SOTLTrafficLightLogic
201  */
203 
204  /*
205  * Pointer to the sensor logic regarding the count of the vehicles that pass into a tl.
206  */
208 
209  /*
210  * When true means the class has responsibilities to intantiate and delete the SOTLSensors instance,
211  * otherwise MSSOTLTrafficLightLogic::init and MSSOTLTrafficLightLogic::~MSSOTLTrafficLightLogic have not to affect SOTLSensors instance lifecycle
212  */
214 
215  // The map to store the cars*timesteps for each target phase
216  std::map<int, SUMOTime> targetPhasesCTS;
217 
218  //The map to store the time each target phase have been checked last
219  //This helps to compute the timesteps to get the cars*timesteps value
220  std::map<int, SUMOTime> lastCheckForTargetPhase;
221 
222  //Map to store how many selection rounds have been done from the last selection of the phase
223  std::map<int, int> targetPhasesLastSelection;
224 
226  //return 2 * targetPhasesCTS.size() - 1;
227  return (int)targetPhasesCTS.size() - 1;
228  }
229 
230  /*
231  * This member keeps track which is the current steps chain, i.e.
232  * which is the last target phase executed (even if it is currently executed)
233  * (a steps chain starts always with a target phase)
234  */
236 
238  /*
239  * @brief Check for phases compliancy
240  */
241  void checkPhases();
242 
243  /*
244  * Find the first target phase and set the current step on it
245  */
246  void setToATargetPhase();
247 
248  /*
249  * This function member helps to set up the map keeping track of target phases and associated timesteps
250  */
251  void setupCTS();
252 
253  /*
254  * Updates the cars-timesteps counters for each target phase except the one belonging to the current steps chain
255  */
256  void updateCTS();
257 
258  /*
259  * To reset the cars-timesteps counter when a target phase is newly selected
260  * If phaseStep is not a target phase nothing happens
261  */
262  void resetCTS(int phaseStep);
263  /*
264  * TEST
265  */
266  void updateDecayThreshold();
267 
268  /*
269  * Traffic threshold calculation mode:
270  * 0-> cars times seconds
271  * 1-> estimated cars times seconds
272  * 2-> queue length
273  */
274  int getMode() {
275  return StringUtils::toInt(getParameter("MODE", "0"));
276  }
277  /*
278  * Decay threshold that should be used in case of penetration rate != 100%
279  * 0-> not active
280  * 1-> active
281  */
283  return StringUtils::toBool(getParameter("DECAY_THRESHOLD", "0"));
284  }
285 
286  double getDecayConstant() {
287  return StringUtils::toDouble(getParameter("DECAY_CONSTANT", "-0.001"));
288  }
289 
290 };
291 
292 #endif
293 /****************************************************************************/
MSSOTLTrafficLightLogic::getTargetPhaseMaxLastSelection
int getTargetPhaseMaxLastSelection()
Definition: MSSOTLTrafficLightLogic.h:225
MSSOTLTrafficLightLogic::getMode
int getMode()
Definition: MSSOTLTrafficLightLogic.h:274
MSSOTLTrafficLightLogic::trySwitch
SUMOTime trySwitch()
Switches to the next phase.
Definition: MSSOTLTrafficLightLogic.cpp:452
MSSOTLTrafficLightLogic::mySensors
MSSOTLSensors * mySensors
Definition: MSSOTLTrafficLightLogic.h:202
MSSOTLTrafficLightLogic
A self-organizing traffic light logic.
Definition: MSSOTLTrafficLightLogic.h:58
MSSOTLTrafficLightLogic::getCountSensors
MSSOTLE2Sensors * getCountSensors()
Return the sensors that count the passage of vehicles in and out of the tl.
Definition: MSSOTLTrafficLightLogic.h:182
MSSOTLTrafficLightLogic::resetCTS
void resetCTS(int phaseStep)
Definition: MSSOTLTrafficLightLogic.cpp:213
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
MSSOTLTrafficLightLogic::updateDecayThreshold
void updateDecayThreshold()
Definition: MSSOTLTrafficLightLogic.cpp:293
SUMOTime.h
MSSOTLTrafficLightLogic::isThresholdPassed
bool isThresholdPassed()
Definition: MSSOTLTrafficLightLogic.cpp:305
MSSOTLTrafficLightLogic::updateCTS
void updateCTS()
Definition: MSSOTLTrafficLightLogic.cpp:222
DELTA_T
SUMOTime DELTA_T
Definition: SUMOTime.cpp:36
MSSOTLTrafficLightLogic::lastChain
int lastChain
Definition: MSSOTLTrafficLightLogic.h:235
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
MSPhasedTrafficLightLogic::getCurrentPhaseDef
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
Definition: MSPhasedTrafficLightLogic.cpp:131
MSTrafficLightLogic::Phases
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
Definition: MSTrafficLightLogic.h:61
MSPushButton
Definition: MSPushButton.h:30
MSSOTLTrafficLightLogic::getSpeedThreshold
double getSpeedThreshold()
Definition: MSSOTLTrafficLightLogic.h:155
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1197
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSSOTLDefinitions.h
MSSOTLTrafficLightLogic::myCountSensors
MSSOTLE2Sensors * myCountSensors
Definition: MSSOTLTrafficLightLogic.h:207
MSSOTLTrafficLightLogic::canRelease
virtual bool canRelease()=0
MSSOTLTrafficLightLogic::getSensors
MSSOTLSensors * getSensors()
Definition: MSSOTLTrafficLightLogic.h:175
MSSOTLTrafficLightLogic::getOutputSensorsLength
double getOutputSensorsLength()
Definition: MSSOTLTrafficLightLogic.h:163
MSSOTLTrafficLightLogic::isPushButtonPressed
bool isPushButtonPressed()
Definition: MSSOTLTrafficLightLogic.cpp:506
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
MSPhasedTrafficLightLogic.h
MSSOTLTrafficLightLogic::getInputSensorsLength
double getInputSensorsLength()
Definition: MSSOTLTrafficLightLogic.h:159
MSSOTLTrafficLightLogic::getThreshold
int getThreshold()
Definition: MSSOTLTrafficLightLogic.h:151
MSPhaseDefinition::duration
SUMOTime duration
The duration of the phase.
Definition: MSPhaseDefinition.h:70
MSSOTLTrafficLightLogic::computeReturnTime
virtual SUMOTime computeReturnTime()
Definition: MSSOTLTrafficLightLogic.h:188
MSSOTLTrafficLightLogic::~MSSOTLTrafficLightLogic
~MSSOTLTrafficLightLogic()
Destructor.
Definition: MSSOTLTrafficLightLogic.cpp:68
MSSOTLTrafficLightLogic::isDecayThresholdActivated
bool isDecayThresholdActivated()
Definition: MSSOTLTrafficLightLogic.h:282
MSSOTLTrafficLightLogic::decideNextPhase
virtual int decideNextPhase()
Definition: MSSOTLTrafficLightLogic.cpp:426
MSSOTLTrafficLightLogic::setToATargetPhase
void setToATargetPhase()
Definition: MSSOTLTrafficLightLogic.cpp:108
MSSOTLTrafficLightLogic::getDecayConstant
double getDecayConstant()
Definition: MSSOTLTrafficLightLogic.h:286
MSSOTLTrafficLightLogic::checkPhases
void checkPhases()
Definition: MSSOTLTrafficLightLogic.cpp:88
MSSOTLTrafficLightLogic::sensorsSelfBuilt
bool sensorsSelfBuilt
Definition: MSSOTLTrafficLightLogic.h:213
MSSOTLTrafficLightLogic::MSSOTLTrafficLightLogic
MSSOTLTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const TrafficLightType logicType, const Phases &phases, int step, SUMOTime delay, const std::map< std::string, std::string > &parameters)
Constructor without sensors passed.
Definition: MSSOTLTrafficLightLogic.cpp:32
MSSOTLTrafficLightLogic::getPhaseIndexWithMaxCTS
int getPhaseIndexWithMaxCTS()
Definition: MSSOTLTrafficLightLogic.cpp:369
MSSOTLE2Sensors.h
StringUtils.h
StringUtils::toInt
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...
Definition: StringUtils.cpp:278
MSSOTLE2Sensors
Definition: MSSOTLE2Sensors.h:32
MSSOTLTrafficLightLogic::countVehicles
int countVehicles(MSPhaseDefinition phase)
Definition: MSSOTLTrafficLightLogic.cpp:264
MSSOTLTrafficLightLogic::targetPhasesCTS
std::map< int, SUMOTime > targetPhasesCTS
Definition: MSSOTLTrafficLightLogic.h:216
MSSOTLTrafficLightLogic::m_pushButtons
PhasePushButtons m_pushButtons
Definition: MSSOTLTrafficLightLogic.h:117
MSSOTLTrafficLightLogic::PhasePushButtons
std::map< const std::string, std::vector< MSPushButton * > > PhasePushButtons
Definition: MSSOTLTrafficLightLogic.h:116
MSSOTLSensors
Definition: MSSOTLSensors.h:32
MSSOTLTrafficLightLogic::targetPhasesLastSelection
std::map< int, int > targetPhasesLastSelection
Definition: MSSOTLTrafficLightLogic.h:223
config.h
SwarmDebug.h
RandHelper.h
MSTLLogicControl
A class that stores and controls tls and switching of their programs.
Definition: MSTLLogicControl.h:59
MSSOTLTrafficLightLogic::decayThreshold
double decayThreshold
Definition: MSSOTLTrafficLightLogic.h:237
MSSOTLTrafficLightLogic::lastCheckForTargetPhase
std::map< int, SUMOTime > lastCheckForTargetPhase
Definition: MSSOTLTrafficLightLogic.h:220
MSPhaseDefinition
The definition of a single phase of a tls logic.
Definition: MSPhaseDefinition.h:51
MSSOTLTrafficLightLogic::logStatus
void logStatus()
Definition: MSSOTLTrafficLightLogic.cpp:83
MSSOTLTrafficLightLogic::init
void init(NLDetectorBuilder &nb)
Initialises the tls with sensors on incoming and outgoing lanes Sensors are built in the simulation a...
Definition: MSSOTLTrafficLightLogic.cpp:121
MSSOTLTrafficLightLogic::setupCTS
void setupCTS()
Definition: MSSOTLTrafficLightLogic.cpp:97
NLDetectorBuilder
Builds detectors for microsim.
Definition: NLDetectorBuilder.h:55
MSSOTLTrafficLightLogic::getCurrentPhaseElapsed
SUMOTime getCurrentPhaseElapsed()
Definition: MSSOTLTrafficLightLogic.cpp:358
MSPhasedTrafficLightLogic
A fixed traffic light logic.
Definition: MSPhasedTrafficLightLogic.h:47