Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2013-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 MSDevice_GLOSA.h 15 : /// @author Jakob Erdmann 16 : /// @date 21.04.2021 17 : /// 18 : // A device for Green Light Optimal Speed Advisory 19 : /****************************************************************************/ 20 : #pragma once 21 : #include <config.h> 22 : 23 : #include "MSVehicleDevice.h" 24 : #include <utils/common/SUMOTime.h> 25 : 26 : 27 : // =========================================================================== 28 : // class declarations 29 : // =========================================================================== 30 : class SUMOTrafficObject; 31 : class MSLink; 32 : 33 : 34 : // =========================================================================== 35 : // class definitions 36 : // =========================================================================== 37 : /** 38 : * @class MSDevice_GLOSA 39 : * @brief A device which collects info on the vehicle trip (mainly on departure and arrival) 40 : * 41 : * Each device collects departure time, lane and speed and the same for arrival. 42 : * 43 : * @see MSDevice 44 : */ 45 : class MSDevice_GLOSA : public MSVehicleDevice { 46 : public: 47 : /** @brief Inserts MSDevice_GLOSA-options 48 : * @param[filled] oc The options container to add the options to 49 : */ 50 : static void insertOptions(OptionsCont& oc); 51 : 52 : 53 : /** @brief Build devices for the given vehicle, if needed 54 : * 55 : * The options are read and evaluated whether a example-device shall be built 56 : * for the given vehicle. 57 : * 58 : * The built device is stored in the given vector. 59 : * 60 : * @param[in] v The vehicle for which a device may be built 61 : * @param[filled] into The vector to store the built device in 62 : */ 63 : static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into); 64 : 65 : /// @brief resets counters 66 : static void cleanup(); 67 : 68 : public: 69 : /// @brief Destructor. 70 : ~MSDevice_GLOSA(); 71 : 72 : 73 : 74 : /// @name Methods called on vehicle movement / state change, overwriting MSDevice 75 : /// @{ 76 : 77 : /** @brief updates distance and computes speed advice 78 : * 79 : * @param[in] veh Vehicle that asks this reminder. 80 : * @param[in] oldPos Position before move. 81 : * @param[in] newPos Position after move with newSpeed. 82 : * @param[in] newSpeed Moving speed. 83 : * 84 : * @return True (always). 85 : */ 86 : bool notifyMove(SUMOTrafficObject& veh, double oldPos, 87 : double newPos, double newSpeed); 88 : 89 : 90 : /** @brief updates next tls link 91 : * 92 : * @param[in] veh The entering vehicle. 93 : * @param[in] reason how the vehicle enters the lane 94 : * @return Always true 95 : * @see MSMoveReminder::notifyEnter 96 : * @see MSMoveReminder::Notification 97 : */ 98 : bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0); 99 : 100 : 101 : /// @} 102 : 103 : 104 : /// @brief return the name for this type of device 105 0 : const std::string deviceName() const { 106 0 : return "glosa"; 107 : } 108 : 109 : /// @brief try to retrieve the given parameter from this device. Throw exception for unsupported key 110 : std::string getParameter(const std::string& key) const; 111 : 112 : /// @brief try to set the given parameter for this device. Throw exception for unsupported key 113 : void setParameter(const std::string& key, const std::string& value); 114 : 115 : /** @brief Called on writing tripinfo output 116 : * 117 : * @param[in] os The stream to write the information into 118 : * @exception IOError not yet implemented 119 : * @see MSDevice::generateOutput 120 : */ 121 : void generateOutput(OutputDevice* tripinfoOut) const; 122 : 123 : 124 : 125 : private: 126 : 127 : /// @brief compute time to next (relevant) switch 128 : static double getTimeToSwitch(const MSLink* tlsLink); 129 : 130 : /// @brief return minimum number of seconds to reach the junction 131 : double earliest_arrival(double speed, double distance); 132 : 133 : /// @brief return maximum number of seconds to reach the junction 134 : double latest_arrival(double speed, double distance, double earliest); 135 : 136 : double distance_at_continuous_accel(double speed, double time); 137 : 138 : double time_to_junction_at_continuous_accel(double d, double v); 139 : 140 : /// @brief adapt speed to reach junction at green 141 : void adaptSpeed(double distance, double timeToJunction, double timeToSwitch); 142 : 143 : /** @brief Constructor 144 : * 145 : * @param[in] holder The vehicle that holds this device 146 : * @param[in] id The ID of the device 147 : */ 148 : MSDevice_GLOSA(SUMOVehicle& holder, const std::string& id, double minSpeed, double range, double maxSpeedFactor); 149 : 150 : 151 : 152 : private: 153 : /// @brief myHolder cast to needed type 154 : MSVehicle& myVeh; 155 : 156 : /// @brief the upcoming traffic light 157 : const MSLink* myNextTLSLink; 158 : /// @brief the distance to the upcoming traffic light 159 : double myDistance; 160 : 161 : /// @brief minimum approach speed towards red light 162 : double myMinSpeed; 163 : /// @brief maximum communication range 164 : double myRange; 165 : /// @brief maximum speed factor when trying to reach green light 166 : double myMaxSpeedFactor; 167 : 168 : /// @brief original speed factor 169 : double myOriginalSpeedFactor; 170 : 171 : 172 : private: 173 : /// @brief Invalidated copy constructor. 174 : MSDevice_GLOSA(const MSDevice_GLOSA&); 175 : 176 : /// @brief Invalidated assignment operator. 177 : MSDevice_GLOSA& operator=(const MSDevice_GLOSA&); 178 : 179 : 180 : };