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-2022 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// ===========================================================================
36class MSNet;
37
38
39// ===========================================================================
40// class definitions
41// ===========================================================================
53public:
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;
119
123 const std::string getLogicType() const {
124 return "simpleTrafficLightLogic";
125 }
127
128
129
132
137 int getCurrentPhaseIndex() const override;
138
139
144 const MSPhaseDefinition& getCurrentPhaseDef() const override;
146
147
148
151
156 SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const override;
157
158
164 SUMOTime getOffsetFromIndex(int index) const override;
165
166
172 int getIndexFromOffset(SUMOTime offset) const override;
174
175
176
179
187 virtual void changeStepAndDuration(MSTLLogicControl& tlcontrol, SUMOTime simStep,
188 int step, SUMOTime stepDuration) override;
189
192 void setPhases(const Phases& phases, int index);
194
197 virtual void saveState(OutputDevice& out) const override;
198
199 virtual SUMOTime mapTimeInCycle(SUMOTime t) const override;
200
202 virtual const std::string getParameter(const std::string& key, const std::string defaultValue = "") const override;
203
205 virtual void setParameter(const std::string& key, const std::string& value) override;
206
207protected:
208
210 SUMOTime getEarliest(SUMOTime prevStart) const;
211
213 SUMOTime getLatest() const;
214
215
216protected:
219
222
224 //compared to absolute simulation time or timeInCycle
226
227private:
229 void deletePhases();
230
231};
long long int SUMOTime
Definition: GUI.h:36
TrafficLightType
The simulated network and simulation perfomer.
Definition: MSNet.h:88
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 std::string getLogicType() const
Returns the type of the logic as a string.
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