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.sourceforge.net/
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