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 /****************************************************************************/
18 // A fixed traffic light logic
19 /****************************************************************************/
20 #ifndef MSSimpleTrafficLightLogic_h
21 #define MSSimpleTrafficLightLogic_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <utility>
30 #include <vector>
31 #include <bitset>
32 #include "MSTrafficLightLogic.h"
33 
34 
35 // ===========================================================================
36 // class declarations
37 // ===========================================================================
38 class MSNet;
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
55 public:
68  const std::string& id, const std::string& programID,
69  const TrafficLightType logicType,
70  const Phases& phases, int step, SUMOTime delay,
71  const std::map<std::string, std::string>& parameters);
72 
73 
76 
79 
84  virtual SUMOTime trySwitch();
86 
87 
88 
91 
96  int getPhaseNumber() const;
97 
98 
103  const Phases& getPhases() const;
104 
105 
110  Phases& getPhases();
111 
112 
118  const MSPhaseDefinition& getPhase(int givenstep) const;
119 
123  const std::string getLogicType() const {
124  return "simpleTrafficLightLogic";
125  }
127 
128 
129 
132 
137  int getCurrentPhaseIndex() const;
138 
139 
144  const MSPhaseDefinition& getCurrentPhaseDef() const;
146 
147 
148 
151 
156  SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const;
157 
158 
164  SUMOTime getOffsetFromIndex(int index) const;
165 
166 
172  int getIndexFromOffset(SUMOTime offset) const;
174 
175 
176 
179 
187  void changeStepAndDuration(MSTLLogicControl& tlcontrol, SUMOTime simStep,
188  int step, SUMOTime stepDuration);
189 
192  void setPhases(const Phases& phases, int index);
194 
195 
196 protected:
199 
201  int myStep;
202 
203 
204 private:
206  void deletePhases();
207 
208 };
209 
210 
211 #endif
212 
213 /****************************************************************************/
214 
MSSimpleTrafficLightLogic::setPhases
void setPhases(const Phases &phases, int index)
Replaces the phases and set the phase index.
Definition: MSSimpleTrafficLightLogic.cpp:202
MSSimpleTrafficLightLogic::getPhase
const MSPhaseDefinition & getPhase(int givenstep) const
Returns the definition of the phase from the given position within the plan.
Definition: MSSimpleTrafficLightLogic.cpp:115
MSSimpleTrafficLightLogic::getPhaseNumber
int getPhaseNumber() const
Returns the number of phases.
Definition: MSSimpleTrafficLightLogic.cpp:97
MSSimpleTrafficLightLogic::getCurrentPhaseIndex
int getCurrentPhaseIndex() const
Returns the current index within the program.
Definition: MSSimpleTrafficLightLogic.cpp:123
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:42
MSTrafficLightLogic::Phases
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
Definition: MSTrafficLightLogic.h:61
MSNet
The simulated network and simulation perfomer.
Definition: MSNet.h:91
TrafficLightType
TrafficLightType
Definition: SUMOXMLDefinitions.h:1197
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSSimpleTrafficLightLogic::getCurrentPhaseDef
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
Definition: MSSimpleTrafficLightLogic.cpp:129
MSSimpleTrafficLightLogic::getLogicType
const std::string getLogicType() const
Returns the type of the logic as a string.
Definition: MSSimpleTrafficLightLogic.h:123
MSTrafficLightLogic.h
MSSimpleTrafficLightLogic::trySwitch
virtual SUMOTime trySwitch()
Switches to the next phase.
Definition: MSSimpleTrafficLightLogic.cpp:62
MSSimpleTrafficLightLogic::getPhaseIndexAtTime
SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const
Returns the index of the logic at the given simulation step.
Definition: MSSimpleTrafficLightLogic.cpp:136
MSSimpleTrafficLightLogic
A fixed traffic light logic.
Definition: MSSimpleTrafficLightLogic.h:54
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:151
MSSimpleTrafficLightLogic::getIndexFromOffset
int getIndexFromOffset(SUMOTime offset) const
Returns the step (the phasenumber) of a given position of the cycle.
Definition: MSSimpleTrafficLightLogic.cpp:165
MSTrafficLightLogic
The parent class for traffic light logics.
Definition: MSTrafficLightLogic.h:55
MSSimpleTrafficLightLogic::deletePhases
void deletePhases()
frees memory responsibilities
Definition: MSSimpleTrafficLightLogic.cpp:211
MSSimpleTrafficLightLogic::changeStepAndDuration
void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration)
Changes the current phase and her duration.
Definition: MSSimpleTrafficLightLogic.cpp:187
MSSimpleTrafficLightLogic::~MSSimpleTrafficLightLogic
~MSSimpleTrafficLightLogic()
Destructor.
Definition: MSSimpleTrafficLightLogic.cpp:55
MSSimpleTrafficLightLogic::myPhases
Phases myPhases
The list of phases this logic uses.
Definition: MSSimpleTrafficLightLogic.h:198
MSSimpleTrafficLightLogic::getPhases
const Phases & getPhases() const
Returns the phases of this tls program.
Definition: MSSimpleTrafficLightLogic.cpp:103
config.h
MSTLLogicControl
A class that stores and controls tls and switching of their programs.
Definition: MSTLLogicControl.h:59
MSPhaseDefinition
The definition of a single phase of a tls logic.
Definition: MSPhaseDefinition.h:51
MSSimpleTrafficLightLogic::myStep
int myStep
The current step.
Definition: MSSimpleTrafficLightLogic.h:201