SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSTrafficLightLogic.h
Go to the documentation of this file.
1 /****************************************************************************/
11 // The parent class for traffic light logics
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
14 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 #ifndef MSTrafficLightLogic_h
25 #define MSTrafficLightLogic_h
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #include <map>
38 #include <string>
39 #include <bitset>
40 #include <utils/common/Command.h>
43 #include <microsim/MSLink.h>
44 #include "MSPhaseDefinition.h"
45 
46 
47 // ===========================================================================
48 // class declarations
49 // ===========================================================================
50 class MSNet;
51 class MSLink;
52 class MSTLLogicControl;
53 class NLDetectorBuilder;
54 
55 
56 // ===========================================================================
57 // class definitions
58 // ===========================================================================
63 class MSTrafficLightLogic : public Named, public Parameterised {
64 public:
67 
69  typedef std::vector<MSPhaseDefinition*> Phases;
70 
72  typedef std::vector<MSLink*> LinkVector;
73 
75  typedef std::vector<LinkVector> LinkVectorVector;
76 
78  typedef std::vector<MSLane*> LaneVector;
79 
81  typedef std::vector<LaneVector> LaneVectorVector;
83 
84 
85 public:
93  const std::string& id,
94  const std::string& programID,
95  SUMOTime delay,
96  const std::map<std::string, std::string>& parameters);
97 
98 
104  virtual void init(NLDetectorBuilder& nb);
105 
106 
108  virtual ~MSTrafficLightLogic();
109 
110 
111 
114 
120  void addLink(MSLink* link, MSLane* lane, unsigned int pos);
121 
122 
130  virtual void adaptLinkInformationFrom(const MSTrafficLightLogic& logic);
131 
132 
136  std::map<MSLink*, LinkState> collectLinkStates() const;
137 
138 
142  void resetLinkStates(const std::map<MSLink*, LinkState>& vals) const;
144 
145 
146 
149 
154  virtual SUMOTime trySwitch(bool isActive) = 0;
155 
156 
163  bool setTrafficLightSignals(SUMOTime t) const;
165 
166 
167 
170 
174  const std::string& getProgramID() const {
175  return myProgramID;
176  }
177 
178 
183  return myLanes;
184  }
185 
186 
191  const LaneVector& getLanesAt(unsigned int i) const {
192  return myLanes[i];
193  }
194 
195 
199  const LinkVectorVector& getLinks() const {
200  return myLinks;
201  }
202 
203 
208  const LinkVector& getLinksAt(unsigned int i) const {
209  return myLinks[i];
210  }
211 
212 
217  int getLinkIndex(const MSLink* const link) const;
218 
219 
223  virtual unsigned int getPhaseNumber() const = 0;
224 
225 
229  virtual const Phases& getPhases() const = 0;
230 
231 
236  virtual const MSPhaseDefinition& getPhase(unsigned int givenstep) const = 0;
238 
239 
240 
243 
247  virtual unsigned int getCurrentPhaseIndex() const = 0;
248 
249 
253  virtual const MSPhaseDefinition& getCurrentPhaseDef() const = 0;
254 
255 
260  return myDefaultCycleTime;
261  }
262 
263 
269  SUMOTime getNextSwitchTime() const;
271 
272 
273 
276 
280  virtual SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const = 0;
281 
282 
287  virtual SUMOTime getOffsetFromIndex(unsigned int index) const = 0;
288 
289 
294  virtual unsigned int getIndexFromOffset(SUMOTime offset) const = 0;
296 
297 
298 
301 
305  void addOverridingDuration(SUMOTime duration);
306 
307 
312 
313 
320  virtual void changeStepAndDuration(MSTLLogicControl& tlcontrol,
321  SUMOTime simStep, unsigned int step, SUMOTime stepDuration) = 0;
322 
324 
325 
326 protected:
331  class SwitchCommand : public Command {
332  public:
338  SwitchCommand(MSTLLogicControl& tlcontrol,
339  MSTrafficLightLogic* tlLogic,
340  SUMOTime nextSwitch);
341 
343  ~SwitchCommand();
344 
349  SUMOTime execute(SUMOTime currentTime);
350 
351 
355  void deschedule(MSTrafficLightLogic* tlLogic);
356 
357 
362  return myAssumedNextSwitch;
363  }
364 
365 
366  private:
369 
372 
375 
377  bool myAmValid;
378 
379  private:
382 
385 
386  };
387 
388 protected:
390  std::string myProgramID;
391 
394 
397 
399  std::vector<SUMOTime> myOverridingTimes;
400 
403 
406 
409 
410 
411 private:
414 
417 
418 };
419 
420 
421 #endif
422 
423 /****************************************************************************/
424