Eclipse SUMO - Simulation of Urban MObility
MSSimpleTrafficLightLogic.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-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 /****************************************************************************/
19 // A fixed traffic light logic
20 /****************************************************************************/
21 #ifndef MSSimpleTrafficLightLogic_h
22 #define MSSimpleTrafficLightLogic_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #include <utility>
31 #include <vector>
32 #include <bitset>
33 #include "MSTrafficLightLogic.h"
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class MSNet;
40 
41 
42 // ===========================================================================
43 // class definitions
44 // ===========================================================================
56 public:
69  const std::string& id, const std::string& programID,
70  const TrafficLightType logicType,
71  const Phases& phases, int step, SUMOTime delay,
72  const std::map<std::string, std::string>& parameters);
73 
74 
77 
80 
85  virtual SUMOTime trySwitch();
87 
88 
89 
92 
97  int getPhaseNumber() const;
98 
99 
104  const Phases& getPhases() const;
105 
106 
111  Phases& getPhases();
112 
113 
119  const MSPhaseDefinition& getPhase(int givenstep) const;
120 
124  const std::string getLogicType() const {
125  return "simpleTrafficLightLogic";
126  }
128 
129 
130 
133 
138  int getCurrentPhaseIndex() const;
139 
140 
145  const MSPhaseDefinition& getCurrentPhaseDef() const;
147 
148 
149 
152 
157  SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const;
158 
159 
165  SUMOTime getOffsetFromIndex(int index) const;
166 
167 
173  int getIndexFromOffset(SUMOTime offset) const;
175 
176 
177 
180 
188  void changeStepAndDuration(MSTLLogicControl& tlcontrol, SUMOTime simStep,
189  int step, SUMOTime stepDuration);
190 
193  void setPhases(const Phases& phases, int index);
195 
196 
197 protected:
200 
202  int myStep;
203 
204 
205 private:
207  void deletePhases();
208 
209 };
210 
211 
212 #endif
213 
214 /****************************************************************************/
215 
MSSimpleTrafficLightLogic::setPhases
void setPhases(const Phases &phases, int index)
Replaces the phases and set the phase index.
Definition: MSSimpleTrafficLightLogic.cpp:203
MSSimpleTrafficLightLogic::getPhase
const MSPhaseDefinition & getPhase(int givenstep) const
Returns the definition of the phase from the given position within the plan.
Definition: MSSimpleTrafficLightLogic.cpp:116
MSSimpleTrafficLightLogic::getPhaseNumber
int getPhaseNumber() const
Returns the number of phases.
Definition: MSSimpleTrafficLightLogic.cpp:98
MSSimpleTrafficLightLogic::getCurrentPhaseIndex
int getCurrentPhaseIndex() const
Returns the current index within the program.
Definition: MSSimpleTrafficLightLogic.cpp:124
MSSimpleTrafficLightLogic::MSSimpleTrafficLightLogic
MSSimpleTrafficLightLogic(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.
Definition: MSSimpleTrafficLightLogic.cpp:43
MSTrafficLightLogic::Phases
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
Definition: MSTrafficLightLogic.h:62
MSNet
The simulated network and simulation perfomer.
Definition: MSNet.h:92
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1192
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
MSSimpleTrafficLightLogic::getCurrentPhaseDef
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
Definition: MSSimpleTrafficLightLogic.cpp:130
MSSimpleTrafficLightLogic::getLogicType
const std::string getLogicType() const
Returns the type of the logic as a string.
Definition: MSSimpleTrafficLightLogic.h:124
MSTrafficLightLogic.h
MSSimpleTrafficLightLogic::trySwitch
virtual SUMOTime trySwitch()
Switches to the next phase.
Definition: MSSimpleTrafficLightLogic.cpp:63
MSSimpleTrafficLightLogic::getPhaseIndexAtTime
SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const
Returns the index of the logic at the given simulation step.
Definition: MSSimpleTrafficLightLogic.cpp:137
MSSimpleTrafficLightLogic
A fixed traffic light logic.
Definition: MSSimpleTrafficLightLogic.h:55
MSSimpleTrafficLightLogic::getOffsetFromIndex
SUMOTime getOffsetFromIndex(int index) const
Returns the position (start of a phase during a cycle) from of a given step.
Definition: MSSimpleTrafficLightLogic.cpp:152
MSSimpleTrafficLightLogic::getIndexFromOffset
int getIndexFromOffset(SUMOTime offset) const
Returns the step (the phasenumber) of a given position of the cycle.
Definition: MSSimpleTrafficLightLogic.cpp:166
MSTrafficLightLogic
The parent class for traffic light logics.
Definition: MSTrafficLightLogic.h:56
MSSimpleTrafficLightLogic::deletePhases
void deletePhases()
frees memory responsibilities
Definition: MSSimpleTrafficLightLogic.cpp:212
MSSimpleTrafficLightLogic::changeStepAndDuration
void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration)
Changes the current phase and her duration.
Definition: MSSimpleTrafficLightLogic.cpp:188
MSSimpleTrafficLightLogic::~MSSimpleTrafficLightLogic
~MSSimpleTrafficLightLogic()
Destructor.
Definition: MSSimpleTrafficLightLogic.cpp:56
MSSimpleTrafficLightLogic::myPhases
Phases myPhases
The list of phases this logic uses.
Definition: MSSimpleTrafficLightLogic.h:199
MSSimpleTrafficLightLogic::getPhases
const Phases & getPhases() const
Returns the phases of this tls program.
Definition: MSSimpleTrafficLightLogic.cpp:104
config.h
MSTLLogicControl
A class that stores and controls tls and switching of their programs.
Definition: MSTLLogicControl.h:60
MSPhaseDefinition
The definition of a single phase of a tls logic.
Definition: MSPhaseDefinition.h:52
MSSimpleTrafficLightLogic::myStep
int myStep
The current step.
Definition: MSSimpleTrafficLightLogic.h:202