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