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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
19 // A class that stores and controls tls and switching of their programs
20 /****************************************************************************/
21 #ifndef MSTLLogicControl_h
22 #define MSTLLogicControl_h
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #include <config.h>
29 
30 #include <vector>
31 #include <map>
33 #include <utils/common/Command.h>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
40 class MSLink;
41 class MSLane;
42 class MSPhaseDefinition;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
61 public:
67  public:
69  virtual ~OnSwitchAction() {};
70 
71 
74  virtual void execute() = 0;
75 
76  };
77 
78 
79 
87  public:
90 
91 
94 
95 
102  bool checkOriginalTLS() const;
103 
104 
112  bool addLogic(const std::string& programID, MSTrafficLightLogic* logic, bool netWasLoaded,
113  bool isNewDefault = true);
114 
115 
116 
117  MSTrafficLightLogic* getLogic(const std::string& programID) const;
118  void addSwitchCommand(OnSwitchAction* c);
119  std::vector<MSTrafficLightLogic*> getAllLogics() const;
120  void saveInitialStates();
121  bool isActive(const MSTrafficLightLogic* tl) const;
123  void switchTo(MSTLLogicControl& tlc, const std::string& programID);
124 
125  /* @brief get logic by programID. For the special case "off"
126  * instantiate an MSOffTrafficLightLogic */
127  MSTrafficLightLogic* getLogicInstantiatingOff(MSTLLogicControl& tlc,
128  const std::string& programID);
129 
130  /* @brief sets the state to the given string get for the special program "online"
131  * this program is instantiated only once */
132  void setStateInstantiatingOnline(MSTLLogicControl& tlc,
133  const std::string& state);
134 
135 
136  void executeOnSwitchActions() const;
137  void addLink(MSLink* link, MSLane* lane, int pos);
138 
139 
140  private:
143 
145  std::map<std::string, MSTrafficLightLogic*> myVariants;
146 
148  std::map<MSLink*, LinkState> myOriginalLinkStates;
149 
151  std::vector<OnSwitchAction*> mySwitchActions;
152 
153 
154  private:
157 
160 
161 
162  };
163 
164 
165 
168 
169 
172 
173 
191  bool closeNetworkReading();
192 
193 
200  void setTrafficLightSignals(SUMOTime t) const;
201 
202 
208  std::vector<MSTrafficLightLogic*> getAllLogics() const;
209 
210 
217  TLSLogicVariants& get(const std::string& id) const;
218 
219 
226  MSTrafficLightLogic* get(const std::string& id, const std::string& programID) const;
227 
228 
234  MSTrafficLightLogic* getActive(const std::string& id) const;
235 
236 
242  std::vector<std::string> getAllTLIds() const;
243 
244 
266  bool add(const std::string& id, const std::string& programID,
267  MSTrafficLightLogic* logic, bool newDefault = true);
268 
269 
270 
275  bool knows(const std::string& id) const;
276 
277 
282  bool isActive(const MSTrafficLightLogic* tl) const;
283 
284 
293  void switchTo(const std::string& id, const std::string& programID);
294 
295 
296 
299 
308  void addWAUT(SUMOTime refTime, const std::string& id,
309  const std::string& startProg);
310 
311 
320  void addWAUTSwitch(const std::string& wautid, SUMOTime when,
321  const std::string& to);
322 
323 
335  void addWAUTJunction(const std::string& wautid, const std::string& tls,
336  const std::string& proc, bool synchron);
337 
338 
349  void closeWAUT(const std::string& wautid);
351 
352 
353 
358  void check2Switch(SUMOTime step);
359 
360 
368  std::pair<SUMOTime, MSPhaseDefinition> getPhaseDef(const std::string& tlid) const;
369 
371  void switchOffAll();
372 
373 
374 
375 protected:
383  class SwitchInitCommand : public Command {
384  public:
390  SwitchInitCommand(MSTLLogicControl& p, const std::string& wautid, int index)
391  : myParent(p), myWAUTID(wautid), myIndex(index) { }
392 
393 
396 
397 
398 
401 
417  return myParent.initWautSwitch(*this);
418  }
420 
421 
422 
426  const std::string& getWAUTID() const {
427  return myWAUTID;
428  }
429 
430 
434  int& getIndex() {
435  return myIndex;
436  }
437 
438 
439  protected:
442 
444  std::string myWAUTID;
445 
447  int myIndex;
448 
449 
450  private:
453 
456 
457  };
458 
459 
460 
461 public:
469 
470 
471 protected:
475  struct WAUTSwitch {
479  std::string to;
480  };
481 
482 
486  struct WAUTJunction {
488  std::string junction;
490  std::string procedure;
492  bool synchron;
493  };
494 
495 
499  struct WAUT {
501  std::string id;
503  std::string startProg;
507  std::vector<WAUTSwitch> switches;
509  std::vector<WAUTJunction> junctions;
510  };
511 
512 
517  public:
527  bool synchron)
528  : myFrom(from), myTo(to), mySwitchSynchron(synchron), myWAUT(waut), myControl(control) { }
529 
530 
532  virtual ~WAUTSwitchProcedure() { }
533 
534 
539  virtual bool trySwitch(SUMOTime step) = 0;
540 
541 
542  protected:
553  bool isPosAtGSP(SUMOTime currentTime, const MSTrafficLightLogic& logic);
554 
555 
561  SUMOTime getDiffToStartOfPhase(MSTrafficLightLogic& logic, SUMOTime toTime);
562 
563 
569  void switchToPos(SUMOTime simStep, MSTrafficLightLogic& logic, SUMOTime toTime);
570 
571 
579  int getGSPValue(const MSTrafficLightLogic& logic) const;
580 
581 
582  protected:
585 
588 
591 
594 
597 
598 
599  private:
602 
605 
606  };
607 
608 
614  public:
624  bool synchron);
625 
626 
629 
630 
635  bool trySwitch(SUMOTime step);
636 
637 
638  private:
641 
644 
645  };
646 
647 
648 
654  public:
664  bool synchron);
665 
668 
669 
674  bool trySwitch(SUMOTime step);
675 
676 
677  protected:
680  void adaptLogic(SUMOTime step);
681 
682 
683  private:
686 
689 
690  };
691 
692 
698  public:
708  bool synchron);
709 
710 
713 
714 
719  bool trySwitch(SUMOTime step);
720 
721 
722  protected:
728  void adaptLogic(SUMOTime step);
729 
730 
736  void stretchLogic(SUMOTime step, SUMOTime startPos, SUMOTime allStretchTime);
737 
738 
744  void cutLogic(SUMOTime step, SUMOTime startPos, SUMOTime allCutTime);
745 
746 
747  protected:
753  double begin;
755  double end;
757  double fac;
758 
759  };
760 
761 
766  int getStretchAreaNo(MSTrafficLightLogic* from) const;
767 
768 
776  StretchBereichDef getStretchBereichDef(MSTrafficLightLogic* from, int index) const;
777 
778 
779  private:
782 
785 
786  };
787 
788 
795  std::string junction;
802  };
803 
804 
806  std::map<std::string, WAUT*> myWAUTs;
807 
809  std::vector<WAUTSwitchProcess> myCurrentlySwitched;
810 
812  std::map<std::string, TLSLogicVariants*> myLogics;
813 
816 
817 
818 private:
821 
824 
825 };
826 
827 
828 #endif
829 
830 /****************************************************************************/
831 
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;
long long int SUMOTime
Definition: SUMOTime.h:36
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:54
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.
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:71
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.