SUMO - Simulation of Urban MObility
MSTLLogicControl.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // A class that stores and controls tls and switching of their programs
22 /****************************************************************************/
23 #ifndef MSTLLogicControl_h
24 #define MSTLLogicControl_h
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <vector>
37 #include <map>
39 #include <utils/common/Command.h>
40 
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
46 class MSLink;
47 class MSLane;
48 class MSPhaseDefinition;
49 
50 
51 // ===========================================================================
52 // class definitions
53 // ===========================================================================
67 public:
73  public:
75  virtual ~OnSwitchAction() {};
76 
77 
80  virtual void execute() = 0;
81 
82  };
83 
84 
85 
93  public:
96 
97 
100 
101 
108  bool checkOriginalTLS() const;
109 
110 
118  bool addLogic(const std::string& programID, MSTrafficLightLogic* logic, bool netWasLoaded,
119  bool isNewDefault = true);
120 
121 
122 
123  MSTrafficLightLogic* getLogic(const std::string& programID) const;
124  void addSwitchCommand(OnSwitchAction* c);
125  std::vector<MSTrafficLightLogic*> getAllLogics() const;
126  void saveInitialStates();
127  bool isActive(const MSTrafficLightLogic* tl) const;
129  void switchTo(MSTLLogicControl& tlc, const std::string& programID);
130 
131  /* @brief get logic by programID. For the special case "off"
132  * instantiate an MSOffTrafficLightLogic */
133  MSTrafficLightLogic* getLogicInstantiatingOff(MSTLLogicControl& tlc,
134  const std::string& programID);
135 
136  /* @brief sets the state to the given string get for the special program "online"
137  * this program is instantiated only once */
138  void setStateInstantiatingOnline(MSTLLogicControl& tlc,
139  const std::string& state);
140 
141 
142  void executeOnSwitchActions() const;
143  void addLink(MSLink* link, MSLane* lane, int pos);
144 
145 
146  private:
149 
151  std::map<std::string, MSTrafficLightLogic*> myVariants;
152 
154  std::map<MSLink*, LinkState> myOriginalLinkStates;
155 
157  std::vector<OnSwitchAction*> mySwitchActions;
158 
159 
160  private:
163 
166 
167 
168  };
169 
170 
171 
174 
175 
178 
179 
197  bool closeNetworkReading();
198 
199 
206  void setTrafficLightSignals(SUMOTime t) const;
207 
208 
214  std::vector<MSTrafficLightLogic*> getAllLogics() const;
215 
216 
223  TLSLogicVariants& get(const std::string& id) const;
224 
225 
232  MSTrafficLightLogic* get(const std::string& id, const std::string& programID) const;
233 
234 
240  MSTrafficLightLogic* getActive(const std::string& id) const;
241 
242 
248  std::vector<std::string> getAllTLIds() const;
249 
250 
272  bool add(const std::string& id, const std::string& programID,
273  MSTrafficLightLogic* logic, bool newDefault = true);
274 
275 
276 
281  bool knows(const std::string& id) const;
282 
283 
288  bool isActive(const MSTrafficLightLogic* tl) const;
289 
290 
299  void switchTo(const std::string& id, const std::string& programID);
300 
301 
302 
305 
314  void addWAUT(SUMOTime refTime, const std::string& id,
315  const std::string& startProg);
316 
317 
326  void addWAUTSwitch(const std::string& wautid, SUMOTime when,
327  const std::string& to);
328 
329 
341  void addWAUTJunction(const std::string& wautid, const std::string& tls,
342  const std::string& proc, bool synchron);
343 
344 
355  void closeWAUT(const std::string& wautid);
357 
358 
359 
364  void check2Switch(SUMOTime step);
365 
366 
374  std::pair<SUMOTime, MSPhaseDefinition> getPhaseDef(const std::string& tlid) const;
375 
377  void switchOffAll();
378 
379 
380 
381 protected:
389  class SwitchInitCommand : public Command {
390  public:
396  SwitchInitCommand(MSTLLogicControl& p, const std::string& wautid, int index)
397  : myParent(p), myWAUTID(wautid), myIndex(index) { }
398 
399 
402 
403 
404 
407 
423  return myParent.initWautSwitch(*this);
424  }
426 
427 
428 
432  const std::string& getWAUTID() const {
433  return myWAUTID;
434  }
435 
436 
440  int& getIndex() {
441  return myIndex;
442  }
443 
444 
445  protected:
448 
450  std::string myWAUTID;
451 
453  int myIndex;
454 
455 
456  private:
459 
462 
463  };
464 
465 
466 
467 public:
475 
476 
477 protected:
481  struct WAUTSwitch {
485  std::string to;
486  };
487 
488 
492  struct WAUTJunction {
494  std::string junction;
496  std::string procedure;
498  bool synchron;
499  };
500 
501 
505  struct WAUT {
507  std::string id;
509  std::string startProg;
513  std::vector<WAUTSwitch> switches;
515  std::vector<WAUTJunction> junctions;
516  };
517 
518 
523  public:
533  bool synchron)
534  : myFrom(from), myTo(to), mySwitchSynchron(synchron), myWAUT(waut), myControl(control) { }
535 
536 
538  virtual ~WAUTSwitchProcedure() { }
539 
540 
545  virtual bool trySwitch(SUMOTime step) = 0;
546 
547 
548  protected:
559  bool isPosAtGSP(SUMOTime currentTime, const MSTrafficLightLogic& logic);
560 
561 
567  SUMOTime getDiffToStartOfPhase(MSTrafficLightLogic& logic, SUMOTime toTime);
568 
569 
575  void switchToPos(SUMOTime simStep, MSTrafficLightLogic& logic, SUMOTime toTime);
576 
577 
585  int getGSPValue(const MSTrafficLightLogic& logic) const;
586 
587 
588  protected:
591 
594 
597 
600 
603 
604 
605  private:
608 
611 
612  };
613 
614 
620  public:
630  bool synchron);
631 
632 
635 
636 
641  bool trySwitch(SUMOTime step);
642 
643 
644  private:
647 
650 
651  };
652 
653 
654 
660  public:
670  bool synchron);
671 
674 
675 
680  bool trySwitch(SUMOTime step);
681 
682 
683  protected:
686  void adaptLogic(SUMOTime step);
687 
688 
689  private:
692 
695 
696  };
697 
698 
704  public:
714  bool synchron);
715 
716 
719 
720 
725  bool trySwitch(SUMOTime step);
726 
727 
728  protected:
734  void adaptLogic(SUMOTime step);
735 
736 
742  void stretchLogic(SUMOTime step, SUMOTime startPos, SUMOTime allStretchTime);
743 
744 
750  void cutLogic(SUMOTime step, SUMOTime startPos, SUMOTime allCutTime);
751 
752 
753  protected:
759  double begin;
761  double end;
763  double fac;
764 
765  };
766 
767 
772  int getStretchAreaNo(MSTrafficLightLogic* from) const;
773 
774 
782  StretchBereichDef getStretchBereichDef(MSTrafficLightLogic* from, int index) const;
783 
784 
785  private:
788 
791 
792  };
793 
794 
801  std::string junction;
808  };
809 
810 
812  std::map<std::string, WAUT*> myWAUTs;
813 
815  std::vector<WAUTSwitchProcess> myCurrentlySwitched;
816 
818  std::map<std::string, TLSLogicVariants*> myLogics;
819 
822 
823 
824 private:
827 
830 
831 };
832 
833 
834 #endif
835 
836 /****************************************************************************/
837 
double end
The end of a stretch/cut area (time, in s)
bool add(const std::string &id, const std::string &programID, MSTrafficLightLogic *logic, bool newDefault=true)
Adds a tls program to the container.
void switchOffAll()
switch all logic variants to &#39;off&#39;
std::map< MSLink *, LinkState > myOriginalLinkStates
Originally loaded link states.
int & getIndex()
Returns a reference to the index.
std::map< std::string, TLSLogicVariants * > myLogics
A map from ids to the corresponding variants.
Storage for all programs of a single tls.
double fac
The weight factor of a stretch/cut area.
Base class for things to execute if a tls switches to a new phase.
void switchTo(const std::string &id, const std::string &programID)
Switches the named (id) tls to the named (programID) program.
std::map< std::string, MSTrafficLightLogic * > myVariants
A map of subkeys to programs.
SwitchInitCommand(MSTLLogicControl &p, const std::string &wautid, int index)
Constructor.
~MSTLLogicControl()
Destructor.
std::string myWAUTID
The id of the WAUT that shall switch.
bool isActive(const MSTrafficLightLogic *tl) const
Returns whether the given tls program is the currently active for his tls.
double begin
The begin of a stretch/cut area (time, in s)
std::string junction
The id of the junction to switch.
std::string procedure
The procedure to switch the junction with.
MSTLLogicControl & myParent
The control to call.
virtual ~OnSwitchAction()
Destructor.
MSTrafficLightLogic * myTo
The program to switch the tls to.
virtual ~WAUTSwitchProcedure()
Destructor.
MSTLLogicControl()
Constructor.
Base (microsim) event class.
Definition: Command.h:60
WAUT & myWAUT
The WAUT responsible for switching.
void closeWAUT(const std::string &wautid)
Closes loading of a WAUT.
SUMOTime initWautSwitch(SwitchInitCommand &cmd)
Initialises switching a WAUT.
bool myNetWasLoaded
Information whether the net was completely loaded.
Storage for a junction assigned to a WAUT.
A class that stores and controls tls and switching of their programs.
bool mySwitchSynchron
Information whether to switch synchron (?)
MSTLLogicControl & myControl
The control the logic belongs to.
std::pair< SUMOTime, MSPhaseDefinition > getPhaseDef(const std::string &tlid) const
return the complete phase definition for a named traffic lights logic
MSTLLogicControl & operator=(const MSTLLogicControl &)
Invalidated assignment operator.
WAUTSwitchProcedure * proc
The used procedure.
WAUTSwitchProcedure(MSTLLogicControl &control, WAUT &waut, MSTrafficLightLogic *from, MSTrafficLightLogic *to, bool synchron)
Constructor.
MSTrafficLightLogic * getActive(const std::string &id) const
Returns the active program of a named tls.
This class simply switches to the next program.
bool synchron
Information whether this junction shall be switched synchron.
MSTrafficLightLogic * to
The program to switch the tls to.
This class switches using the Stretch algorithm.
void check2Switch(SUMOTime step)
Checks whether any WAUT is trying to switch a tls into another program.
int myIndex
The current index within the WAUT switch table.
SUMOTime when
The time the WAUT shall switch the TLS.
std::vector< OnSwitchAction * > mySwitchActions
The list of actions/commands to execute on switch.
std::string startProg
The name of the start program.
void addWAUTJunction(const std::string &wautid, const std::string &tls, const std::string &proc, bool synchron)
Adds a tls to the list of tls to be switched by the named WAUT.
std::vector< WAUTJunction > junctions
The list of switches assigned to the WAUT.
bool knows(const std::string &id) const
Returns the information whether the named tls is stored.
std::vector< WAUTSwitchProcess > myCurrentlySwitched
A list of currently running switching procedures.
bool closeNetworkReading()
Lets MSTLLogicControl know that the network has been loaded.
An initialised switch process.
std::vector< WAUTSwitch > switches
The list of switches to be done by the WAUT.
virtual void execute()=0
Executes the action.
This event-class is used to initialise a WAUT switch at a certain time.
void addWAUT(SUMOTime refTime, const std::string &id, const std::string &startProg)
Adds a WAUT definition.
This class switches using the GSP algorithm.
SUMOTime refTime
The reference time (offset to the switch times)
This is the abstract base class for switching from one tls program to another.
const std::string & getWAUTID() const
Returns the WAUT-id.
std::string id
The id of the WAUT.
std::map< std::string, WAUT * > myWAUTs
A map of ids to corresponding WAUTs.
The parent class for traffic light logics.
Storage for a WAUTs switch point.
void addWAUTSwitch(const std::string &wautid, SUMOTime when, const std::string &to)
Adds a WAUT switch step to a previously built WAUT.
std::string to
The program name the WAUT shall switch the TLS to.
long long int SUMOTime
Definition: TraCIDefs.h:51
MSTrafficLightLogic * from
The current program of the tls.
std::vector< std::string > getAllTLIds() const
void setTrafficLightSignals(SUMOTime t) const
Lets all running (current) tls programs apply their current signal states to links they control...
MSTrafficLightLogic * myFrom
The current program of the tls to switch.
The definition of a single phase of a tls logic.
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
SUMOTime execute(SUMOTime)
Begins a WAUT switch by executing the command.
MSTrafficLightLogic * myCurrentProgram
The currently used program.
std::vector< MSTrafficLightLogic * > getAllLogics() const
Returns a vector which contains all logics.
std::string junction
The junction name.
A WAUT definition.