SUMO - Simulation of Urban MObility
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 
100  ~TLSLogicVariants();
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;
125  void addSwitchCommand(OnSwitchAction* c);
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 */
134  MSTrafficLightLogic* getLogicInstantiatingOff(MSTLLogicControl& tlc,
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 */
139  void setStateInstantiatingOnline(MSTLLogicControl& tlc,
140  const std::string& state);
141 
142 
143  void executeOnSwitchActions() const;
144  void addLink(MSLink* link, MSLane* lane, int pos);
145 
146 
147 
148  private:
151 
153  std::map<std::string, MSTrafficLightLogic*> myVariants;
154 
156  std::map<MSLink*, LinkState> myOriginalLinkStates;
157 
159  std::vector<OnSwitchAction*> mySwitchActions;
160 
161 
162  private:
165 
168 
169 
170  };
171 
172 
173 
176 
177 
180 
181 
199  bool closeNetworkReading();
200 
201 
208  void setTrafficLightSignals(SUMOTime t) const;
209 
210 
216  std::vector<MSTrafficLightLogic*> getAllLogics() const;
217 
218 
225  TLSLogicVariants& get(const std::string& id) const;
226 
227 
234  MSTrafficLightLogic* get(const std::string& id, const std::string& programID) const;
235 
236 
242  MSTrafficLightLogic* getActive(const std::string& id) const;
243 
244 
250  std::vector<std::string> getAllTLIds() const;
251 
252 
274  bool add(const std::string& id, const std::string& programID,
275  MSTrafficLightLogic* logic, bool newDefault = true);
276 
277 
278 
283  bool knows(const std::string& id) const;
284 
285 
290  bool isActive(const MSTrafficLightLogic* tl) const;
291 
292 
301  void switchTo(const std::string& id, const std::string& programID);
302 
303 
304 
307 
316  void addWAUT(SUMOTime refTime, const std::string& id,
317  const std::string& startProg);
318 
319 
328  void addWAUTSwitch(const std::string& wautid, SUMOTime when,
329  const std::string& to);
330 
331 
343  void addWAUTJunction(const std::string& wautid, const std::string& tls,
344  const std::string& proc, bool synchron);
345 
346 
357  void closeWAUT(const std::string& wautid);
359 
360 
361 
366  void check2Switch(SUMOTime step);
367 
368 
376  std::pair<SUMOTime, MSPhaseDefinition> getPhaseDef(const std::string& tlid) const;
377 
378 
379 
380 protected:
388  class SwitchInitCommand : public Command {
389  public:
395  SwitchInitCommand(MSTLLogicControl& p, const std::string& wautid, unsigned int index)
396  : myParent(p), myWAUTID(wautid), myIndex(index) { }
397 
398 
401 
402 
403 
406 
422  return myParent.initWautSwitch(*this);
423  }
425 
426 
427 
431  const std::string& getWAUTID() const {
432  return myWAUTID;
433  }
434 
435 
439  unsigned int& getIndex() {
440  return myIndex;
441  }
442 
443 
444  protected:
447 
449  std::string myWAUTID;
450 
452  unsigned int myIndex;
453 
454 
455  private:
458 
461 
462  };
463 
464 
465 
466 public:
474 
475 
476 protected:
480  struct WAUTSwitch {
484  std::string to;
485  };
486 
487 
491  struct WAUTJunction {
493  std::string junction;
495  std::string procedure;
497  bool synchron;
498  };
499 
500 
504  struct WAUT {
506  std::string id;
508  std::string startProg;
512  std::vector<WAUTSwitch> switches;
514  std::vector<WAUTJunction> junctions;
515  };
516 
517 
522  public:
532  bool synchron)
533  : myFrom(from), myTo(to), mySwitchSynchron(synchron), myWAUT(waut), myControl(control) { }
534 
535 
537  virtual ~WAUTSwitchProcedure() { }
538 
539 
544  virtual bool trySwitch(SUMOTime step) = 0;
545 
546 
547  protected:
558  bool isPosAtGSP(SUMOTime currentTime, const MSTrafficLightLogic& logic);
559 
560 
566  SUMOTime getDiffToStartOfPhase(MSTrafficLightLogic& logic, SUMOTime toTime);
567 
568 
574  void switchToPos(SUMOTime simStep, MSTrafficLightLogic& logic, SUMOTime toTime);
575 
576 
584  unsigned int getGSPValue(const MSTrafficLightLogic& logic) const;
585 
586 
587  protected:
590 
593 
596 
599 
602 
603 
604  private:
607 
610 
611  };
612 
613 
619  public:
629  bool synchron);
630 
631 
634 
635 
640  bool trySwitch(SUMOTime step);
641 
642 
643  private:
646 
649 
650  };
651 
652 
653 
659  public:
669  bool synchron);
670 
673 
674 
679  bool trySwitch(SUMOTime step);
680 
681 
682  protected:
685  void adaptLogic(SUMOTime step);
686 
687 
688  private:
691 
694 
695  };
696 
697 
703  public:
713  bool synchron);
714 
715 
718 
719 
724  bool trySwitch(SUMOTime step);
725 
726 
727  protected:
733  void adaptLogic(SUMOTime step);
734 
735 
741  void stretchLogic(SUMOTime step, SUMOTime startPos, SUMOTime allStretchTime);
742 
743 
749  void cutLogic(SUMOTime step, SUMOTime startPos, SUMOTime allCutTime);
750 
751 
752  protected:
763 
764  };
765 
766 
771  int getStretchAreaNo(MSTrafficLightLogic* from) const;
772 
773 
781  StretchBereichDef getStretchBereichDef(MSTrafficLightLogic* from, int index) const;
782 
783 
784  private:
787 
790 
791  };
792 
793 
800  std::string junction;
807  };
808 
809 
811  std::map<std::string, WAUT*> myWAUTs;
812 
814  std::vector<WAUTSwitchProcess> myCurrentlySwitched;
815 
817  std::map<std::string, TLSLogicVariants*> myLogics;
818 
821 
822 
823 private:
826 
829 
830 };
831 
832 
833 #endif
834 
835 /****************************************************************************/
836 
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.
long long int SUMOTime
Definition: SUMOTime.h:43
std::map< MSLink *, LinkState > myOriginalLinkStates
Originally loaded link states.
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.
~MSTLLogicControl()
Destructor.
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.
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.
std::vector< std::string > getAllTLIds() const
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.
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.
MSTLLogicControl & operator=(const MSTLLogicControl &)
Invalidated assignment operator.
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.
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.
unsigned int myIndex
The current index within the WAUT switch table.
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.
SUMOTime when
The time the WAUT shall switch the TLS.
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.
bool knows(const std::string &id) const
Returns the information whether the named tls is stored.
std::string startProg
The name of the start program.
const std::string & getWAUTID() const
Returns the WAUT-id.
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.
std::vector< WAUTSwitch > switches
The list of switches to be done by the WAUT.
unsigned int & getIndex()
Returns a reference to the index.
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.
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.
#define SUMOReal
Definition: config.h:213
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.
std::vector< MSTrafficLightLogic * > getAllLogics() const
Returns a vector which contains all logics.
MSTrafficLightLogic * from
The current program of the tls.
SwitchInitCommand(MSTLLogicControl &p, const std::string &wautid, unsigned int index)
Constructor.
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::string junction
The junction name.
A WAUT definition.