Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2002-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 MSDelayBasedTrafficLightLogic.h
15 : /// @author Leonhard Luecken
16 : /// @date Feb 2017
17 : ///
18 : // An actuated traffic light logic based on time delay of approaching vehicles
19 : /****************************************************************************/
20 : #pragma once
21 : #include <config.h>
22 :
23 : #include <map>
24 : #include "MSSimpleTrafficLightLogic.h"
25 :
26 :
27 : // ===========================================================================
28 : // class declarations
29 : // ===========================================================================
30 : class NLDetectorBuilder;
31 : class MSE2Collector;
32 :
33 :
34 : // ===========================================================================
35 : // class definitions
36 : // ===========================================================================
37 : /**
38 : * @class MSDelayBasedTrafficLightLogic
39 : * @brief An actuated traffic light logic based on time delay of approaching vehicles
40 : * @todo Validate against the original algorithm's details.
41 : * @note The current phase is not prolonged if the passing time of the next approaching vehicle
42 : * is larger than the remaining greentime (in contrast to the original algorithm)
43 : * @note The maximal green time can be exceeded if no vehicles are present on other approaches;
44 : */
45 : class MSDelayBasedTrafficLightLogic : public MSSimpleTrafficLightLogic {
46 : public:
47 : /** @brief Constructor
48 : * @param[in] tlcontrol The tls control responsible for this tls
49 : * @param[in] id This tls' id
50 : * @param[in] programID This tls' sub-id (program id)
51 : * @param[in] phases Definitions of the phases
52 : * @param[in] step The initial phase index
53 : * @param[in] delay The time to wait before the first switch
54 : * @param[in] parameter The parameter to use for tls set-up
55 : */
56 : MSDelayBasedTrafficLightLogic(MSTLLogicControl& tlcontrol,
57 : const std::string& id, const std::string& programID,
58 : const SUMOTime offset,
59 : const MSSimpleTrafficLightLogic::Phases& phases,
60 : int step, SUMOTime delay,
61 : const Parameterised::Map& parameter,
62 : const std::string& basePath);
63 :
64 :
65 : /** @brief Initializes the tls with information about incoming lanes
66 : * @param[in] nb The detector builder
67 : * @exception ProcessError If something fails on initialization
68 : */
69 : void init(NLDetectorBuilder& nb) override;
70 :
71 :
72 : /// @brief Destructor
73 : ~MSDelayBasedTrafficLightLogic();
74 :
75 :
76 :
77 : /// @name Switching and setting current rows
78 : /// @{
79 :
80 : /** @brief Switches to the next phase, if possible
81 : * @return The time of the next switch
82 : * @see MSTrafficLightLogic::trySwitch
83 : */
84 : SUMOTime trySwitch() override;
85 : /// @}
86 :
87 : bool showDetectors() const {
88 0 : return myShowDetectors;
89 : }
90 :
91 : void setShowDetectors(bool show);
92 :
93 : /// @brief retrieve all detectors used by this program
94 : std::map<std::string, double> getDetectorStates() const override;
95 :
96 : /// @brief retrieve a specific detector used by this program
97 : double getDetectorState(const std::string laneID) const override;
98 :
99 : /// @brief return the estimated queue length at the upcoming traffic light
100 : double getTLQueueLength(const std::string laneID) const override;
101 :
102 :
103 : protected:
104 : /// @name "actuated" algorithm methods
105 : /// @{
106 :
107 : /**
108 : * @brief Checks for approaching vehicles on the lanes associated with green signals
109 : * and returns the minimal time to keep the green phase going.
110 : * This is zero if no vehicle on the lane has gathered any waiting time
111 : * or if the green time is exhausted (maximal green time has passed since switch).
112 : * @return Minimal remaining green time.
113 : */
114 : SUMOTime checkForWaitingTime();
115 :
116 : /**
117 : * @brief The returned, proposed prolongation for the green phase is oriented on the
118 : * largest estimated passing time among the vehicles with waiting time.
119 : * @param actDuration Duration of the current phase
120 : * @param maxDuration Maximal duration of the current phase
121 : * @param[in/out] othersEmpty Whether there are vehicles on another approach, which is not part of a green signal group for the current phase
122 : * @return The proposed prolongation time for the current phase
123 : */
124 : SUMOTime proposeProlongation(const SUMOTime actDuration, const SUMOTime maxDuration, bool& othersEmpty);
125 :
126 : protected:
127 : /// A map from lanes to the corresponding lane detectors
128 : std::map<const MSLane*, MSE2Collector*> myLaneDetectors;
129 :
130 : /// Range of the connected detector, which provides the information on approaching vehicles
131 : double myDetectionRange;
132 :
133 : /// If a vehicle's timeloss is below myTimeLossThreshold, this is counted as insignificant,
134 : /// since this may stem from dawdling, or driving only slightly slower than the maximal velocity on the lane.
135 : // (Idea: this might be adapted to the detector-length and the vehicle's maximal speed)
136 : double myTimeLossThreshold;
137 :
138 : /// Whether the detectors shall be shown in the GUI
139 : bool myShowDetectors;
140 :
141 : /// The output file for generated detectors
142 : std::string myFile;
143 :
144 : /// The frequency for aggregating detector output
145 : SUMOTime myFreq;
146 :
147 : /// Whether detector output separates by vType
148 : std::string myVehicleTypes;
149 :
150 : /// Whether phases may be extended beyond maxDur in the absence of traffic
151 : bool myExtendMaxDur;
152 : };
|