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-2013 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);
125  const std::string& programID);
126  void executeOnSwitchActions() const;
127  void addLink(MSLink* link, MSLane* lane, unsigned int pos);
128 
129 
130 
131  private:
134 
136  std::map<std::string, MSTrafficLightLogic*> myVariants;
137 
139  std::map<MSLink*, LinkState> myOriginalLinkStates;
140 
142  std::vector<OnSwitchAction*> mySwitchActions;
143 
144 
145  private:
148 
151 
152 
153  };
154 
155 
156 
159 
160 
163 
164 
182  bool closeNetworkReading();
183 
184 
191  void setTrafficLightSignals(SUMOTime t) const;
192 
193 
199  std::vector<MSTrafficLightLogic*> getAllLogics() const;
200 
201 
208  TLSLogicVariants& get(const std::string& id) const;
209 
210 
217  MSTrafficLightLogic* get(const std::string& id, const std::string& programID) const;
218 
219 
225  MSTrafficLightLogic* getActive(const std::string& id) const;
226 
227 
233  std::vector<std::string> getAllTLIds() const;
234 
235 
257  bool add(const std::string& id, const std::string& programID,
258  MSTrafficLightLogic* logic, bool newDefault = true);
259 
260 
261 
266  bool knows(const std::string& id) const;
267 
268 
273  bool isActive(const MSTrafficLightLogic* tl) const;
274 
275 
284  void switchTo(const std::string& id, const std::string& programID);
285 
286 
287 
290 
299  void addWAUT(SUMOTime refTime, const std::string& id,
300  const std::string& startProg);
301 
302 
311  void addWAUTSwitch(const std::string& wautid, SUMOTime when,
312  const std::string& to);
313 
314 
326  void addWAUTJunction(const std::string& wautid, const std::string& tls,
327  const std::string& proc, bool synchron);
328 
329 
340  void closeWAUT(const std::string& wautid);
342 
343 
344 
349  void check2Switch(SUMOTime step);
350 
351 
359  std::pair<SUMOTime, MSPhaseDefinition> getPhaseDef(const std::string& tlid) const;
360 
361 
362 
363 protected:
371  class SwitchInitCommand : public Command {
372  public:
378  SwitchInitCommand(MSTLLogicControl& p, const std::string& wautid, unsigned int index)
379  : myParent(p), myWAUTID(wautid), myIndex(index) { }
380 
381 
384 
385 
386 
389 
405  return myParent.initWautSwitch(*this);
406  }
408 
409 
410 
414  const std::string& getWAUTID() const {
415  return myWAUTID;
416  }
417 
418 
422  unsigned int& getIndex() {
423  return myIndex;
424  }
425 
426 
427  protected:
430 
432  std::string myWAUTID;
433 
435  unsigned int myIndex;
436 
437 
438  private:
441 
444 
445  };
446 
447 
448 
449 public:
457 
458 
459 protected:
463  struct WAUTSwitch {
467  std::string to;
468  };
469 
470 
474  struct WAUTJunction {
476  std::string junction;
478  std::string procedure;
480  bool synchron;
481  };
482 
483 
487  struct WAUT {
489  std::string id;
491  std::string startProg;
495  std::vector<WAUTSwitch> switches;
497  std::vector<WAUTJunction> junctions;
498  };
499 
500 
505  public:
515  bool synchron)
516  : myFrom(from), myTo(to), mySwitchSynchron(synchron), myWAUT(waut), myControl(control) { }
517 
518 
520  virtual ~WAUTSwitchProcedure() { }
521 
522 
527  virtual bool trySwitch(SUMOTime step) = 0;
528 
529 
530  protected:
541  bool isPosAtGSP(SUMOTime currentTime, const MSTrafficLightLogic& logic);
542 
543 
550 
551 
557  void switchToPos(SUMOTime simStep, MSTrafficLightLogic& logic, SUMOTime toTime);
558 
559 
567  unsigned int getGSPValue(const MSTrafficLightLogic& logic) const;
568 
569 
570  protected:
573 
576 
579 
582 
585 
586 
587  private:
590 
593 
594  };
595 
596 
602  public:
612  bool synchron);
613 
614 
617 
618 
623  bool trySwitch(SUMOTime step);
624 
625 
626  private:
629 
632 
633  };
634 
635 
636 
642  public:
652  bool synchron);
653 
656 
657 
662  bool trySwitch(SUMOTime step);
663 
664 
665  protected:
668  void adaptLogic(SUMOTime step);
669 
670 
671  private:
674 
677 
678  };
679 
680 
686  public:
696  bool synchron);
697 
698 
701 
702 
707  bool trySwitch(SUMOTime step);
708 
709 
710  protected:
716  void adaptLogic(SUMOTime step);
717 
718 
724  void stretchLogic(SUMOTime step, SUMOTime startPos, SUMOTime allStretchTime);
725 
726 
732  void cutLogic(SUMOTime step, SUMOTime startPos, SUMOTime allCutTime);
733 
734 
735  protected:
746 
747  };
748 
749 
754  int getStretchAreaNo(MSTrafficLightLogic* from) const;
755 
756 
765 
766 
767  private:
770 
773 
774  };
775 
776 
783  std::string junction;
790  };
791 
792 
794  std::map<std::string, WAUT*> myWAUTs;
795 
797  std::vector<WAUTSwitchProcess> myCurrentlySwitched;
798 
800  std::map<std::string, TLSLogicVariants*> myLogics;
801 
804 
805 
806 private:
809 
812 
813 };
814 
815 
816 #endif
817 
818 /****************************************************************************/
819