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