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.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
22 // A fixed traffic light logic
23 /****************************************************************************/
24 #pragma once
25 #include <config.h>
26 
27 #include <utility>
28 #include <vector>
29 #include <bitset>
30 #include "MSTrafficLightLogic.h"
31 
32 
33 // ===========================================================================
34 // class declarations
35 // ===========================================================================
36 class MSNet;
37 
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
53 public:
67  const std::string& id, const std::string& programID,
68  const SUMOTime offset,
69  const TrafficLightType logicType,
70  const Phases& phases, int step, SUMOTime delay,
71  const Parameterised::Map& parameters);
72 
73 
76 
79 
84  virtual SUMOTime trySwitch() override;
86 
87 
88 
91 
96  int getPhaseNumber() const override;
97 
98 
103  const Phases& getPhases() const override;
104 
105 
110  Phases& getPhases();
111 
112 
118  const MSPhaseDefinition& getPhase(int givenstep) const override;
120 
121 
124 
129  int getCurrentPhaseIndex() const override;
130 
131 
136  const MSPhaseDefinition& getCurrentPhaseDef() const override;
138 
139 
140 
143 
148  SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const override;
149 
150 
156  SUMOTime getOffsetFromIndex(int index) const override;
157 
158 
164  int getIndexFromOffset(SUMOTime offset) const override;
166 
167 
168 
171 
179  virtual void changeStepAndDuration(MSTLLogicControl& tlcontrol, SUMOTime simStep,
180  int step, SUMOTime stepDuration) override;
181 
184  void setPhases(const Phases& phases, int index);
186 
189  virtual void saveState(OutputDevice& out) const override;
190 
191  virtual SUMOTime mapTimeInCycle(SUMOTime t) const override;
192 
194  virtual const std::string getParameter(const std::string& key, const std::string defaultValue = "") const override;
195 
197  virtual void setParameter(const std::string& key, const std::string& value) override;
198 
199 protected:
200 
202  SUMOTime getEarliest(SUMOTime prevStart) const;
203 
205  SUMOTime getLatest() const;
206 
207 
208 protected:
211 
213  int myStep;
214 
216  //compared to absolute simulation time or timeInCycle
218 
219 private:
221  void deletePhases();
222 
223 };
long long int SUMOTime
Definition: GUI.h:35
TrafficLightType
The simulated network and simulation perfomer.
Definition: MSNet.h:89
The definition of a single phase of a tls logic.
A fixed traffic light logic.
SUMOTime getLatest() const
the maximum duration for keeping the current phase when considering 'latestEnd'
int getIndexFromOffset(SUMOTime offset) const override
Returns the step (the phasenumber) of a given position of the cycle.
virtual void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration) override
Changes the current phase and her duration.
Phases myPhases
The list of phases this logic uses.
virtual void saveState(OutputDevice &out) const override
Saves the current tls states into the given stream.
const MSPhaseDefinition & getPhase(int givenstep) const override
Returns the definition of the phase from the given position within the plan.
SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const override
Returns the index of the logic at the given simulation step.
SUMOTime getOffsetFromIndex(int index) const override
Returns the position (start of a phase during a cycle) from of a given step.
int getPhaseNumber() const override
Returns the number of phases.
SUMOTime getEarliest(SUMOTime prevStart) const
the minimum duration for keeping the current phase when considering 'earliestEnd'
void setPhases(const Phases &phases, int index)
Replaces the phases and set the phase index.
MSSimpleTrafficLightLogic(MSTLLogicControl &tlcontrol, const std::string &id, const std::string &programID, const SUMOTime offset, const TrafficLightType logicType, const Phases &phases, int step, SUMOTime delay, const Parameterised::Map &parameters)
Constructor.
virtual SUMOTime mapTimeInCycle(SUMOTime t) const override
map the given time into the current cycle
bool myCoordinated
whether coordination parameters earliestEnd, latestEnd are
int getCurrentPhaseIndex() const override
Returns the current index within the program.
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const override
gets a parameter
void deletePhases()
frees memory responsibilities
const Phases & getPhases() const override
Returns the phases of this tls program.
virtual void setParameter(const std::string &key, const std::string &value) override
Sets a parameter and updates internal constants.
virtual SUMOTime trySwitch() override
Switches to the next phase.
const MSPhaseDefinition & getCurrentPhaseDef() const override
Returns the definition of the current phase.
A class that stores and controls tls and switching of their programs.
The parent class for traffic light logics.
std::vector< MSPhaseDefinition * > Phases
Definition of a list of phases, being the junction logic.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45