SUMO - Simulation of Urban MObility
NBTrafficLightLogic.h
Go to the documentation of this file.
1 /****************************************************************************/
9 // A SUMO-compliant built logic for a traffic light
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 #ifndef NBTrafficLightLogic_h
23 #define NBTrafficLightLogic_h
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <vector>
36 #include <string>
37 #include <bitset>
38 #include <utility>
39 #include <set>
40 #include "NBConnectionDefs.h"
41 #include <utils/common/SUMOTime.h>
42 #include <utils/common/Named.h>
44 
45 
46 // ===========================================================================
47 // class declarations
48 // ===========================================================================
49 class OutputDevice;
50 
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
59 class NBTrafficLightLogic : public Named, public Parameterised {
60 public:
66  public:
71 
73  std::string state;
74 
79  PhaseDefinition(SUMOTime durationArg, const std::string& stateArg, SUMOTime minDurArg, SUMOTime maxDurArg) :
80  duration(durationArg),
81  minDur(minDurArg),
82  maxDur(maxDurArg),
83  state(stateArg) { }
84 
87 
92  bool operator!=(const PhaseDefinition& pd) const {
93  return pd.duration != duration || pd.state != state;
94  }
95 
96  };
97 
98 
106  NBTrafficLightLogic(const std::string& id, const std::string& subid, int noLinks,
107  SUMOTime offset = 0, TrafficLightType type = TLTYPE_STATIC);
108 
109 
114 
115 
118 
119 
130  void addStep(SUMOTime duration, const std::string& state, int index = -1);
131  void addStep(SUMOTime duration, const std::string& state, SUMOTime minDur, SUMOTime maxDur, int index = -1);
132 
133 
139  void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState);
140 
145  void setPhaseDuration(int phaseIndex, SUMOTime duration);
146  void setPhaseMinDuration(int phaseIndex, SUMOTime duration);
147  void setPhaseMaxDuration(int phaseIndex, SUMOTime duration);
148 
149  /* @brief deletes the phase at the given index
150  * @note thhrows InvalidArgument on out-of range index
151  */
152  void deletePhase(int index);
153 
154  /* @brief deletes all phases and reset the expect number of links
155  */
156  void resetPhases();
157 
162  void closeBuilding(bool checkVarDurations = true);
163 
164 
168  SUMOTime getDuration() const;
169 
170 
174  void setOffset(SUMOTime offset) {
175  myOffset = offset;
176  }
177 
178 
182  const std::string& getProgramID() const {
183  return mySubID;
184  };
185 
186 
190  const std::vector<PhaseDefinition>& getPhases() const {
191  return myPhases;
192  }
193 
194 
198  SUMOTime getOffset() const {
199  return myOffset;
200  };
201 
202 
205  int getNumLinks() {
206  return myNumLinks;
207  }
208 
211  return myType;
212  }
213 
216  myType = type;
217  }
218 
219 private:
222 
224  const std::string mySubID;
225 
228 
230  typedef std::vector<PhaseDefinition> PhaseDefinitionVector;
231 
233  PhaseDefinitionVector myPhases;
234 
237 
239  static const char allowedStatesInitializer[];
240  static const std::string ALLOWED_STATES;
241 
242 private:
245 
246 };
247 
248 
249 #endif
250 
251 /****************************************************************************/
252 
static const std::string ALLOWED_STATES
TrafficLightType getType() const
get the algorithm type (static etc..)
const std::string & getProgramID() const
Returns the ProgramID.
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.
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.
The definition of a single phase of the logic.
SUMOTime duration
The duration of the phase in s.
void setType(TrafficLightType type)
set the algorithm type (static etc..)
const std::vector< PhaseDefinition > & getPhases() const
Returns the phases.
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:51
SUMOTime getDuration() const
Returns the duration of the complete cycle.
Base class for objects which have an id.
Definition: Named.h:46
void closeBuilding(bool checkVarDurations=true)
closes the building process
SUMOTime getOffset() const
Returns the offset of first switch.
PhaseDefinition(SUMOTime durationArg, const std::string &stateArg, SUMOTime minDurArg, SUMOTime maxDurArg)
Constructor.
const std::string mySubID
The tls program&#39;s subid.
~NBTrafficLightLogic()
Destructor.
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:71
long long int SUMOTime
Definition: TraCIDefs.h:52
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.
bool operator!=(const PhaseDefinition &pd) const
Comparison operator.