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-sim.org/
12 // Copyright (C) 2001-2014 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, unsigned 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(unsigned int phaseIndex, unsigned int tlIndex, LinkState linkState);
132 
137  void setPhaseDuration(unsigned 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(unsigned 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  unsigned int getNumLinks() {
196  return myNumLinks;
197  }
198 
201  return myType;
202  }
203 
206  myType = type;
207  }
208 
209 private:
211  unsigned int myNumLinks;
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
TrafficLightType getType() const
get the algorithm type (static etc..)
const std::string & getProgramID() const
Returns the ProgramID.
void closeBuilding()
closes the building process
std::vector< PhaseDefinition > PhaseDefinitionVector
Definition of a vector of traffic light phases.
A SUMO-compliant built logic for a traffic light.
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's offset.
void setPhaseDuration(unsigned int phaseIndex, SUMOTime duration)
Modifies the duration for an existing phase (used by NETEDIT)
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.
void setPhaseState(unsigned int phaseIndex, unsigned int tlIndex, LinkState linkState)
Modifies the state for an existing phase (used by NETEDIT)
An upper class for objects with additional parameters.
Definition: Parameterised.h:47
SUMOTime getDuration() const
Returns the duration of the complete cycle.
Base class for objects which have an id.
Definition: Named.h:45
SUMOTime getOffset() const
Returns the offset of first switch.
unsigned int myNumLinks
The number of participating links.
void deletePhase(unsigned int index)
unsigned int getNumLinks()
Returns the number of participating links.
const std::string mySubID
The tls program's subid.
~NBTrafficLightLogic()
Destructor.
int SUMOTime
Definition: SUMOTime.h:43
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
NBTrafficLightLogic(const std::string &id, const std::string &subid, unsigned int noLinks, SUMOTime offset=0, TrafficLightType type=TLTYPE_STATIC)
Constructor.
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'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.