Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 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 set current program upon loading saved state
125 : void switchToLoaded(MSTrafficLightLogic* tl);
126 :
127 : /* @brief get logic by programID. For the special case "off"
128 : * instantiate an MSOffTrafficLightLogic */
129 : MSTrafficLightLogic* getLogicInstantiatingOff(MSTLLogicControl& tlc,
130 : const std::string& programID);
131 :
132 : /* @brief sets the state to the given string get for the special program "online"
133 : * this program is instantiated only once */
134 : void setStateInstantiatingOnline(MSTLLogicControl& tlc,
135 : const std::string& state);
136 :
137 :
138 : void executeOnSwitchActions() const;
139 : void addLink(MSLink* link, MSLane* lane, int pos);
140 : void ignoreLinkIndex(int pos);
141 :
142 : private:
143 : /// @brief The currently used program
144 : MSTrafficLightLogic* myCurrentProgram;
145 :
146 : /// @brief The program that would be used in the absence of TraCI
147 : MSTrafficLightLogic* myDefaultProgram;
148 :
149 : /// @brief A map of subkeys to programs
150 : std::map<std::string, MSTrafficLightLogic*> myVariants;
151 :
152 : /// @brief Originally loaded link states
153 : std::map<MSLink*, LinkState> myOriginalLinkStates;
154 :
155 : /// @brief The list of actions/commands to execute on switch
156 : std::vector<OnSwitchAction*> mySwitchActions;
157 :
158 : private:
159 : /// @brief Invalidated copy constructor.
160 : TLSLogicVariants(const TLSLogicVariants&);
161 :
162 : /// @brief Invalidated assignment operator.
163 : TLSLogicVariants& operator=(const TLSLogicVariants&);
164 :
165 :
166 : };
167 :
168 :
169 : /// @brief Constructor
170 : MSTLLogicControl();
171 :
172 : /// @brief Destructor
173 : ~MSTLLogicControl();
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 : /** @brief Lets all running (current) tls programs apply their current signal states to links they control
195 : * @param[in] t The current time
196 : * @see MSTrafficLightLogic::setTrafficLightSignals
197 : * @see LinkState
198 : * @see MSLink::setTLState
199 : */
200 : void setTrafficLightSignals(SUMOTime t) const;
201 :
202 : /** @brief Returns a vector which contains all logics
203 : *
204 : * All logics are included, active (current) and non-active
205 : * @return A vector containing all loaded logics
206 : */
207 : std::vector<MSTrafficLightLogic*> getAllLogics() const;
208 :
209 : /** @brief Returns the variants of a named tls
210 : *
211 : * @param[in] id The id of the tls to get variants of
212 : * @return The variants of the named tls
213 : * @exception InvalidArgument
214 : */
215 : TLSLogicVariants& get(const std::string& id) const;
216 :
217 : /** @brief Returns a single program (variant) defined by the tls id and the program programID
218 : *
219 : * @param[in] id The id of the tls to get program of
220 : * @param[in] programID The program id of the tls program to get
221 : * @return The defined tls program if existing, 0 otherwise
222 : */
223 : MSTrafficLightLogic* get(const std::string& id, const std::string& programID) const;
224 :
225 : /** @brief Returns the active program of a named tls
226 : *
227 : * @param[in] id The id of the tls to get the active program of
228 : * @return The current program of the defined tls if existing, 0 otherwise
229 : */
230 : MSTrafficLightLogic* getActive(const std::string& id) const;
231 :
232 : /**
233 : * Returns the ids of all existing variants-structures, wich are the ids of their
234 : * contained tls logics (not the logic's programm-ids)
235 : * @return the list of ids
236 : */
237 : std::vector<std::string> getAllTLIds() const;
238 :
239 : /** @brief Adds a tls program to the container
240 : *
241 : * If a tls with the given id is not yet known, a TLSLogicVariants structure
242 : * is built for this tls and added to the internal container and the tls
243 : * program is used as the new default.
244 : *
245 : * If the tls to add is loaded from an additional file (indicated by myNetWasLoaded,
246 : * see closeNetworkReading), links from previously loaded tls are adapted to the logic.
247 : * This may throw a ProcessError in the case no tls program was loaded for this
248 : * tls before (was not defined in the network). In case of an error the logic gets deleted.
249 : *
250 : * The parameter newDefault defines whether this program will be used as the new
251 : * default program of this tls. This means that an existing tls program for this
252 : * tls is replaced within the according TLSLogicVariants structure.
253 : *
254 : * @param[in] id The id of the tls (program) to add
255 : * @param[in] programID The program id of the tls (program) to add
256 : * @param[in] logic The tls logic to insert
257 : * @exception ProcessError In the case an additional tls program is loaded and no one for the tls existed in the network
258 : * @return true if the tls program could be added, false otherwise
259 : */
260 : bool add(const std::string& id, const std::string& programID,
261 : MSTrafficLightLogic* logic, bool newDefault = true);
262 :
263 : /** @brief Returns the information whether the named tls is stored
264 : * @param[in] id The id of the tls to ask for
265 : * @return Whether a tls with the given id is known
266 : */
267 : bool knows(const std::string& id) const;
268 :
269 : /** @brief Returns whether the given tls program is the currently active for his tls
270 : * @param[in] tl The tls to ask for
271 : * @return Whether the given tl is currently active (or a different program is used)
272 : */
273 : bool isActive(const MSTrafficLightLogic* tl) const;
274 :
275 : /** @brief Switches the named (id) tls to the named (programID) program
276 : *
277 : * The program with the used programID must be previously added.
278 : * If the tls itself or the program to switch to is not known, false is returned.
279 : * @param[in] id The id of the tls to switch to
280 : * @param[in] programID The program id of the tls (program) to switch to
281 : * @exception ProcessError If either the tls or the program to switch to is not known
282 : */
283 : void switchTo(const std::string& id, const std::string& programID);
284 :
285 : /// @name WAUT definition methods
286 : /// @{
287 :
288 : /** @brief Adds a WAUT definition
289 : *
290 : * Throws an InvalidArgument if the given id is already in use.
291 : * @param[in] refTime The reference time of the WAUT
292 : * @param[in] id The ID of the WAUT
293 : * @param[in] startProg The begin program of the WAUT
294 : * @param[in] period The period with which to repeat the switches
295 : * @exception InvalidArgument If the id is already used by another WAUT
296 : */
297 : void addWAUT(SUMOTime refTime, const std::string& id,
298 : const std::string& startProg, SUMOTime period);
299 :
300 :
301 : /** @brief Adds a WAUT switch step to a previously built WAUT
302 : *
303 : * Throws an InvalidArgument if the given WAUT id is not known.
304 : * @param[in] wautid The ID of the WAUT
305 : * @param[in] when The switch procedure begin
306 : * @param[in] to The program the WAUT shall start to switch to at the given time
307 : * @exception InvalidArgument If the named WAUT is not known
308 : */
309 : void addWAUTSwitch(const std::string& wautid, SUMOTime when,
310 : const std::string& to);
311 :
312 :
313 : /** @brief Adds a tls to the list of tls to be switched by the named WAUT
314 : *
315 : * Passes the values directly to the used tls control. This throws an InvalidArgument
316 : * if the given WAUT id or the given junction id is not known.
317 : * @param[in] wautid The ID of the WAUT
318 : * @param[in] tls The id of the tls to be switched
319 : * @param[in] proc The switching procedure to use
320 : * @param[in] synchron Whether the switching shall be done in synchron mode
321 : * @exception InvalidArgument If the named WAUT or the named tls are not known
322 : * @exception ProcessError If the initial switch fails
323 : */
324 : void addWAUTJunction(const std::string& wautid, const std::string& tls,
325 : const std::string& proc, bool synchron);
326 :
327 :
328 : /** @brief Closes loading of a WAUT
329 : *
330 : * Instantiates the first switch ("SwitchInitCommand") for the WAUT into the
331 : * network's simulation time step begin event control.
332 : * Throws an InvalidArgument if the given WAUT id is not known.
333 : *
334 : * @param[in] wautid The ID of the WAUT
335 : * @exception InvalidArgument If the named WAUT is not known
336 : * @see SwitchInitCommand
337 : */
338 : void closeWAUT(const std::string& wautid);
339 : /// @}
340 :
341 :
342 :
343 : /** @brief Checks whether any WAUT is trying to switch a tls into another program
344 : *
345 : * Called from MSNet::simulationStep
346 : */
347 : void check2Switch(SUMOTime step);
348 :
349 :
350 : /** @brief return the complete phase definition for a named traffic lights logic
351 : *
352 : * The phase definition will be the current of the currently active program of
353 : * the named tls.
354 : * @param[in] tlid The id of the tls to get the current phases of
355 : * @return A pair containing the current time and the current phases of the named tls
356 : */
357 : std::pair<SUMOTime, MSPhaseDefinition> getPhaseDef(const std::string& tlid) const;
358 :
359 : /// @brief switch all logic variants to 'off'
360 : void switchOffAll();
361 :
362 : /** @brief Saves the current tls states into the given stream
363 : */
364 : void saveState(OutputDevice& out);
365 :
366 : /** @brief Clear all tls states before quick-loading state */
367 : void clearState(SUMOTime time, bool quickReload = false);
368 :
369 :
370 :
371 : protected:
372 : /**
373 : * @class SwitchInitCommand
374 : * @brief This event-class is used to initialise a WAUT switch at a certain time.
375 : *
376 : * This command is reused. The index of the WAUT-switch is incremented at each
377 : * call to the control.
378 : */
379 : class SwitchInitCommand : public Command {
380 : public:
381 : /** @brief Constructor
382 : * @param[in] p The logic control
383 : * @param[in] wautid The id of the WAUT
384 : * @param[in] index The first position within the WAUT table
385 : */
386 : SwitchInitCommand(MSTLLogicControl& p, const std::string& wautid, int index)
387 156 : : myParent(p), myWAUTID(wautid), myIndex(index) { }
388 :
389 :
390 : /// @brief Destructor
391 156 : ~SwitchInitCommand() { }
392 :
393 :
394 :
395 : /// @name Derived from Command
396 : /// @{
397 :
398 : /** @brief Begins a WAUT switch by executing the command.
399 : *
400 : * The parent's "initWautSwitch" method is called supporting
401 : * this command as an argument. The result of "initWautSwitch"
402 : * is returned.
403 : *
404 : * "initWautSwitch" may throw an ProcessError if the program
405 : * to switch to is not known.
406 : *
407 : * @param[in] currentTime The current simulation time (unused)
408 : * @return The time after which the command shall be executed again
409 : * @exception ProcessError If the program to switch to does not exist
410 : * @see MSTLLogicControl::initWautSwitch
411 : */
412 288 : SUMOTime execute(SUMOTime) {
413 288 : return myParent.initWautSwitch(*this);
414 : }
415 : /// @}
416 :
417 :
418 :
419 : /** @brief Returns the WAUT-id
420 : * @return The WAUT id
421 : */
422 : const std::string& getWAUTID() const {
423 288 : return myWAUTID;
424 : }
425 :
426 :
427 : /** @brief Returns a reference to the index
428 : * @return A reference to the index
429 : */
430 : int& getIndex() {
431 : return myIndex;
432 : }
433 :
434 :
435 : protected:
436 : /// @brief The control to call
437 : MSTLLogicControl& myParent;
438 :
439 : /// @brief The id of the WAUT that shall switch
440 : std::string myWAUTID;
441 :
442 : /// @brief The current index within the WAUT switch table
443 : int myIndex;
444 :
445 :
446 : private:
447 : /// @brief Invalidated copy constructor.
448 : SwitchInitCommand(const SwitchInitCommand&);
449 :
450 : /// @brief Invalidated assignment operator.
451 : SwitchInitCommand& operator=(const SwitchInitCommand&);
452 :
453 : };
454 :
455 :
456 :
457 : public:
458 : /** @brief Initialises switching a WAUT
459 : *
460 : * This method is called from a previously built SwitchInitCommand
461 : * @param[in] The command which initialises the switch
462 : * @return The time offset to next call
463 : */
464 : SUMOTime initWautSwitch(SwitchInitCommand& cmd);
465 :
466 :
467 : protected:
468 : /** @struct WAUTSwitch
469 : * @brief Storage for a WAUTs switch point
470 : */
471 2120 : struct WAUTSwitch {
472 : /// @brief The time the WAUT shall switch the TLS
473 : SUMOTime when;
474 : /// @brief The program name the WAUT shall switch the TLS to
475 : std::string to;
476 : };
477 :
478 :
479 : /** @struct WAUTJunction
480 : * @brief Storage for a junction assigned to a WAUT
481 : */
482 164 : struct WAUTJunction {
483 : /// @brief The junction name
484 : std::string junction;
485 : /// @brief The procedure to switch the junction with
486 : std::string procedure;
487 : /// @brief Information whether this junction shall be switched synchron
488 : bool synchron;
489 : };
490 :
491 :
492 : /** @struct WAUT
493 : * @brief A WAUT definition
494 : */
495 : struct WAUT {
496 : /// @brief The id of the WAUT
497 : std::string id;
498 : /// @brief The name of the start program
499 : std::string startProg;
500 : /// @brief The reference time (offset to the switch times)
501 : SUMOTime refTime;
502 : /// @brief The period with which to repeat switches
503 : SUMOTime period;
504 : /// @brief The list of switches to be done by the WAUT
505 : std::vector<WAUTSwitch> switches;
506 : /// @brief The list of switches assigned to the WAUT
507 : std::vector<WAUTJunction> junctions;
508 : };
509 :
510 :
511 : /** @class WAUTSwitchProcedure
512 : * @brief This is the abstract base class for switching from one tls program to another.
513 : */
514 : class WAUTSwitchProcedure {
515 : public:
516 : /** @brief Constructor
517 : * @param[in] control The responsible tls control
518 : * @param[in] waut The WAUT to switch
519 : * @param[in] from The original tls program
520 : * @param[in] to The destination tls program
521 : * @param[in] synchron Whether the switch shall be done in synchronuous mode
522 : */
523 : WAUTSwitchProcedure(MSTLLogicControl& control, WAUT& waut,
524 : MSTrafficLightLogic* from, MSTrafficLightLogic* to,
525 : bool synchron)
526 0 : : myFrom(from), myTo(to), mySwitchSynchron(synchron), myWAUT(waut), myControl(control) { }
527 :
528 :
529 : /// @brief Destructor
530 0 : virtual ~WAUTSwitchProcedure() { }
531 :
532 :
533 : /** @brief Determines whether a switch is possible.
534 : * @param[in] step The current simulation step
535 : * @return If a switch shall be done, this method should return true.
536 : */
537 : virtual bool trySwitch(SUMOTime step);
538 :
539 :
540 : protected:
541 : /** @brief Checks, whether the position of a signal programm is at the GSP ("Good Switching Point")
542 : *
543 : * The GSP must be given as a logic's parameter ("GSP"). Not the simulation second,
544 : * but the phase the GSP lies within is used. If the phase the GSP lies within is
545 : * the same as the logic's current phase, the result is true.
546 : * @param[in] currentTime The current time step
547 : * @param[in] logic The logic for which this should be examined
548 : * @return Whether the current step is the GSP
549 : * @see getGSPValue
550 : */
551 : bool isPosAtGSP(SUMOTime currentTime, const MSTrafficLightLogic& logic);
552 :
553 : /** @brief Returns the difference between a given time and the start of the phase
554 : * @param[in] logic The logic to consider
555 : * @param[in] toTime The time to ask for
556 : * @return How much time elapsed between the last pahse start and the given time
557 : */
558 : SUMOTime getDiffToStartOfPhase(MSTrafficLightLogic& logic, SUMOTime toTime);
559 :
560 : /** @brief switches the given logic directly to the given position
561 : * @param[in] simStep The current simulation time
562 : * @param[in] logic The logic to switch
563 : * @param[in] toTime The time offset within the logic's phases to switch to
564 : */
565 : void switchToPos(SUMOTime simStep, MSTrafficLightLogic& logic, SUMOTime toTime);
566 :
567 : /** @brief Returns the GSP-value
568 : *
569 : * The GSP must be given as a logic's parameter ("GSP").
570 : * @param[in] logic The logic to retrieve the GSP from
571 : * @return The GSP value; 0 if not given.
572 : * @see MSTrafficLightLogic::getParameterValue
573 : */
574 : SUMOTime getGSPTime(const MSTrafficLightLogic& logic) const;
575 :
576 : /** @brief Changes the destination program's phase to which the tls was switched
577 : *
578 : * Default does nothing, implemented only in the subclasses.
579 : * @param[in] step The current simulation time
580 : */
581 0 : virtual void adaptLogic(SUMOTime step) {
582 : UNUSED_PARAMETER(step);
583 0 : }
584 :
585 : protected:
586 : /// @brief The current program of the tls to switch
587 : MSTrafficLightLogic* myFrom;
588 :
589 : /// @brief The program to switch the tls to
590 : MSTrafficLightLogic* myTo;
591 :
592 : /// @brief Information whether to switch synchron (?)
593 : bool mySwitchSynchron;
594 :
595 : /// @brief The WAUT responsible for switching
596 : WAUT& myWAUT;
597 :
598 : /// @brief The control the logic belongs to
599 : MSTLLogicControl& myControl;
600 :
601 :
602 : private:
603 : /// @brief Invalidated copy constructor.
604 : WAUTSwitchProcedure(const WAUTSwitchProcedure&);
605 :
606 : /// @brief Invalidated assignment operator.
607 : WAUTSwitchProcedure& operator=(const WAUTSwitchProcedure&);
608 :
609 : };
610 :
611 :
612 : /**
613 : * @class WAUTSwitchProcedure_JustSwitch
614 : * @brief This class simply switches to the next program
615 : */
616 : class WAUTSwitchProcedure_JustSwitch : public WAUTSwitchProcedure {
617 : public:
618 : /** @brief Constructor
619 : * @param[in] control The responsible tls control
620 : * @param[in] waut The WAUT to switch
621 : * @param[in] from The original tls program
622 : * @param[in] to The destination tls program
623 : * @param[in] synchron Whether the switch shall be done in synchronuous mode
624 : */
625 : WAUTSwitchProcedure_JustSwitch(MSTLLogicControl& control, WAUT& waut,
626 : MSTrafficLightLogic* from, MSTrafficLightLogic* to,
627 : bool synchron);
628 :
629 : /// @brief Destructor
630 : ~WAUTSwitchProcedure_JustSwitch();
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 :
640 :
641 :
642 : /**
643 : * @class WAUTSwitchProcedure_GSP
644 : * @brief This class switches using the GSP algorithm.
645 : */
646 : class WAUTSwitchProcedure_GSP : public WAUTSwitchProcedure {
647 : public:
648 : /** @brief Constructor
649 : * @param[in] control The responsible tls control
650 : * @param[in] waut The WAUT to switch
651 : * @param[in] from The original tls program
652 : * @param[in] to The destination tls program
653 : * @param[in] synchron Whether the switch shall be done in synchronuous mode
654 : */
655 : WAUTSwitchProcedure_GSP(MSTLLogicControl& control, WAUT& waut,
656 : MSTrafficLightLogic* from, MSTrafficLightLogic* to,
657 : bool synchron);
658 :
659 : /// @brief Destructor
660 : ~WAUTSwitchProcedure_GSP();
661 :
662 : protected:
663 : /** @brief Stretches the destination program's phase to which the tls was switched
664 : */
665 : void adaptLogic(SUMOTime step);
666 :
667 : };
668 :
669 :
670 : /**
671 : * @class WAUTSwitchProcedure_Stretch
672 : * @brief This class switches using the Stretch algorithm.
673 : */
674 : class WAUTSwitchProcedure_Stretch : public WAUTSwitchProcedure {
675 : public:
676 : /** @brief Constructor
677 : * @param[in] control The responsible tls control
678 : * @param[in] waut The WAUT to switch
679 : * @param[in] from The original tls program
680 : * @param[in] to The destination tls program
681 : * @param[in] synchron Whether the switch shall be done in synchronuous mode
682 : */
683 : WAUTSwitchProcedure_Stretch(MSTLLogicControl& control, WAUT& waut,
684 : MSTrafficLightLogic* from, MSTrafficLightLogic* to,
685 : bool synchron);
686 :
687 : /// @brief Destructor
688 : ~WAUTSwitchProcedure_Stretch();
689 :
690 : protected:
691 : /** @brief Determines the destination program's changes and applies them
692 : * @param[in] step The current simulation step
693 : * @see cutLogic
694 : * @see stretchLogic
695 : */
696 : void adaptLogic(SUMOTime step);
697 :
698 : /** @brief Stretches the logic to synchronize
699 : * @param[in] step The current simulation step
700 : * @param[in] startPos The position in the destination program to switch to
701 : * @param[in] allStretchTime The amount by which the logic shall be streched
702 : */
703 : void stretchLogic(SUMOTime step, SUMOTime startPos, SUMOTime allStretchTime);
704 :
705 : /** @brief Cuts the logic to synchronize
706 : * @param[in] step The current simulation step
707 : * @param[in] startPos The position in the destination program to switch to
708 : * @param[in] allCutTime The amount by which the logic shall be cut
709 : */
710 : void cutLogic(SUMOTime step, SUMOTime startPos, SUMOTime allCutTime);
711 :
712 : protected:
713 : /** @struct StretchRange
714 : * @brief A definition of a stretch - Bereich
715 : */
716 : struct StretchRange {
717 : /// @brief The begin of a stretch/cut area
718 : SUMOTime begin;
719 : /// @brief The end of a stretch/cut area
720 : SUMOTime end;
721 : /// @brief The weight factor of a stretch/cut area
722 : double fac;
723 : };
724 :
725 : protected:
726 : /// @brief the given Stretch-areas for the "to" program, this is 0-based indexed, while the input is 1-based
727 : std::vector<StretchRange> myStretchRanges;
728 : };
729 :
730 :
731 : /**
732 : * @struct WAUTSwitchProcess
733 : * @brief An initialised switch process
734 : */
735 572 : struct WAUTSwitchProcess {
736 : /// @brief The id of the junction to switch
737 : std::string junction;
738 : /// @brief The current program of the tls
739 : MSTrafficLightLogic* from;
740 : /// @brief The program to switch the tls to
741 : MSTrafficLightLogic* to;
742 : /// @brief The used procedure
743 : WAUTSwitchProcedure* proc;
744 : };
745 :
746 :
747 : /// @brief A map of ids to corresponding WAUTs
748 : std::map<std::string, WAUT*> myWAUTs;
749 :
750 : /// @brief A list of currently running switching procedures
751 : std::vector<WAUTSwitchProcess> myCurrentlySwitched;
752 :
753 : /// @brief A map from ids to the corresponding variants
754 : std::map<std::string, TLSLogicVariants*> myLogics;
755 :
756 : /// @brief Information whether the net was completely loaded
757 : bool myNetWasLoaded;
758 :
759 :
760 : private:
761 : /// @brief Invalidated copy constructor.
762 : MSTLLogicControl(const MSTLLogicControl&);
763 :
764 : /// @brief Invalidated assignment operator.
765 : MSTLLogicControl& operator=(const MSTLLogicControl&);
766 :
767 : };
|