SUMO - Simulation of Urban MObility
NBTrafficLightLogic.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-2018 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 /****************************************************************************/
17 // A SUMO-compliant built logic for a traffic light
18 /****************************************************************************/
19 #ifndef NBTrafficLightLogic_h
20 #define NBTrafficLightLogic_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <vector>
29 #include <string>
30 #include <bitset>
31 #include <utility>
32 #include <set>
33 #include "NBConnectionDefs.h"
34 #include <utils/common/SUMOTime.h>
35 #include <utils/common/Named.h>
37 
38 
39 // ===========================================================================
40 // class declarations
41 // ===========================================================================
42 class OutputDevice;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
52 class NBTrafficLightLogic : public Named, public Parameterised {
53 public:
59  public:
64 
66  std::string state;
67 
72  PhaseDefinition(SUMOTime durationArg, const std::string& stateArg, SUMOTime minDurArg, SUMOTime maxDurArg) :
73  duration(durationArg),
74  minDur(minDurArg),
75  maxDur(maxDurArg),
76  state(stateArg) { }
77 
80 
85  bool operator!=(const PhaseDefinition& pd) const {
86  return pd.duration != duration || pd.state != state;
87  }
88 
89  };
90 
91 
99  NBTrafficLightLogic(const std::string& id, const std::string& subid, int noLinks,
100  SUMOTime offset = 0, TrafficLightType type = TLTYPE_STATIC);
101 
102 
107 
108 
111 
112 
123  void addStep(SUMOTime duration, const std::string& state, int index = -1);
124  void addStep(SUMOTime duration, const std::string& state, SUMOTime minDur, SUMOTime maxDur, int index = -1);
125 
126 
132  void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState);
133 
138  void setPhaseDuration(int phaseIndex, SUMOTime duration);
139  void setPhaseMinDuration(int phaseIndex, SUMOTime duration);
140  void setPhaseMaxDuration(int phaseIndex, SUMOTime duration);
141 
142  /* @brief deletes the phase at the given index
143  * @note thhrows InvalidArgument on out-of range index
144  */
145  void deletePhase(int index);
146 
147  /* @brief changes state size either by cutting of at the end or by adding
148  * new states at the end
149  */
150  void setStateLength(int numLinks, LinkState fill = LINKSTATE_TL_RED);
151 
152  /* @brief deletes all phases and reset the expect number of links
153  */
154  void resetPhases();
155 
160  void closeBuilding(bool checkVarDurations = true);
161 
162 
166  SUMOTime getDuration() const;
167 
168 
172  void setOffset(SUMOTime offset) {
173  myOffset = offset;
174  }
175 
176 
180  const std::string& getProgramID() const {
181  return mySubID;
182  };
183 
184 
188  const std::vector<PhaseDefinition>& getPhases() const {
189  return myPhases;
190  }
191 
192 
196  SUMOTime getOffset() const {
197  return myOffset;
198  };
199 
200 
203  int getNumLinks() {
204  return myNumLinks;
205  }
206 
209  return myType;
210  }
211 
214  myType = type;
215  }
216 
217 private:
220 
222  const std::string mySubID;
223 
226 
228  typedef std::vector<PhaseDefinition> PhaseDefinitionVector;
229 
231  PhaseDefinitionVector myPhases;
232 
235 
236 private:
239 
240 };
241 
242 
243 #endif
244 
245 /****************************************************************************/
246 
long long int SUMOTime
Definition: SUMOTime.h:36
SUMOTime getOffset() const
Returns the offset of first switch.
void setPhaseMaxDuration(int phaseIndex, SUMOTime duration)
int getNumLinks()
Returns the number of participating links.
void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState)
Modifies the state for an existing phase (used by NETEDIT)
std::vector< PhaseDefinition > PhaseDefinitionVector
Definition of a vector of traffic light phases.
A SUMO-compliant built logic for a traffic light.
int myNumLinks
The number of participating links.
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
NBTrafficLightLogic(const std::string &id, const std::string &subid, int noLinks, SUMOTime offset=0, TrafficLightType type=TLTYPE_STATIC)
Constructor.
void setPhaseMinDuration(int phaseIndex, SUMOTime duration)
void setOffset(SUMOTime offset)
Sets the offset of this tls.
const std::string & getProgramID() const
Returns the ProgramID.
The definition of a single phase of the logic.
SUMOTime duration
The duration of the phase in s.
bool operator!=(const PhaseDefinition &pd) const
Comparison operator.
void setType(TrafficLightType type)
set the algorithm type (static etc..)
SUMOTime myOffset
The tls program&#39;s offset.
std::string state
The state definition.
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic, in MSLink and GNEInternalLane.
An upper class for objects with additional parameters.
Definition: Parameterised.h:44
Base class for objects which have an id.
Definition: Named.h:58
SUMOTime getDuration() const
Returns the duration of the complete cycle.
void closeBuilding(bool checkVarDurations=true)
closes the building process
PhaseDefinition(SUMOTime durationArg, const std::string &stateArg, SUMOTime minDurArg, SUMOTime maxDurArg)
Constructor.
TrafficLightType getType() const
get the algorithm type (static etc..)
const std::string mySubID
The tls program&#39;s subid.
~NBTrafficLightLogic()
Destructor.
The link has red light (must brake)
void setPhaseDuration(int phaseIndex, SUMOTime duration)
Modifies the duration for an existing phase (used by NETEDIT)
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
TrafficLightType myType
The algorithm type for the traffic light.
void addStep(SUMOTime duration, const std::string &state, int index=-1)
Adds a phase to the logic.
PhaseDefinitionVector myPhases
The junction logic&#39;s storage for traffic light phase list.
TrafficLightType
NBTrafficLightLogic & operator=(const NBTrafficLightLogic &s)
Invalidated assignment operator.