SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2013 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>
43 
44 
45 // ===========================================================================
46 // class declarations
47 // ===========================================================================
48 class OutputDevice;
49 
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
58 class NBTrafficLightLogic : public Named {
59 public:
65  public:
68 
70  std::string state;
71 
76  PhaseDefinition(SUMOTime durationArg, const std::string& stateArg)
77  : duration(durationArg), state(stateArg) { }
78 
81 
86  bool operator!=(const PhaseDefinition& pd) const {
87  return pd.duration != duration || pd.state != state;
88  }
89 
90  };
91 
92 
100  NBTrafficLightLogic(const std::string& id, const std::string& subid, unsigned int noLinks,
101  SUMOTime offset = 0, TrafficLightType type = TLTYPE_STATIC);
102 
103 
108 
109 
112 
113 
122  void addStep(SUMOTime duration, const std::string& state, int index = -1);
123 
124 
130  void setPhaseState(unsigned int phaseIndex, unsigned int tlIndex, LinkState linkState);
131 
136  void setPhaseDuration(unsigned int phaseIndex, SUMOTime duration);
137 
138  /* @brief deletes the phase at the given index
139  * @note thhrows InvalidArgument on out-of range index
140  */
141  void deletePhase(unsigned int index);
142 
143  /* @brief deletes all phases and reset the expect number of links
144  */
145  void resetPhases();
146 
151  void closeBuilding();
152 
153 
157  SUMOTime getDuration() const;
158 
159 
163  void setOffset(SUMOTime offset) {
164  myOffset = offset;
165  }
166 
167 
171  const std::string& getProgramID() const {
172  return mySubID;
173  };
174 
175 
179  const std::vector<PhaseDefinition>& getPhases() const {
180  return myPhases;
181  }
182 
183 
187  SUMOTime getOffset() const {
188  return myOffset;
189  };
190 
191 
194  unsigned int getNumLinks() {
195  return myNumLinks;
196  }
197 
200  return myType;
201  }
202 
205  myType = type;
206  }
207 
208 private:
210  unsigned int myNumLinks;
211 
213  const std::string mySubID;
214 
217 
219  typedef std::vector<PhaseDefinition> PhaseDefinitionVector;
220 
223 
226 
228  static const char allowedStatesInitializer[];
229  static const std::string ALLOWED_STATES;
230 
231 private:
234 
235 };
236 
237 
238 #endif
239 
240 /****************************************************************************/
241 
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&#39;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)
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&#39;s subid.
~NBTrafficLightLogic()
Destructor.
int SUMOTime
Definition: SUMOTime.h:43
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:70
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&#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.