Eclipse SUMO - Simulation of Urban MObility
MSSOTLWaveTrafficLightLogic.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2010-2024 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 /****************************************************************************/
19 // The class for SOTL Platoon logics
20 /****************************************************************************/
21 
23 
25  MSTLLogicControl& tlcontrol, const std::string& id,
26  const std::string& programID, const Phases& phases, int step,
27  SUMOTime delay,
28  const Parameterised::Map& parameters) :
29  MSSOTLTrafficLightLogic(tlcontrol, id, programID, TrafficLightType::SOTL_WAVE, phases, step, delay,
30  parameters) {
32  "*** Intersection " + id
33  + " will run using MSSOTLWaveTrafficLightLogic ***");
34  //sets the lastDuration of every phase to the same value as the default duration of that phase
35  for (int i = 0; i < getPhaseNumber(); i++) {
36  (*myPhases[i]).lastDuration = (*myPhases[i]).duration;
37  }
38 }
39 
41  MSTLLogicControl& tlcontrol, const std::string& id,
42  const std::string& programID, const Phases& phases, int step,
43  SUMOTime delay, const Parameterised::Map& parameters,
44  MSSOTLSensors* sensors) :
45  MSSOTLTrafficLightLogic(tlcontrol, id, programID, TrafficLightType::SOTL_WAVE, phases, step, delay,
46  parameters, sensors) {
47  //sets the lastDuration of every phase to the same value as the default duration of that phase
48  for (int i = 0; i < getPhaseNumber(); i++) {
49  (*myPhases[i]).lastDuration = (*myPhases[i]).duration;
50  }
51 }
52 
54 
55  //10% of lastDuration
56  SUMOTime delta = 10 * getCurrentPhaseDef().lastDuration / 100;
57 
58  //this allows a minimum variation of +-1s
59  if (delta < 1000) {
60  delta = 1000;
61  }
62  if (getCurrentPhaseElapsed() >= getCurrentPhaseDef().minDuration) {
64  >= getCurrentPhaseDef().lastDuration - delta) {
65  if ((countVehicles() == 0) //no other vehicles approaching green lights
67  >= getCurrentPhaseDef().lastDuration + delta) //maximum value of the window surrounding lastDuration
69  >= getCurrentPhaseDef().maxDuration) //declared maximum duration has been reached
70  ) {
71 
72  (*myPhases[getCurrentPhaseIndex()]).lastDuration =
74  return true;
75  }
76  }
77  }
78  return false;
79 }
80 
82  std::string state = getCurrentPhaseDef().getState();
83  int vehicles = 0;
84  for (int i = 0; i < (int)getLaneVectors().size(); i++) {
85  if (i > 0
86  && ((getLaneVectors()[i][0]->getID()).compare(
87  getLaneVectors()[i - 1][0]->getID()) == 0)) {
88  continue;
89  }
90  if (state[i] != 'r') {
91  vehicles += getSensors()->countVehicles(getLaneVectors()[i][0]);
92  }
93 
94  }
95  return vehicles;
96 }
long long int SUMOTime
Definition: GUI.h:35
TrafficLightType
const std::string & getState() const
Returns the state within this phase.
SUMOTime lastDuration
The previous duration of the phase.
virtual int countVehicles(MSLane *lane)=0
A self-organizing traffic light logic.
MSSOTLWaveTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const Phases &phases, int step, SUMOTime delay, const Parameterised::Map &parameters)
Constructor without sensors passed.
Phases myPhases
The list of phases this logic uses.
int getPhaseNumber() const override
Returns the number of phases.
int getCurrentPhaseIndex() const override
Returns the current index within the program.
const MSPhaseDefinition & getCurrentPhaseDef() const override
Returns the definition of the current phase.
A class that stores and controls tls and switching of their programs.
const LaneVectorVector & getLaneVectors() const
Returns the list of lists of all lanes controlled by this tls.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:154
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:66
const std::string & getID() const
Returns the id.
Definition: Named.h:74
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45