SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSTLLogicControl.h
Go to the documentation of this file.
1 /****************************************************************************/
11 // A class that stores and controls tls and switching of their programs
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2016 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 MSTLLogicControl_h
25 #define MSTLLogicControl_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 <vector>
38 #include <map>
40 #include <utils/common/Command.h>
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
47 class MSLink;
48 class MSLane;
49 class MSPhaseDefinition;
50 
51 
52 // ===========================================================================
53 // class definitions
54 // ===========================================================================
68 public:
74  public:
76  virtual ~OnSwitchAction() {};
77 
78 
81  virtual void execute() = 0;
82 
83  };
84 
85 
86 
94  public:
97 
98 
101 
102 
109  bool checkOriginalTLS() const;
110 
111 
119  bool addLogic(const std::string& programID, MSTrafficLightLogic* logic, bool netWasLoaded,
120  bool isNewDefault = true);
121 
122 
123 
124  MSTrafficLightLogic* getLogic(const std::string& programID) const;
126  std::vector<MSTrafficLightLogic*> getAllLogics() const;
127  void saveInitialStates();
128  bool isActive(const MSTrafficLightLogic* tl) const;
130  void switchTo(MSTLLogicControl& tlc, const std::string& programID);
131 
132  /* @brief get logic by programID. For the special case "off"
133  * instantiate an MSOffTrafficLightLogic */
135  const std::string& programID);
136 
137  /* @brief sets the state to the given string get for the special program "online"
138  * this program is instantiated only once */
140  const std::string& state);
141 
142 
143  void executeOnSwitchActions() const;
144  void addLink(MSLink* link, MSLane* lane, int pos);
145 
146 
147  private:
150 
152  std::map<std::string, MSTrafficLightLogic*> myVariants;
153 
155  std::map<MSLink*, LinkState> myOriginalLinkStates;
156 
158  std::vector<OnSwitchAction*> mySwitchActions;
159 
160 
161  private:
164 
167 
168 
169  };
170 
171 
172 
175 
176 
179 
180 
198  bool closeNetworkReading();
199 
200 
207  void setTrafficLightSignals(SUMOTime t) const;
208 
209 
215  std::vector<MSTrafficLightLogic*> getAllLogics() const;
216 
217 
224  TLSLogicVariants& get(const std::string& id) const;
225 
226 
233  MSTrafficLightLogic* get(const std::string& id, const std::string& programID) const;
234 
235 
241  MSTrafficLightLogic* getActive(const std::string& id) const;
242 
243 
249  std::vector<std::string> getAllTLIds() const;
250 
251 
273  bool add(const std::string& id, const std::string& programID,
274  MSTrafficLightLogic* logic, bool newDefault = true);
275 
276 
277 
282  bool knows(const std::string& id) const;
283 
284 
289  bool isActive(const MSTrafficLightLogic* tl) const;
290 
291 
300  void switchTo(const std::string& id, const std::string& programID);
301 
302 
303 
306 
315  void addWAUT(SUMOTime refTime, const std::string& id,
316  const std::string& startProg);
317 
318 
327  void addWAUTSwitch(const std::string& wautid, SUMOTime when,
328  const std::string& to);
329 
330 
342  void addWAUTJunction(const std::string& wautid, const std::string& tls,
343  const std::string& proc, bool synchron);
344 
345 
356  void closeWAUT(const std::string& wautid);
358 
359 
360 
365  void check2Switch(SUMOTime step);
366 
367 
375  std::pair<SUMOTime, MSPhaseDefinition> getPhaseDef(const std::string& tlid) const;
376 
378  void switchOffAll();
379 
380 
381 
382 protected:
390  class SwitchInitCommand : public Command {
391  public:
397  SwitchInitCommand(MSTLLogicControl& p, const std::string& wautid, int index)
398  : myParent(p), myWAUTID(wautid), myIndex(index) { }
399 
400 
403 
404 
405 
408 
424  return myParent.initWautSwitch(*this);
425  }
427 
428 
429 
433  const std::string& getWAUTID() const {
434  return myWAUTID;
435  }
436 
437 
441  int& getIndex() {
442  return myIndex;
443  }
444 
445 
446  protected:
449 
451  std::string myWAUTID;
452 
454  int myIndex;
455 
456 
457  private:
460 
463 
464  };
465 
466 
467 
468 public:
476 
477 
478 protected:
482  struct WAUTSwitch {
486  std::string to;
487  };
488 
489 
493  struct WAUTJunction {
495  std::string junction;
497  std::string procedure;
499  bool synchron;
500  };
501 
502 
506  struct WAUT {
508  std::string id;
510  std::string startProg;
514  std::vector<WAUTSwitch> switches;
516  std::vector<WAUTJunction> junctions;
517  };
518 
519 
524  public:
534  bool synchron)
535  : myFrom(from), myTo(to), mySwitchSynchron(synchron), myWAUT(waut), myControl(control) { }
536 
537 
539  virtual ~WAUTSwitchProcedure() { }
540 
541 
546  virtual bool trySwitch(SUMOTime step) = 0;
547 
548 
549  protected:
560  bool isPosAtGSP(SUMOTime currentTime, const MSTrafficLightLogic& logic);
561 
562 
569 
570 
576  void switchToPos(SUMOTime simStep, MSTrafficLightLogic& logic, SUMOTime toTime);
577 
578 
586  int getGSPValue(const MSTrafficLightLogic& logic) const;
587 
588 
589  protected:
592 
595 
598 
601 
604 
605 
606  private:
609 
612 
613  };
614 
615 
621  public:
631  bool synchron);
632 
633 
636 
637 
642  bool trySwitch(SUMOTime step);
643 
644 
645  private:
648 
651 
652  };
653 
654 
655 
661  public:
671  bool synchron);
672 
675 
676 
681  bool trySwitch(SUMOTime step);
682 
683 
684  protected:
687  void adaptLogic(SUMOTime step);
688 
689 
690  private:
693 
696 
697  };
698 
699 
705  public:
715  bool synchron);
716 
717 
720 
721 
726  bool trySwitch(SUMOTime step);
727 
728 
729  protected:
735  void adaptLogic(SUMOTime step);
736 
737 
743  void stretchLogic(SUMOTime step, SUMOTime startPos, SUMOTime allStretchTime);
744 
745 
751  void cutLogic(SUMOTime step, SUMOTime startPos, SUMOTime allCutTime);
752 
753 
754  protected:
765 
766  };
767 
768 
773  int getStretchAreaNo(MSTrafficLightLogic* from) const;
774 
775 
784 
785 
786  private:
789 
792 
793  };
794 
795 
802  std::string junction;
809  };
810 
811 
813  std::map<std::string, WAUT*> myWAUTs;
814 
816  std::vector<WAUTSwitchProcess> myCurrentlySwitched;
817 
819  std::map<std::string, TLSLogicVariants*> myLogics;
820 
823 
824 
825 private:
828 
831 
832 };
833 
834 
835 #endif
836 
837 /****************************************************************************/
838 
bool checkOriginalTLS() const
Verifies traffic lights loaded from the network.
bool trySwitch(SUMOTime step)
Determines whether a switch is possible.
bool add(const std::string &id, const std::string &programID, MSTrafficLightLogic *logic, bool newDefault=true)
Adds a tls program to the container.
bool isActive(const MSTrafficLightLogic *tl) const
Returns whether the given tls program is the currently active for his tls.
void cutLogic(SUMOTime step, SUMOTime startPos, SUMOTime allCutTime)
Cuts the logic to synchronize.
void switchOffAll()
switch all logic variants to 'off'
long long int SUMOTime
Definition: SUMOTime.h:43
std::map< MSLink *, LinkState > myOriginalLinkStates
Originally loaded link states.
int & getIndex()
Returns a reference to the index.
SUMOReal end
The end of a stretch/cut area (time, in s)
std::map< std::string, TLSLogicVariants * > myLogics
A map from ids to the corresponding variants.
Storage for all programs of a single tls.
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.
WAUTSwitchProcedure_GSP(MSTLLogicControl &control, WAUT &waut, MSTrafficLightLogic *from, MSTrafficLightLogic *to, bool synchron)
Constructor.
void setTrafficLightSignals(SUMOTime t) const
Lets all running (current) tls programs apply their current signal states to links they control...
std::string myWAUTID
The id of the WAUT that shall switch.
MSTrafficLightLogic * getActive(const std::string &id) const
Returns the active program of a named tls.
bool trySwitch(SUMOTime step)
Determines whether a switch is possible.
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.
WAUTSwitchProcedure_Stretch(MSTLLogicControl &control, WAUT &waut, MSTrafficLightLogic *from, MSTrafficLightLogic *to, bool synchron)
Constructor.
std::vector< std::string > getAllTLIds() const
void addLink(MSLink *link, MSLane *lane, int pos)
virtual ~WAUTSwitchProcedure()
Destructor.
MSTLLogicControl()
Constructor.
Base (microsim) event class.
Definition: Command.h:61
WAUT & myWAUT
The WAUT responsible for switching.
void closeWAUT(const std::string &wautid)
Closes loading of a WAUT.
MSTrafficLightLogic * getLogic(const std::string &programID) const
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.
std::vector< MSTrafficLightLogic * > getAllLogics() const
bool mySwitchSynchron
Information whether to switch synchron (?)
MSTLLogicControl & myControl
The control the logic belongs to.
bool addLogic(const std::string &programID, MSTrafficLightLogic *logic, bool netWasLoaded, bool isNewDefault=true)
Adds a logic (program)
void addSwitchCommand(OnSwitchAction *c)
MSTrafficLightLogic * getLogicInstantiatingOff(MSTLLogicControl &tlc, const std::string &programID)
bool isActive(const MSTrafficLightLogic *tl) const
MSTLLogicControl & operator=(const MSTLLogicControl &)
Invalidated assignment operator.
MSTrafficLightLogic * getActive() const
std::pair< SUMOTime, MSPhaseDefinition > getPhaseDef(const std::string &tlid) const
return the complete phase definition for a named traffic lights logic
WAUTSwitchProcedure * proc
The used procedure.
void adaptLogic(SUMOTime step)
Stretches the destination program's phase to which the tls was switched.
WAUTSwitchProcedure(MSTLLogicControl &control, WAUT &waut, MSTrafficLightLogic *from, MSTrafficLightLogic *to, bool synchron)
Constructor.
SUMOReal fac
The weight factor of a stretch/cut area.
This class simply switches to the next program.
bool synchron
Information whether this junction shall be switched synchron.
void adaptLogic(SUMOTime step)
Determines the destination program's changes and applies them.
virtual bool trySwitch(SUMOTime step)=0
Determines whether a switch is possible.
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.
int getStretchAreaNo(MSTrafficLightLogic *from) const
Returns the number of given Stretch-areas for the given program.
SUMOTime when
The time the WAUT shall switch the TLS.
void stretchLogic(SUMOTime step, SUMOTime startPos, SUMOTime allStretchTime)
Stretches the logic to synchronize.
SUMOReal begin
The begin of a stretch/cut area (time, in s)
std::vector< OnSwitchAction * > mySwitchActions
The list of actions/commands to execute on switch.
void setStateInstantiatingOnline(MSTLLogicControl &tlc, const std::string &state)
bool knows(const std::string &id) const
Returns the information whether the named tls is stored.
bool trySwitch(SUMOTime step)
Determines whether a switch is possible.
std::string startProg
The name of the start program.
WAUTSwitchProcedure & operator=(const WAUTSwitchProcedure &)
Invalidated assignment operator.
const std::string & getWAUTID() const
Returns the WAUT-id.
WAUTSwitchProcedure_JustSwitch(MSTLLogicControl &control, WAUT &waut, MSTrafficLightLogic *from, MSTrafficLightLogic *to, bool synchron)
Constructor.
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.
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.
WAUTSwitchProcedure_GSP & operator=(const WAUTSwitchProcedure_GSP &)
Invalidated assignment operator.
void switchTo(MSTLLogicControl &tlc, const std::string &programID)
StretchBereichDef getStretchBereichDef(MSTrafficLightLogic *from, int index) const
Returns the numbered Stretch-area for the given program.
std::vector< WAUTSwitch > switches
The list of switches to be done by the WAUT.
virtual void execute()=0
Executes the action.
void switchToPos(SUMOTime simStep, MSTrafficLightLogic &logic, SUMOTime toTime)
switches the given logic directly to the given position
This event-class is used to initialise a WAUT switch at a certain time.
WAUTSwitchProcedure_Stretch & operator=(const WAUTSwitchProcedure_Stretch &)
Invalidated assignment operator.
void addWAUT(SUMOTime refTime, const std::string &id, const std::string &startProg)
Adds a WAUT definition.
This class switches using the GSP algorithm.
SUMOTime getDiffToStartOfPhase(MSTrafficLightLogic &logic, SUMOTime toTime)
Returns the difference between a given time and the start of the phase.
SUMOTime refTime
The reference time (offset to the switch times)
This is the abstract base class for switching from one tls program to another.
std::string id
The id of the WAUT.
WAUTSwitchProcedure_JustSwitch & operator=(const WAUTSwitchProcedure_JustSwitch &)
Invalidated assignment operator.
TLSLogicVariants & operator=(const TLSLogicVariants &)
Invalidated assignment operator.
std::map< std::string, WAUT * > myWAUTs
A map of ids to corresponding WAUTs.
bool isPosAtGSP(SUMOTime currentTime, const MSTrafficLightLogic &logic)
Checks, whether the position of a signal programm is at the GSP ("GuenstigerUmschaltPunkt") ...
The parent class for traffic light logics.
#define SUMOReal
Definition: config.h:214
Storage for a WAUTs switch point.
int getGSPValue(const MSTrafficLightLogic &logic) const
Returns the GSP-value.
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.
std::vector< MSTrafficLightLogic * > getAllLogics() const
Returns a vector which contains all logics.
MSTrafficLightLogic * from
The current program of the tls.
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:79
SUMOTime execute(SUMOTime)
Begins a WAUT switch by executing the command.
MSTrafficLightLogic * myCurrentProgram
The currently used program.
SwitchInitCommand & operator=(const SwitchInitCommand &)
Invalidated assignment operator.
std::string junction
The junction name.
A WAUT definition.