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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A SUMO-compliant built logic for a traffic light
20 /****************************************************************************/
21 #ifndef NBTrafficLightLogic_h
22 #define NBTrafficLightLogic_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
35 #include <string>
36 #include <bitset>
37 #include <utility>
38 #include <set>
39 #include "NBConnectionDefs.h"
40 #include <utils/common/SUMOTime.h>
41 #include <utils/common/Named.h>
43 
44 
45 // ===========================================================================
46 // class declarations
47 // ===========================================================================
48 class OutputDevice;
49 
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
58 class NBTrafficLightLogic : public Named, public Parameterised {
59 public:
65  public:
70 
72  std::string state;
73 
78  PhaseDefinition(SUMOTime durationArg, const std::string& stateArg, SUMOTime minDurArg, SUMOTime maxDurArg) :
79  duration(durationArg),
80  minDur(minDurArg),
81  maxDur(maxDurArg),
82  state(stateArg) { }
83 
86 
91  bool operator!=(const PhaseDefinition& pd) const {
92  return pd.duration != duration || pd.state != state;
93  }
94 
95  };
96 
97 
105  NBTrafficLightLogic(const std::string& id, const std::string& subid, int noLinks,
106  SUMOTime offset = 0, TrafficLightType type = TLTYPE_STATIC);
107 
108 
113 
114 
117 
118 
129  void addStep(SUMOTime duration, const std::string& state, int index = -1);
130  void addStep(SUMOTime duration, const std::string& state, SUMOTime minDur, SUMOTime maxDur, int index = -1);
131 
132 
138  void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState);
139 
144  void setPhaseDuration(int phaseIndex, SUMOTime duration);
145  void setPhaseMinDuration(int phaseIndex, SUMOTime duration);
146  void setPhaseMaxDuration(int phaseIndex, SUMOTime duration);
147 
148  /* @brief deletes the phase at the given index
149  * @note thhrows InvalidArgument on out-of range index
150  */
151  void deletePhase(int index);
152 
153  /* @brief changes state size either by cutting of at the end or by adding
154  * new states at the end
155  */
156  void setStateLength(int numLinks, LinkState fill = LINKSTATE_TL_RED);
157 
158  /* @brief deletes all phases and reset the expect number of links
159  */
160  void resetPhases();
161 
166  void closeBuilding(bool checkVarDurations = true);
167 
168 
172  SUMOTime getDuration() const;
173 
174 
178  void setOffset(SUMOTime offset) {
179  myOffset = offset;
180  }
181 
182 
186  const std::string& getProgramID() const {
187  return mySubID;
188  };
189 
190 
194  const std::vector<PhaseDefinition>& getPhases() const {
195  return myPhases;
196  }
197 
198 
202  SUMOTime getOffset() const {
203  return myOffset;
204  };
205 
206 
209  int getNumLinks() {
210  return myNumLinks;
211  }
212 
215  return myType;
216  }
217 
220  myType = type;
221  }
222 
223 private:
226 
228  const std::string mySubID;
229 
232 
234  typedef std::vector<PhaseDefinition> PhaseDefinitionVector;
235 
237  PhaseDefinitionVector myPhases;
238 
241 
243  static const char allowedStatesInitializer[];
244  static const std::string ALLOWED_STATES;
245 
246 private:
249 
250 };
251 
252 
253 #endif
254 
255 /****************************************************************************/
256 
static const std::string ALLOWED_STATES
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:50
Base class for objects which have an id.
Definition: Named.h:54
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:70
void setStateLength(int numLinks, LinkState fill=LINKSTATE_TL_RED)
long long int SUMOTime
Definition: TraCIDefs.h:51
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
static const char allowedStatesInitializer[]
all allowed characters for phase state (see SUMOXMLDefinitions)
NBTrafficLightLogic & operator=(const NBTrafficLightLogic &s)
Invalidated assignment operator.