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-2020 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:
66  const std::string& id, const std::string& programID,
67  const TrafficLightType logicType,
68  const Phases& phases, int step, SUMOTime delay,
69  const std::map<std::string, std::string>& parameters);
70 
71 
74 
77 
82  virtual SUMOTime trySwitch();
84 
85 
86 
89 
94  int getPhaseNumber() const;
95 
96 
101  const Phases& getPhases() const;
102 
103 
108  Phases& getPhases();
109 
110 
116  const MSPhaseDefinition& getPhase(int givenstep) const;
117 
121  const std::string getLogicType() const {
122  return "simpleTrafficLightLogic";
123  }
125 
126 
127 
130 
135  int getCurrentPhaseIndex() const;
136 
137 
142  const MSPhaseDefinition& getCurrentPhaseDef() const;
144 
145 
146 
149 
154  SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const;
155 
156 
162  SUMOTime getOffsetFromIndex(int index) const;
163 
164 
170  int getIndexFromOffset(SUMOTime offset) const;
172 
173 
174 
177 
185  void changeStepAndDuration(MSTLLogicControl& tlcontrol, SUMOTime simStep,
186  int step, SUMOTime stepDuration);
187 
190  void setPhases(const Phases& phases, int index);
192 
193 
194 protected:
197 
199  int myStep;
200 
201 
202 private:
204  void deletePhases();
205 
206 };
long long int SUMOTime
Definition: SUMOTime.h:31
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.
Phases myPhases
The list of phases this logic uses.
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.
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.
void deletePhases()
frees memory responsibilities
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.