SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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-sim.org/
14 // Copyright (C) 2001-2014 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>
39 #include "MSTrafficLightLogic.h"
41 #include <utils/common/Command.h>
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;
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 */
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 */
133  const std::string& state);
134 
135 
136  void executeOnSwitchActions() const;
137  void addLink(MSLink* link, MSLane* lane, unsigned int pos);
138 
139 
140 
141  private:
144 
146  std::map<std::string, MSTrafficLightLogic*> myVariants;
147 
149  std::map<MSLink*, LinkState> myOriginalLinkStates;
150 
152  std::vector<OnSwitchAction*> mySwitchActions;
153 
154 
155  private:
158 
161 
162 
163  };
164 
165 
166 
169 
170 
173 
174 
192  bool closeNetworkReading();
193 
194 
201  void setTrafficLightSignals(SUMOTime t) const;
202 
203 
209  std::vector<MSTrafficLightLogic*> getAllLogics() const;
210 
211 
218  TLSLogicVariants& get(const std::string& id) const;
219 
220 
227  MSTrafficLightLogic* get(const std::string& id, const std::string& programID) const;
228 
229 
235  MSTrafficLightLogic* getActive(const std::string& id) const;
236 
237 
243  std::vector<std::string> getAllTLIds() const;
244 
245 
267  bool add(const std::string& id, const std::string& programID,
268  MSTrafficLightLogic* logic, bool newDefault = true);
269 
270 
271 
276  bool knows(const std::string& id) const;
277 
278 
283  bool isActive(const MSTrafficLightLogic* tl) const;
284 
285 
294  void switchTo(const std::string& id, const std::string& programID);
295 
296 
297 
300 
309  void addWAUT(SUMOTime refTime, const std::string& id,
310  const std::string& startProg);
311 
312 
321  void addWAUTSwitch(const std::string& wautid, SUMOTime when,
322  const std::string& to);
323 
324 
336  void addWAUTJunction(const std::string& wautid, const std::string& tls,
337  const std::string& proc, bool synchron);
338 
339 
350  void closeWAUT(const std::string& wautid);
352 
353 
354 
359  void check2Switch(SUMOTime step);
360 
361 
369  std::pair<SUMOTime, MSPhaseDefinition> getPhaseDef(const std::string& tlid) const;
370 
371 
372 
373 protected:
381  class SwitchInitCommand : public Command {
382  public:
388  SwitchInitCommand(MSTLLogicControl& p, const std::string& wautid, unsigned int index)
389  : myParent(p), myWAUTID(wautid), myIndex(index) { }
390 
391 
394 
395 
396 
399 
415  return myParent.initWautSwitch(*this);
416  }
418 
419 
420 
424  const std::string& getWAUTID() const {
425  return myWAUTID;
426  }
427 
428 
432  unsigned int& getIndex() {
433  return myIndex;
434  }
435 
436 
437  protected:
440 
442  std::string myWAUTID;
443 
445  unsigned int myIndex;
446 
447 
448  private:
451 
454 
455  };
456 
457 
458 
459 public:
467 
468 
469 protected:
473  struct WAUTSwitch {
477  std::string to;
478  };
479 
480 
484  struct WAUTJunction {
486  std::string junction;
488  std::string procedure;
490  bool synchron;
491  };
492 
493 
497  struct WAUT {
499  std::string id;
501  std::string startProg;
505  std::vector<WAUTSwitch> switches;
507  std::vector<WAUTJunction> junctions;
508  };
509 
510 
515  public:
525  bool synchron)
526  : myFrom(from), myTo(to), mySwitchSynchron(synchron), myWAUT(waut), myControl(control) { }
527 
528 
530  virtual ~WAUTSwitchProcedure() { }
531 
532 
537  virtual bool trySwitch(SUMOTime step) = 0;
538 
539 
540  protected:
551  bool isPosAtGSP(SUMOTime currentTime, const MSTrafficLightLogic& logic);
552 
553 
560 
561 
567  void switchToPos(SUMOTime simStep, MSTrafficLightLogic& logic, SUMOTime toTime);
568 
569 
577  unsigned int getGSPValue(const MSTrafficLightLogic& logic) const;
578 
579 
580  protected:
583 
586 
589 
592 
595 
596 
597  private:
600 
603 
604  };
605 
606 
612  public:
622  bool synchron);
623 
624 
627 
628 
633  bool trySwitch(SUMOTime step);
634 
635 
636  private:
639 
642 
643  };
644 
645 
646 
652  public:
662  bool synchron);
663 
666 
667 
672  bool trySwitch(SUMOTime step);
673 
674 
675  protected:
678  void adaptLogic(SUMOTime step);
679 
680 
681  private:
684 
687 
688  };
689 
690 
696  public:
706  bool synchron);
707 
708 
711 
712 
717  bool trySwitch(SUMOTime step);
718 
719 
720  protected:
726  void adaptLogic(SUMOTime step);
727 
728 
734  void stretchLogic(SUMOTime step, SUMOTime startPos, SUMOTime allStretchTime);
735 
736 
742  void cutLogic(SUMOTime step, SUMOTime startPos, SUMOTime allCutTime);
743 
744 
745  protected:
756 
757  };
758 
759 
764  int getStretchAreaNo(MSTrafficLightLogic* from) const;
765 
766 
775 
776 
777  private:
780 
783 
784  };
785 
786 
793  std::string junction;
800  };
801 
802 
804  std::map<std::string, WAUT*> myWAUTs;
805 
807  std::vector<WAUTSwitchProcess> myCurrentlySwitched;
808 
810  std::map<std::string, TLSLogicVariants*> myLogics;
811 
814 
815 
816 private:
819 
822 
823 };
824 
825 
826 #endif
827 
828 /****************************************************************************/
829