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.org/sumo
3 // Copyright (C) 2010-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // The class for SOTL Platoon logics
19 /****************************************************************************/
20 
22 
24  MSTLLogicControl& tlcontrol, const std::string& id,
25  const std::string& subid, const Phases& phases, int step,
26  SUMOTime delay,
27  const std::map<std::string, std::string>& parameters) throw() :
28  MSSOTLTrafficLightLogic(tlcontrol, id, subid, phases, step, delay,
29  parameters) {
31  "*** Intersection " + id
32  + " will run using MSSOTLWaveTrafficLightLogic ***");
33  //sets the lastDuration of every phase to the same value as the default duration of that phase
34  for (int i = 0; i < getPhaseNumber(); i++) {
35  (*myPhases[i]).lastDuration = (*myPhases[i]).duration;
36  }
37 }
38 
40  MSTLLogicControl& tlcontrol, const std::string& id,
41  const std::string& subid, const Phases& phases, int step,
42  SUMOTime delay, const std::map<std::string, std::string>& parameters,
43  MSSOTLSensors* sensors) throw() :
44  MSSOTLTrafficLightLogic(tlcontrol, id, subid, phases, step, delay,
45  parameters, sensors) {
46  //sets the lastDuration of every phase to the same value as the default duration of that phase
47  for (int i = 0; i < getPhaseNumber(); i++) {
48  (*myPhases[i]).lastDuration = (*myPhases[i]).duration;
49  }
50 }
51 
53 
54  //10% of lastDuration
55  SUMOTime delta = 10 * getCurrentPhaseDef().lastDuration / 100;
56 
57  //this allows a minimum variation of +-1s
58  if (delta < 1000) {
59  delta = 1000;
60  }
61  if (getCurrentPhaseElapsed() >= getCurrentPhaseDef().minDuration) {
63  >= getCurrentPhaseDef().lastDuration - delta) {
64  if ((countVehicles() == 0) //no other vehicles approaching green lights
66  >= getCurrentPhaseDef().lastDuration + delta) //maximum value of the window surrounding lastDuration
68  >= getCurrentPhaseDef().maxDuration) //declared maximum duration has been reached
69  ) {
70 
71  (*myPhases[getCurrentPhaseIndex()]).lastDuration =
73  return true;
74  }
75  }
76  }
77  return false;
78 }
79 
81  std::string state = getCurrentPhaseDef().getState();
82  int vehicles = 0;
83  for (int i = 0; i < (int)getLaneVectors().size(); i++) {
84  if (i > 0
85  && ((getLaneVectors()[i][0]->getID()).compare(
86  getLaneVectors()[i - 1][0]->getID()) == 0)) {
87  continue;
88  }
89  if (state[i] != 'r') {
90  vehicles += getSensors()->countVehicles(getLaneVectors()[i][0]);
91  }
92 
93  }
94  return vehicles;
95 }
const std::string & getState() const
Returns the state within this phase.
const LaneVectorVector & getLaneVectors() const
Returns the list of lists of all lanes controlled by this tls.
const std::string & getID() const
Returns the id.
Definition: Named.h:74
MSSOTLWaveTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &subid, const Phases &phases, int step, SUMOTime delay, const std::map< std::string, std::string > &parameters)
Constructor without sensors passed.
A class that stores and controls tls and switching of their programs.
A self-organizing traffic light logic.
Phases myPhases
The list of phases this logic uses.
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:57
virtual int countVehicles(MSLane *lane)=0
SUMOTime lastDuration
The previous duration of the phase.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
int getCurrentPhaseIndex() const
Returns the current index within the program.
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:84
long long int SUMOTime
Definition: TraCIDefs.h:51