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-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 
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