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.org/sumo
3 // Copyright (C) 2010-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 /****************************************************************************/
15 // The class for SOTL Platoon logics
16 /****************************************************************************/
17 
19 
21  MSTLLogicControl& tlcontrol, const std::string& id,
22  const std::string& programID, const Phases& phases, int step,
23  SUMOTime delay,
24  const std::map<std::string, std::string>& parameters) :
25  MSSOTLTrafficLightLogic(tlcontrol, id, programID, TLTYPE_SOTL_WAVE, phases, step, delay,
26  parameters) {
28  "*** Intersection " + id
29  + " will run using MSSOTLWaveTrafficLightLogic ***");
30  //sets the lastDuration of every phase to the same value as the default duration of that phase
31  for (int i = 0; i < getPhaseNumber(); i++) {
32  (*myPhases[i]).lastDuration = (*myPhases[i]).duration;
33  }
34 }
35 
37  MSTLLogicControl& tlcontrol, const std::string& id,
38  const std::string& programID, const Phases& phases, int step,
39  SUMOTime delay, const std::map<std::string, std::string>& parameters,
40  MSSOTLSensors* sensors) :
41  MSSOTLTrafficLightLogic(tlcontrol, id, programID, TLTYPE_SOTL_WAVE, phases, step, delay,
42  parameters, sensors) {
43  //sets the lastDuration of every phase to the same value as the default duration of that phase
44  for (int i = 0; i < getPhaseNumber(); i++) {
45  (*myPhases[i]).lastDuration = (*myPhases[i]).duration;
46  }
47 }
48 
50 
51  //10% of lastDuration
52  SUMOTime delta = 10 * getCurrentPhaseDef().lastDuration / 100;
53 
54  //this allows a minimum variation of +-1s
55  if (delta < 1000) {
56  delta = 1000;
57  }
58  if (getCurrentPhaseElapsed() >= getCurrentPhaseDef().minDuration) {
60  >= getCurrentPhaseDef().lastDuration - delta) {
61  if ((countVehicles() == 0) //no other vehicles approaching green lights
63  >= getCurrentPhaseDef().lastDuration + delta) //maximum value of the window surrounding lastDuration
65  >= getCurrentPhaseDef().maxDuration) //declared maximum duration has been reached
66  ) {
67 
68  (*myPhases[getCurrentPhaseIndex()]).lastDuration =
70  return true;
71  }
72  }
73  }
74  return false;
75 }
76 
78  std::string state = getCurrentPhaseDef().getState();
79  int vehicles = 0;
80  for (int i = 0; i < (int)getLaneVectors().size(); i++) {
81  if (i > 0
82  && ((getLaneVectors()[i][0]->getID()).compare(
83  getLaneVectors()[i - 1][0]->getID()) == 0)) {
84  continue;
85  }
86  if (state[i] != 'r') {
87  vehicles += getSensors()->countVehicles(getLaneVectors()[i][0]);
88  }
89 
90  }
91  return vehicles;
92 }
MSSOTLTrafficLightLogic
A self-organizing traffic light logic.
Definition: MSSOTLTrafficLightLogic.h:58
MSSOTLWaveTrafficLightLogic::countVehicles
int countVehicles()
Definition: MSSOTLWaveTrafficLightLogic.cpp:77
MSPhaseDefinition::lastDuration
SUMOTime lastDuration
The previous duration of the phase.
Definition: MSPhaseDefinition.h:73
MSPhasedTrafficLightLogic::myPhases
Phases myPhases
The list of phases this logic uses.
Definition: MSPhasedTrafficLightLogic.h:175
MSSOTLWaveTrafficLightLogic::MSSOTLWaveTrafficLightLogic
MSSOTLWaveTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const Phases &phases, int step, SUMOTime delay, const std::map< std::string, std::string > &parameters)
Constructor without sensors passed.
Definition: MSSOTLWaveTrafficLightLogic.cpp:20
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
MSPhasedTrafficLightLogic::getPhaseNumber
int getPhaseNumber() const
Returns the number of phases.
Definition: MSPhasedTrafficLightLogic.cpp:106
MSSOTLWaveTrafficLightLogic::canRelease
bool canRelease()
Definition: MSSOTLWaveTrafficLightLogic.cpp:49
MsgHandler::inform
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:118
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSSOTLSensors::countVehicles
virtual int countVehicles(MSLane *lane)=0
MSSOTLTrafficLightLogic::getSensors
MSSOTLSensors * getSensors()
Definition: MSSOTLTrafficLightLogic.h:175
TLTYPE_SOTL_WAVE
Definition: SUMOXMLDefinitions.h:1206
MSSOTLWaveTrafficLightLogic.h
MSPhaseDefinition::getState
const std::string & getState() const
Returns the state within this phase.
Definition: MSPhaseDefinition.h:199
MSPhasedTrafficLightLogic::getCurrentPhaseIndex
int getCurrentPhaseIndex() const
Returns the current index within the program.
Definition: MSPhasedTrafficLightLogic.cpp:125
MSTrafficLightLogic::getLaneVectors
const LaneVectorVector & getLaneVectors() const
Returns the list of lists of all lanes controlled by this tls.
Definition: MSTrafficLightLogic.h:182
MSSOTLSensors
Definition: MSSOTLSensors.h:32
MSTLLogicControl
A class that stores and controls tls and switching of their programs.
Definition: MSTLLogicControl.h:59
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
MSSOTLTrafficLightLogic::getCurrentPhaseElapsed
SUMOTime getCurrentPhaseElapsed()
Definition: MSSOTLTrafficLightLogic.cpp:358
MsgHandler::getMessageInstance
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:55