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:
69 
71  std::string state;
72 
77  PhaseDefinition(SUMOTime durationArg, const std::string& stateArg)
78  : duration(durationArg), state(stateArg) { }
79 
82 
87  bool operator!=(const PhaseDefinition& pd) const {
88  return pd.duration != duration || pd.state != state;
89  }
90 
91  };
92 
93 
101  NBTrafficLightLogic(const std::string& id, const std::string& subid, int noLinks,
102  SUMOTime offset = 0, TrafficLightType type = TLTYPE_STATIC);
103 
104 
109 
110 
113 
114 
123  void addStep(SUMOTime duration, const std::string& state, int index = -1);
124 
125 
131  void setPhaseState(int phaseIndex, int tlIndex, LinkState linkState);
132 
137  void setPhaseDuration(int phaseIndex, SUMOTime duration);
138 
139  /* @brief deletes the phase at the given index
140  * @note thhrows InvalidArgument on out-of range index
141  */
142  void deletePhase(int index);
143 
144  /* @brief deletes all phases and reset the expect number of links
145  */
146  void resetPhases();
147 
152  void closeBuilding();
153 
154 
158  SUMOTime getDuration() const;
159 
160 
164  void setOffset(SUMOTime offset) {
165  myOffset = offset;
166  }
167 
168 
172  const std::string& getProgramID() const {
173  return mySubID;
174  };
175 
176 
180  const std::vector<PhaseDefinition>& getPhases() const {
181  return myPhases;
182  }
183 
184 
188  SUMOTime getOffset() const {
189  return myOffset;
190  };
191 
192 
195  int getNumLinks() {
196  return myNumLinks;
197  }
198 
201  return myType;
202  }
203 
206  myType = type;
207  }
208 
209 private:
212 
214  const std::string mySubID;
215 
218 
220  typedef std::vector<PhaseDefinition> PhaseDefinitionVector;
221 
223  PhaseDefinitionVector myPhases;
224 
227 
229  static const char allowedStatesInitializer[];
230  static const std::string ALLOWED_STATES;
231 
232 private:
235 
236 };
237 
238 
239 #endif
240 
241 /****************************************************************************/
242 
static const std::string ALLOWED_STATES
SUMOTime getOffset() const
Returns the offset of first switch.
int getNumLinks()
Returns the number of participating links.
void closeBuilding()
closes the building process
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 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:51
Base class for objects which have an id.
Definition: Named.h:46
SUMOTime getDuration() const
Returns the duration of the complete cycle.
TrafficLightType getType() const
get the algorithm type (static etc..)
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.
PhaseDefinition(SUMOTime durationArg, const std::string &stateArg)
Constructor.
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.