1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 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 /****************************************************************************/
10 /// @file    MSTLLogicControl.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Julia Ringel
13 /// @author  Jakob Erdmann
14 /// @author  Michael Behrisch
15 /// @author  Friedemann Wesner
16 /// @date    Sept 2002
17 /// @version $Id$
18 ///
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>
32 #include <utils/xml/SUMOXMLDefinitions.h>
33 #include <utils/common/Command.h>
34 
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class MSTrafficLightLogic;
40 class MSLink;
41 class MSLane;
42 class MSPhaseDefinition;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
48 /**
49  * @class MSTLLogicControl
50  * @brief A class that stores and controls tls and switching of their programs
51  *
52  * This class holds all traffic light logics (programs) and their
53  *  variants during the simulation. In addition, the schedule for switching
54  *  between different tls programs are also stored.
55  *
56  * When a WAUT is forced to switch, for each TLS, a switching procedure
57  *  derived from WAUTSwitchProcedure is initialised and is asked repeatedly
58  *  whether a switch could be done until it returns true.
59  */
60 class MSTLLogicControl {
61 public:
62     /**
63      * @class OnSwitchAction
64      * @brief Base class for things to execute if a tls switches to a new phase
65      */
66     class OnSwitchAction {
67     public:
68         /// @brief Destructor.
~OnSwitchAction()69         virtual ~OnSwitchAction() {};
70 
71 
72         /** @brief Executes the action
73          */
74         virtual void execute() = 0;
75 
76     };
77 
78 
79 
80     /**
81      * @class TLSLogicVariants
82      * @brief Storage for all programs of a single tls
83      *
84      * This class joins all programs of a single tls.
85      */
86     class TLSLogicVariants {
87     public:
88         /// @brief Constructor
89         TLSLogicVariants();
90 
91 
92         /// @brief Destructor
93         ~TLSLogicVariants();
94 
95 
96         /** @brief Verifies traffic lights loaded from the network
97          *
98          * Compare the phase state sizes of each phase with the according tls' number
99          *  of controlled links.
100          * @return Whether all tls programs are valid
101          */
102         bool checkOriginalTLS() const;
103 
104 
105         /** @brief Adds a logic (program)
106          *
107          * @param[in] programID The sub-id of this program
108          * @param[in] logic The logic to add
109          * @param[in] netWasLoaded Whether the network has already been loaded (the links have been assigned)
110          * @param[in] isNewDefault Whether this logic shall be treated as the currently active logic
111          */
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;
122         MSTrafficLightLogic* getActive() 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         void ignoreLinkIndex(int pos);
139 
140 
141     private:
142         /// @brief The currently used program
143         MSTrafficLightLogic* myCurrentProgram;
144 
145         /// @brief A map of subkeys to programs
146         std::map<std::string, MSTrafficLightLogic*> myVariants;
147 
148         /// @brief Originally loaded link states
149         std::map<MSLink*, LinkState> myOriginalLinkStates;
150 
151         /// @brief The list of actions/commands to execute on switch
152         std::vector<OnSwitchAction*> mySwitchActions;
153 
154 
155     private:
156         /// @brief Invalidated copy constructor.
157         TLSLogicVariants(const TLSLogicVariants&);
158 
159         /// @brief Invalidated assignment operator.
160         TLSLogicVariants& operator=(const TLSLogicVariants&);
161 
162 
163     };
164 
165 
166 
167     /// @brief Constructor
168     MSTLLogicControl();
169 
170 
171     /// @brief Destructor
172     ~MSTLLogicControl();
173 
174 
175     /** @brief Lets MSTLLogicControl know that the network has been loaded
176      *
177      * This method must be called after the network (including the initial tls
178      *  definitions) was loaded.
179      *
180      * The originally loaded traffic lights are also verified herein by calling
181      *  TLSLogicVariants::checkOriginalTLS, first.
182      *
183      * The MSTLLogicControl is informed in order to know that link information
184      *  is known for the tls programs loaded afterwards so that it may be adapted
185      *  from the previously loaded tls (a net may only contain one program per tls).
186      *
187      * The states of the links controlled by tls are saved for their potential later usage
188      *  (if the tls is switched to off-mode).
189      *
190      * @return Whether the traffic lights could be initialised and are correct
191      */
192     bool closeNetworkReading();
193 
194 
195     /** @brief Lets all running (current) tls programs apply their current signal states to links they control
196      * @param[in] t The current time
197      * @see MSTrafficLightLogic::setTrafficLightSignals
198      * @see LinkState
199      * @see MSLink::setTLState
200      */
201     void setTrafficLightSignals(SUMOTime t) const;
202 
203 
204     /** @brief Returns a vector which contains all logics
205      *
206      * All logics are included, active (current) and non-active
207      * @return A vector containing all loaded logics
208      */
209     std::vector<MSTrafficLightLogic*> getAllLogics() const;
210 
211 
212     /** @brief Returns the variants of a named tls
213      *
214      * @param[in] id The id of the tls to get variants of
215      * @return The variants of the named tls
216      * @exception InvalidArgument
217      */
218     TLSLogicVariants& get(const std::string& id) const;
219 
220 
221     /** @brief Returns a single program (variant) defined by the tls id and the program programID
222      *
223      * @param[in] id The id of the tls to get program of
224      * @param[in] programID The program id of the tls program to get
225      * @return The defined tls program if existing, 0 otherwise
226      */
227     MSTrafficLightLogic* get(const std::string& id, const std::string& programID) const;
228 
229 
230     /** @brief Returns the active program of a named tls
231      *
232      * @param[in] id The id of the tls to get the active program of
233      * @return The current program of the defined tls if existing, 0 otherwise
234      */
235     MSTrafficLightLogic* getActive(const std::string& id) const;
236 
237 
238     /**
239      * Returns the ids of all existing variants-structures, wich are the ids of their
240      * contained tls logics (not the logic's programm-ids)
241      * @return the list of ids
242      */
243     std::vector<std::string> getAllTLIds() const;
244 
245 
246     /** @brief Adds a tls program to the container
247      *
248      * If a tls with the given id is not yet known, a TLSLogicVariants structure
249      *  is built for this tls and added to the internal container and the tls
250      *  program is used as the new default.
251      *
252      * If the tls to add is loaded from an additional file (indicated by myNetWasLoaded,
253      *  see closeNetworkReading), links from previously loaded tls are adapted to the logic.
254      *  This may throw a ProcessError in the case no tls program was loaded for this
255      *  tls before (was not defined in the network).
256      *
257      * The parameter newDefault defines whether this program will be used as the new
258      *  default program of this tls. This means that an existing tls program for this
259      *  tls is replaced within the according TLSLogicVariants structure.
260      *
261      * @param[in] id The id of the tls (program) to add
262      * @param[in] programID The program id of the tls (program) to add
263      * @param[in] logic The tls logic to insert
264      * @exception ProcessError In the case an additional tls program is loaded and no one for the tls existed in the network
265      * @return true if the tls program could be added, false otherwise
266      */
267     bool add(const std::string& id, const std::string& programID,
268              MSTrafficLightLogic* logic, bool newDefault = true);
269 
270 
271 
272     /** @brief Returns the information whether the named tls is stored
273      * @param[in] id The id of the tls to ask for
274      * @return Whether a tls with the given id is known
275      */
276     bool knows(const std::string& id) const;
277 
278 
279     /** @brief Returns whether the given tls program is the currently active for his tls
280      * @param[in] tl The tls to ask for
281      * @return Whether the given tl is currently active (or a different program is used)
282      */
283     bool isActive(const MSTrafficLightLogic* tl) const;
284 
285 
286     /** @brief Switches the named (id) tls to the named (programID) program
287      *
288      * The program with the used programID must be previously added.
289      * If the tls itself or the program to switch to is not known, false is returned.
290      * @param[in] id The id of the tls to switch to
291      * @param[in] programID The program id of the tls (program) to switch to
292      * @exception ProcessError If either the tls or the program to switch to is not known
293      */
294     void switchTo(const std::string& id, const std::string& programID);
295 
296 
297 
298     /// @name WAUT definition methods
299     /// @{
300 
301     /** @brief Adds a WAUT definition
302      *
303      * Throws an InvalidArgument if the given id is already in use.
304      * @param[in] refTime The reference time of the WAUT
305      * @param[in] id The ID of the WAUT
306      * @param[in] startProg The begin program of the WAUT
307      * @exception InvalidArgument If the id is already used by another WAUT
308      */
309     void addWAUT(SUMOTime refTime, const std::string& id,
310                  const std::string& startProg);
311 
312 
313     /** @brief Adds a WAUT switch step to a previously built WAUT
314      *
315      * Throws an InvalidArgument if the given WAUT id is not known.
316      * @param[in] wautid The ID of the WAUT
317      * @param[in] when The switch procedure begin
318      * @param[in] to The program the WAUT shall start to switch to at the given time
319      * @exception InvalidArgument If the named WAUT is not known
320      */
321     void addWAUTSwitch(const std::string& wautid, SUMOTime when,
322                        const std::string& to);
323 
324 
325     /** @brief Adds a tls to the list of tls to be switched by the named WAUT
326      *
327      * Passes the values directly to the used tls control. This throws an InvalidArgument
328      *  if the given WAUT id or the given junction id is not known.
329      * @param[in] wautid The ID of the WAUT
330      * @param[in] tls The id of the tls to be switched
331      * @param[in] proc The switching procedure to use
332      * @param[in] synchron Whether the switching shall be done in synchron mode
333      * @exception InvalidArgument If the named WAUT or the named tls are not known
334      * @exception ProcessError If the initial switch fails
335      */
336     void addWAUTJunction(const std::string& wautid, const std::string& tls,
337                          const std::string& proc, bool synchron);
338 
339 
340     /** @brief Closes loading of a WAUT
341      *
342      * Instantiates the first switch ("SwitchInitCommand") for the WAUT into the
343      *  network's simulation time step begin event control.
344      * Throws an InvalidArgument if the given WAUT id is not known.
345      *
346      * @param[in] wautid The ID of the WAUT
347      * @exception InvalidArgument If the named WAUT is not known
348      * @see SwitchInitCommand
349      */
350     void closeWAUT(const std::string& wautid);
351     /// @}
352 
353 
354 
355     /** @brief Checks whether any WAUT is trying to switch a tls into another program
356      *
357      * Called from MSNet::simulationStep
358      */
359     void check2Switch(SUMOTime step);
360 
361 
362     /** @brief return the complete phase definition for a named traffic lights logic
363      *
364      * The phase definition will be the current of the currently active program of
365      *  the named tls.
366      * @param[in] tlid The id of the tls to get the current phases of
367      * @return A pair containing the current time and the current phases of the named tls
368      */
369     std::pair<SUMOTime, MSPhaseDefinition> getPhaseDef(const std::string& tlid) const;
370 
371     /// @brief switch all logic variants to 'off'
372     void switchOffAll();
373 
374 
375 
376 protected:
377     /**
378      * @class SwitchInitCommand
379      * @brief This event-class is used to initialise a WAUT switch at a certain time.
380      *
381      * This command is reused. The index of the WAUT-switch is incremented at each
382      *  call to the control.
383      */
384     class SwitchInitCommand : public Command {
385     public:
386         /** @brief Constructor
387          * @param[in] p The logic control
388          * @param[in] wautid The id of the WAUT
389          * @param[in] index The first position within the WAUT table
390          */
SwitchInitCommand(MSTLLogicControl & p,const std::string & wautid,int index)391         SwitchInitCommand(MSTLLogicControl& p, const std::string& wautid, int index)
392             : myParent(p), myWAUTID(wautid), myIndex(index) { }
393 
394 
395         /// @brief Destructor
~SwitchInitCommand()396         ~SwitchInitCommand() { }
397 
398 
399 
400         /// @name Derived from Command
401         /// @{
402 
403         /** @brief Begins a WAUT switch by executing the command.
404          *
405          * The parent's "initWautSwitch" method is called supporting
406          *  this command as an argument. The result of "initWautSwitch"
407          *  is returned.
408          *
409          * "initWautSwitch" may throw an ProcessError if the program
410          *  to switch to is not known.
411          *
412          * @param[in] currentTime The current simulation time (unused)
413          * @return The time after which the command shall be executed again
414          * @exception ProcessError If the program to switch to does not exist
415          * @see MSTLLogicControl::initWautSwitch
416          */
execute(SUMOTime)417         SUMOTime execute(SUMOTime) {
418             return myParent.initWautSwitch(*this);
419         }
420         /// @}
421 
422 
423 
424         /** @brief Returns the WAUT-id
425          * @return The WAUT id
426          */
getWAUTID()427         const std::string& getWAUTID() const {
428             return myWAUTID;
429         }
430 
431 
432         /** @brief Returns a reference to the index
433          * @return A reference to the index
434          */
getIndex()435         int& getIndex() {
436             return myIndex;
437         }
438 
439 
440     protected:
441         /// @brief The control to call
442         MSTLLogicControl& myParent;
443 
444         /// @brief The id of the WAUT that shall switch
445         std::string myWAUTID;
446 
447         /// @brief The current index within the WAUT switch table
448         int myIndex;
449 
450 
451     private:
452         /// @brief Invalidated copy constructor.
453         SwitchInitCommand(const SwitchInitCommand&);
454 
455         /// @brief Invalidated assignment operator.
456         SwitchInitCommand& operator=(const SwitchInitCommand&);
457 
458     };
459 
460 
461 
462 public:
463     /** @brief Initialises switching a WAUT
464      *
465      * This method is called from a previously built SwitchInitCommand
466      * @param[in] The command which initialises the switch
467      * @return The time offset to next call
468      */
469     SUMOTime initWautSwitch(SwitchInitCommand& cmd);
470 
471 
472 protected:
473     /** @struct WAUTSwitch
474      * @brief Storage for a WAUTs switch point
475      */
476     struct WAUTSwitch {
477         /// @brief The time the WAUT shall switch the TLS
478         SUMOTime when;
479         /// @brief The program name the WAUT shall switch the TLS to
480         std::string to;
481     };
482 
483 
484     /** @struct WAUTJunction
485      * @brief Storage for a junction assigned to a WAUT
486      */
487     struct WAUTJunction {
488         /// @brief The junction name
489         std::string junction;
490         /// @brief The procedure to switch the junction with
491         std::string procedure;
492         /// @brief Information whether this junction shall be switched synchron
493         bool synchron;
494     };
495 
496 
497     /** @struct WAUT
498      * @brief A WAUT definition
499      */
500     struct WAUT {
501         /// @brief The id of the WAUT
502         std::string id;
503         /// @brief The name of the start program
504         std::string startProg;
505         /// @brief The reference time (offset to the switch times)
506         SUMOTime refTime;
507         /// @brief The list of switches to be done by the WAUT
508         std::vector<WAUTSwitch> switches;
509         /// @brief The list of switches assigned to the WAUT
510         std::vector<WAUTJunction> junctions;
511     };
512 
513 
514     /** @class WAUTSwitchProcedure
515      * @brief This is the abstract base class for switching from one tls program to another.
516      */
517     class WAUTSwitchProcedure {
518     public:
519         /** @brief Constructor
520          * @param[in] control The responsible tls control
521          * @param[in] waut The WAUT to switch
522          * @param[in] from The original tls program
523          * @param[in] to The destination tls program
524          * @param[in] synchron Whether the switch shall be done in synchronuous mode
525          */
WAUTSwitchProcedure(MSTLLogicControl & control,WAUT & waut,MSTrafficLightLogic * from,MSTrafficLightLogic * to,bool synchron)526         WAUTSwitchProcedure(MSTLLogicControl& control, WAUT& waut,
527                             MSTrafficLightLogic* from, MSTrafficLightLogic* to,
528                             bool synchron)
529             : myFrom(from), myTo(to), mySwitchSynchron(synchron), myWAUT(waut), myControl(control) { }
530 
531 
532         /// @brief Destructor
~WAUTSwitchProcedure()533         virtual ~WAUTSwitchProcedure() { }
534 
535 
536         /** @brief Determines whether a switch is possible.
537          * @param[in] step The current simulation step
538          * @return If a switch shall be done, this method should return true.
539          */
540         virtual bool trySwitch(SUMOTime step) = 0;
541 
542 
543     protected:
544         /** @brief Checks, whether the position of a signal programm is at the GSP ("GuenstigerUmschaltPunkt")
545          *
546          * The GSP must be given as a logic's parameter ("GSP"). Not the simulation second,
547          *  but the phase the GSP lies within is used. If the phase the GSP lies within is
548          *  the same as the logic's current phase, the result is true.
549          * @param[in] currentTime The current time step
550          * @param[in] logic The logic for which this should be examined
551          * @return Whether the current step is the GSP
552          * @see getGSPValue
553          */
554         bool isPosAtGSP(SUMOTime currentTime, const MSTrafficLightLogic& logic);
555 
556 
557         /** @brief Returns the difference between a given time and the start of the phase
558          * @param[in] logic The logic to consider
559          * @param[in] toTime The time to ask for
560          * @return How much time elapsed between the last pahse start and the given time
561          */
562         SUMOTime getDiffToStartOfPhase(MSTrafficLightLogic& logic, SUMOTime toTime);
563 
564 
565         /** @brief switches the given logic directly to the given position
566          * @param[in] simStep The current simulation time
567          * @param[in] logic The logic to switch
568          * @param[in] toTime The time offset within the logic's phases to switch to
569          */
570         void switchToPos(SUMOTime simStep, MSTrafficLightLogic& logic, SUMOTime toTime);
571 
572 
573         /** @brief Returns the GSP-value
574          *
575          * The GSP must be given as a logic's parameter ("GSP").
576          * @param[in] logic The logic to retrieve the GSP from
577          * @return The GSP value; 0 if not given.
578          * @see MSTrafficLightLogic::getParameterValue
579          */
580         int getGSPValue(const MSTrafficLightLogic& logic) const;
581 
582 
583     protected:
584         /// @brief The current program of the tls to switch
585         MSTrafficLightLogic* myFrom;
586 
587         /// @brief The program to switch the tls to
588         MSTrafficLightLogic* myTo;
589 
590         /// @brief Information whether to switch synchron (?)
591         bool mySwitchSynchron;
592 
593         /// @brief The WAUT responsible for switching
594         WAUT& myWAUT;
595 
596         /// @brief The control the logic belongs to
597         MSTLLogicControl& myControl;
598 
599 
600     private:
601         /// @brief Invalidated copy constructor.
602         WAUTSwitchProcedure(const WAUTSwitchProcedure&);
603 
604         /// @brief Invalidated assignment operator.
605         WAUTSwitchProcedure& operator=(const WAUTSwitchProcedure&);
606 
607     };
608 
609 
610     /**
611      * @class WAUTSwitchProcedure_JustSwitch
612      * @brief This class simply switches to the next program
613      */
614     class WAUTSwitchProcedure_JustSwitch : public WAUTSwitchProcedure {
615     public:
616         /** @brief Constructor
617          * @param[in] control The responsible tls control
618          * @param[in] waut The WAUT to switch
619          * @param[in] from The original tls program
620          * @param[in] to The destination tls program
621          * @param[in] synchron Whether the switch shall be done in synchronuous mode
622          */
623         WAUTSwitchProcedure_JustSwitch(MSTLLogicControl& control, WAUT& waut,
624                                        MSTrafficLightLogic* from, MSTrafficLightLogic* to,
625                                        bool synchron);
626 
627 
628         /// @brief Destructor
629         ~WAUTSwitchProcedure_JustSwitch();
630 
631 
632         /** @brief Determines whether a switch is possible.
633          * @param[in] step The current simulation step
634          * @return This implementation alsways returns true
635          */
636         bool trySwitch(SUMOTime step);
637 
638 
639     private:
640         /// @brief Invalidated copy constructor.
641         WAUTSwitchProcedure_JustSwitch(const WAUTSwitchProcedure_JustSwitch&);
642 
643         /// @brief Invalidated assignment operator.
644         WAUTSwitchProcedure_JustSwitch& operator=(const WAUTSwitchProcedure_JustSwitch&);
645 
646     };
647 
648 
649 
650     /**
651      * @class WAUTSwitchProcedure_GSP
652      * @brief This class switches using the GSP algorithm.
653      */
654     class WAUTSwitchProcedure_GSP : public WAUTSwitchProcedure {
655     public:
656         /** @brief Constructor
657          * @param[in] control The responsible tls control
658          * @param[in] waut The WAUT to switch
659          * @param[in] from The original tls program
660          * @param[in] to The destination tls program
661          * @param[in] synchron Whether the switch shall be done in synchronuous mode
662          */
663         WAUTSwitchProcedure_GSP(MSTLLogicControl& control, WAUT& waut,
664                                 MSTrafficLightLogic* from, MSTrafficLightLogic* to,
665                                 bool synchron);
666 
667         /// @brief Destructor
668         ~WAUTSwitchProcedure_GSP();
669 
670 
671         /** @brief Determines whether a switch is possible.
672          * @param[in] step The current simulation step
673          * @return If a switch shall be done, this method should return true.
674          */
675         bool trySwitch(SUMOTime step);
676 
677 
678     protected:
679         /** @brief Stretches the destination program's phase to which the tls was switched
680          */
681         void adaptLogic(SUMOTime step);
682 
683 
684     private:
685         /// @brief Invalidated copy constructor.
686         WAUTSwitchProcedure_GSP(const WAUTSwitchProcedure_GSP&);
687 
688         /// @brief Invalidated assignment operator.
689         WAUTSwitchProcedure_GSP& operator=(const WAUTSwitchProcedure_GSP&);
690 
691     };
692 
693 
694     /**
695      * @class WAUTSwitchProcedure_Stretch
696      * @brief This class switches using the Stretch algorithm.
697      */
698     class WAUTSwitchProcedure_Stretch : public WAUTSwitchProcedure {
699     public:
700         /** @brief Constructor
701          * @param[in] control The responsible tls control
702          * @param[in] waut The WAUT to switch
703          * @param[in] from The original tls program
704          * @param[in] to The destination tls program
705          * @param[in] synchron Whether the switch shall be done in synchronuous mode
706          */
707         WAUTSwitchProcedure_Stretch(MSTLLogicControl& control, WAUT& waut,
708                                     MSTrafficLightLogic* from, MSTrafficLightLogic* to,
709                                     bool synchron);
710 
711 
712         /// @brief Destructor
713         ~WAUTSwitchProcedure_Stretch();
714 
715 
716         /** @brief Determines whether a switch is possible.
717          * @param[in] step The current simulation step
718          * @return If a switch shall be done, this method should return true.
719          */
720         bool trySwitch(SUMOTime step);
721 
722 
723     protected:
724         /** @brief Determines the destination program's changes and applies them
725          * @param[in] step The current simulation step
726          * @see cutLogic
727          * @see stretchLogic
728          */
729         void adaptLogic(SUMOTime step);
730 
731 
732         /** @brief Stretches the logic to synchronize
733          * @param[in] step The current simulation step
734          * @param[in] startPos The position in the destination program to switch to
735          * @param[in] allStretchTime The amount by which the logic shall be streched
736          */
737         void stretchLogic(SUMOTime step, SUMOTime startPos, SUMOTime allStretchTime);
738 
739 
740         /** @brief Cuts the logic to synchronize
741          * @param[in] step The current simulation step
742          * @param[in] startPos The position in the destination program to switch to
743          * @param[in] allCutTime The amount by which the logic shall be cut
744          */
745         void cutLogic(SUMOTime step, SUMOTime startPos, SUMOTime allCutTime);
746 
747 
748     protected:
749         /** @struct StretchBereichDef
750          * @brief A definition of a stretch - Bereich
751          */
752         struct StretchBereichDef {
753             /// @brief The begin of a stretch/cut area (time, in s)
754             double begin;
755             /// @brief The end of a stretch/cut area (time, in s)
756             double end;
757             /// @brief The weight factor of a stretch/cut area
758             double fac;
759 
760         };
761 
762 
763         /** @brief Returns the number of given Stretch-areas for the given program
764          * @param[in] from The tls program to get the number of stretch areas from
765          * @return The number of stretch areas
766          */
767         int getStretchAreaNo(MSTrafficLightLogic* from) const;
768 
769 
770         /** @brief Returns the numbered Stretch-area for the given program
771          *
772          * The first area has normally the number "1", not "0"!
773          * @param[in] from The tls program to get the named stretch area from
774          * @param[in] index The index (identifier) for the area
775          * @return The definition of the stretch area
776          */
777         StretchBereichDef getStretchBereichDef(MSTrafficLightLogic* from, int index) const;
778 
779 
780     private:
781         /// @brief Invalidated copy constructor.
782         WAUTSwitchProcedure_Stretch(const WAUTSwitchProcedure_Stretch&);
783 
784         /// @brief Invalidated assignment operator.
785         WAUTSwitchProcedure_Stretch& operator=(const WAUTSwitchProcedure_Stretch&);
786 
787     };
788 
789 
790     /**
791      * @struct WAUTSwitchProcess
792      * @brief An initialised switch process
793      */
794     struct WAUTSwitchProcess {
795         /// @brief The id of the junction to switch
796         std::string junction;
797         /// @brief The current program of the tls
798         MSTrafficLightLogic* from;
799         /// @brief The program to switch the tls to
800         MSTrafficLightLogic* to;
801         /// @brief The used procedure
802         WAUTSwitchProcedure* proc;
803     };
804 
805 
806     /// @brief A map of ids to corresponding WAUTs
807     std::map<std::string, WAUT*> myWAUTs;
808 
809     /// @brief A list of currently running switching procedures
810     std::vector<WAUTSwitchProcess> myCurrentlySwitched;
811 
812     /// @brief A map from ids to the corresponding variants
813     std::map<std::string, TLSLogicVariants*> myLogics;
814 
815     /// @brief Information whether the net was completely loaded
816     bool myNetWasLoaded;
817 
818 
819 private:
820     /// @brief Invalidated copy constructor.
821     MSTLLogicControl(const MSTLLogicControl&);
822 
823     /// @brief Invalidated assignment operator.
824     MSTLLogicControl& operator=(const MSTLLogicControl&);
825 
826 };
827 
828 
829 #endif
830 
831 /****************************************************************************/
832 
833