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 // ===========================================================================
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 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  virtual void changeStepAndDuration(MSTLLogicControl& tlcontrol, SUMOTime simStep,
188  int step, SUMOTime stepDuration);
189 
192  void setPhases(const Phases& phases, int index);
194 
197  virtual void saveState(OutputDevice& /*out*/) const;
198 
199  virtual SUMOTime mapTimeInCycle(SUMOTime t) const;
200 
201 protected:
202 
204  SUMOTime getEarliest(SUMOTime prevStart) const;
205 
207  SUMOTime getLatest() const;
208 
209 
210 protected:
213 
215  int myStep;
216 
218  //compared to absolute simulation time or timeInCycle
220 
221 private:
223  void deletePhases();
224 
225 };
long long int SUMOTime
Definition: SUMOTime.h:32
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 duratin for keeping the current phase when considering 'latestEnd'
Phases myPhases
The list of phases this logic uses.
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 std::map< std::string, std::string > &parameters)
Constructor.
virtual void saveState(OutputDevice &) const
Saves the current tls states into the given stream.
virtual SUMOTime mapTimeInCycle(SUMOTime t) const
map the given time into the current cycle
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.
int getIndexFromOffset(SUMOTime offset) const
Returns the step (the phasenumber) of a given position of the cycle.
int getPhaseNumber() const
Returns the number of phases.
int getCurrentPhaseIndex() const
Returns the current index within the program.
SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const
Returns the index of the logic at the given simulation step.
SUMOTime getOffsetFromIndex(int index) const
Returns the position (start of a phase during a cycle) from of a given step.
const MSPhaseDefinition & getCurrentPhaseDef() const
Returns the definition of the current phase.
const MSPhaseDefinition & getPhase(int givenstep) const
Returns the definition of the phase from the given position within the plan.
const Phases & getPhases() const
Returns the phases of this tls program.
bool myCoordinated
whether coordination parameters earliestEnd, latestEnd are
void deletePhases()
frees memory responsibilities
virtual void changeStepAndDuration(MSTLLogicControl &tlcontrol, SUMOTime simStep, int step, SUMOTime stepDuration)
Changes the current phase and her duration.
const std::string getLogicType() const
Returns the type of the logic as a string.
virtual SUMOTime trySwitch()
Switches to the next 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