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