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.sourceforge.net/
14 // Copyright (C) 2001-2013 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>
42 #include <microsim/MSLink.h>
43 #include "MSPhaseDefinition.h"
44 
45 
46 // ===========================================================================
47 // class declarations
48 // ===========================================================================
49 class MSNet;
50 class MSLink;
51 class MSTLLogicControl;
52 class NLDetectorBuilder;
53 
54 
55 // ===========================================================================
56 // class definitions
57 // ===========================================================================
63 public:
66 
68  typedef std::vector<MSPhaseDefinition*> Phases;
69 
71  typedef std::vector<MSLink*> LinkVector;
72 
74  typedef std::vector<LinkVector> LinkVectorVector;
75 
77  typedef std::vector<MSLane*> LaneVector;
78 
80  typedef std::vector<LaneVector> LaneVectorVector;
81 
82  typedef std::map<std::string, std::string> ParameterMap;
84 
85 
86 public:
94  const std::string& id,
95  const std::string& programID,
96  SUMOTime delay,
97  const ParameterMap& parameters);
98 
99 
105  virtual void init(NLDetectorBuilder& nb);
106 
107 
109  virtual ~MSTrafficLightLogic();
110 
111 
112 
115 
121  void addLink(MSLink* link, MSLane* lane, unsigned int pos);
122 
123 
131  virtual void adaptLinkInformationFrom(const MSTrafficLightLogic& logic);
132 
133 
137  std::map<MSLink*, LinkState> collectLinkStates() const;
138 
139 
143  void resetLinkStates(const std::map<MSLink*, LinkState>& vals) const;
145 
146 
147 
150 
155  virtual SUMOTime trySwitch(bool isActive) = 0;
156 
157 
164  bool setTrafficLightSignals(SUMOTime t) const;
166 
167 
168 
171 
175  const std::string& getID() const {
176  return myID;
177  }
178 
179 
183  const std::string& getProgramID() const {
184  return myProgramID;
185  }
186 
187 
191  const LaneVectorVector& getLanes() const {
192  return myLanes;
193  }
194 
195 
200  const LaneVector& getLanesAt(unsigned int i) const {
201  return myLanes[i];
202  }
203 
204 
208  const LinkVectorVector& getLinks() const {
209  return myLinks;
210  }
211 
212 
217  const LinkVector& getLinksAt(unsigned int i) const {
218  return myLinks[i];
219  }
220 
221 
226  int getLinkIndex(const MSLink* const link) const;
227 
228 
232  virtual unsigned int getPhaseNumber() const = 0;
233 
234 
238  virtual const Phases& getPhases() const = 0;
239 
240 
245  virtual const MSPhaseDefinition& getPhase(unsigned int givenstep) const = 0;
247 
248 
249 
252 
256  virtual unsigned int getCurrentPhaseIndex() const = 0;
257 
258 
262  virtual const MSPhaseDefinition& getCurrentPhaseDef() const = 0;
263 
264 
269  return myDefaultCycleTime;
270  }
271 
272 
278  SUMOTime getNextSwitchTime() const;
280 
281 
282 
285 
289  virtual SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const = 0;
290 
291 
296  virtual SUMOTime getOffsetFromIndex(unsigned int index) const = 0;
297 
298 
303  virtual unsigned int getIndexFromOffset(SUMOTime offset) const = 0;
305 
306 
307 
310 
314  void addOverridingDuration(SUMOTime duration);
315 
316 
321 
322 
329  virtual void changeStepAndDuration(MSTLLogicControl& tlcontrol,
330  SUMOTime simStep, unsigned int step, SUMOTime stepDuration) = 0;
331 
333 
334 
335 
338 
342  void setParameter(const ParameterMap& params);
343 
344 
349  std::string getParameterValue(const std::string& key) const;
351 
352 
353 protected:
358  class SwitchCommand : public Command {
359  public:
365  SwitchCommand(MSTLLogicControl& tlcontrol,
366  MSTrafficLightLogic* tlLogic,
367  SUMOTime nextSwitch);
368 
370  ~SwitchCommand();
371 
376  SUMOTime execute(SUMOTime currentTime);
377 
378 
382  void deschedule(MSTrafficLightLogic* tlLogic);
383 
384 
389  return myAssumedNextSwitch;
390  }
391 
392 
393  private:
396 
399 
402 
404  bool myAmValid;
405 
406  private:
409 
412 
413  };
414 
415 protected:
418 
420  std::string myID, myProgramID;
421 
424 
427 
429  std::vector<SUMOTime> myOverridingTimes;
430 
433 
436 
439 
440 
441 private:
444 
447 
448 };
449 
450 
451 #endif
452 
453 /****************************************************************************/
454