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-2012 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;
82 
83 
84 public:
92  const std::string& id, const std::string& programID, SUMOTime delay);
93 
94 
100  virtual void init(NLDetectorBuilder& nb);
101 
102 
104  virtual ~MSTrafficLightLogic();
105 
106 
107 
110 
116  void addLink(MSLink* link, MSLane* lane, unsigned int pos);
117 
118 
126  virtual void adaptLinkInformationFrom(const MSTrafficLightLogic& logic);
127 
128 
132  std::map<MSLink*, LinkState> collectLinkStates() const;
133 
134 
138  void resetLinkStates(const std::map<MSLink*, LinkState>& vals) const;
140 
141 
142 
145 
150  virtual SUMOTime trySwitch(bool isActive) = 0;
151 
152 
159  bool setTrafficLightSignals(SUMOTime t) const;
161 
162 
163 
166 
170  const std::string& getID() const {
171  return myID;
172  }
173 
174 
178  const std::string& getProgramID() const {
179  return myProgramID;
180  }
181 
182 
186  const LaneVectorVector& getLanes() const {
187  return myLanes;
188  }
189 
190 
195  const LaneVector& getLanesAt(unsigned int i) const {
196  return myLanes[i];
197  }
198 
199 
203  const LinkVectorVector& getLinks() const {
204  return myLinks;
205  }
206 
207 
212  const LinkVector& getLinksAt(unsigned int i) const {
213  return myLinks[i];
214  }
215 
216 
221  int getLinkIndex(const MSLink* const link) const;
222 
223 
227  virtual unsigned int getPhaseNumber() const = 0;
228 
229 
233  virtual const Phases& getPhases() const = 0;
234 
235 
240  virtual const MSPhaseDefinition& getPhase(unsigned int givenstep) const = 0;
242 
243 
244 
247 
251  virtual unsigned int getCurrentPhaseIndex() const = 0;
252 
253 
257  virtual const MSPhaseDefinition& getCurrentPhaseDef() const = 0;
258 
259 
264  return myDefaultCycleTime;
265  }
266 
267 
273  SUMOTime getNextSwitchTime() const;
275 
276 
277 
280 
284  virtual SUMOTime getPhaseIndexAtTime(SUMOTime simStep) const = 0;
285 
286 
291  virtual SUMOTime getOffsetFromIndex(unsigned int index) const = 0;
292 
293 
298  virtual unsigned int getIndexFromOffset(SUMOTime offset) const = 0;
300 
301 
302 
305 
309  void addOverridingDuration(SUMOTime duration);
310 
311 
316 
317 
324  virtual void changeStepAndDuration(MSTLLogicControl& tlcontrol,
325  SUMOTime simStep, unsigned int step, SUMOTime stepDuration) = 0;
326 
328 
329 
330 
333 
337  void setParameter(const std::map<std::string, std::string>& params);
338 
339 
344  std::string getParameterValue(const std::string& key) const;
346 
347 
348 protected:
353  class SwitchCommand : public Command {
354  public:
360  SwitchCommand(MSTLLogicControl& tlcontrol,
361  MSTrafficLightLogic* tlLogic,
362  SUMOTime nextSwitch);
363 
365  ~SwitchCommand();
366 
371  SUMOTime execute(SUMOTime currentTime);
372 
373 
377  void deschedule(MSTrafficLightLogic* tlLogic);
378 
379 
384  return myAssumedNextSwitch;
385  }
386 
387 
388  private:
391 
394 
397 
399  bool myAmValid;
400 
401  private:
404 
407 
408  };
409 
410 protected:
412  std::map<std::string, std::string> myParameter;
413 
415  std::string myID, myProgramID;
416 
419 
422 
424  std::vector<SUMOTime> myOverridingTimes;
425 
428 
431 
434 
435 
436 private:
439 
442 
443 };
444 
445 
446 #endif
447 
448 /****************************************************************************/
449