LCOV - code coverage report
Current view: top level - src/microsim/devices - MSDevice_GLOSA.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 20.0 % 5 1
Test Date: 2024-11-22 15:46:21 Functions: 0.0 % 1 0

            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 Returns the precomputed, original factor by which the driver
     110              :                wants to be faster than the speed limit
     111              :      * @return Speed limit factor
     112              :      */
     113              :     inline double getOriginalSpeedFactor() const {
     114            0 :         return myOriginalSpeedFactor;
     115              :     }
     116              : 
     117              :     /** @brief Returns if the traffic light stop calculation of the CF model shall be ignored
     118              :      * @return Override stop calculation before traffic light
     119              :      */
     120              :     inline bool getOverrideSafety() const {
     121          508 :         return myOverrideSafety;
     122              :     }
     123              : 
     124              :     /** @brief Returns if the GLOSA device is currently changing the speedFactor
     125              :      * @return If speedFactor has been changed by GLOSA
     126              :      */
     127              :     inline bool isSpeedAdviceActive() const {
     128            0 :         return mySpeedAdviceActive;
     129              :     }
     130              : 
     131              :     /// @brief try to retrieve the given parameter from this device. Throw exception for unsupported key
     132              :     std::string getParameter(const std::string& key) const;
     133              : 
     134              :     /// @brief try to set the given parameter for this device. Throw exception for unsupported key
     135              :     void setParameter(const std::string& key, const std::string& value);
     136              : 
     137              :     /** @brief Called on writing tripinfo output
     138              :      *
     139              :      * @param[in] os The stream to write the information into
     140              :      * @exception IOError not yet implemented
     141              :      * @see MSDevice::generateOutput
     142              :      */
     143              :     void generateOutput(OutputDevice* tripinfoOut) const;
     144              : 
     145              : 
     146              : 
     147              : private:
     148              : 
     149              :     /// @brief compute time to next (relevant) switch
     150              :     static double getTimeToSwitch(const MSLink* tlsLink, int& countOld);
     151              : 
     152              :     /// @brief compute time to next (relevant) switch the vehicle can reach
     153              :     static double getTimeToNextSwitch(const MSLink* tlsLink, bool &currentPhaseGreen, bool &currentPhaseStop, int& countOld);
     154              : 
     155              :     static double timeGreen(const MSLink* tlsLink);
     156              : 
     157              :     /// @brief return minimum number of seconds to reach the junction
     158              :     double earliest_arrival(double speed, double distance);
     159              : 
     160              :     /// @brief return maximum number of seconds to reach the junction
     161              :     double latest_arrival(double speed, double distance, double earliest);
     162              : 
     163              :     double distance_at_continuous_accel(double speed, double time);
     164              : 
     165              :     double time_to_junction_at_continuous_accel(double d, double v);
     166              : 
     167              :     /// @brief adapt speed to reach junction at green
     168              :     void adaptSpeed(double distance, double timeToJunction, double timeToSwitch, bool &solved);
     169              : 
     170              :     /** @brief Constructor
     171              :      *
     172              :      * @param[in] holder The vehicle that holds this device
     173              :      * @param[in] id The ID of the device
     174              :      */
     175              :     MSDevice_GLOSA(SUMOVehicle& holder, const std::string& id, double minSpeed, double range, double maxSpeedFactor,
     176              :         double addSwitchTime, bool useQueue,  bool overrideSafety, bool ignoreCFModel);
     177              : 
     178              : 
     179              : 
     180              : private:
     181              :     /// @brief myHolder cast to needed type
     182              :     MSVehicle& myVeh;
     183              : 
     184              :     /// @brief the upcoming traffic light
     185              :     const MSLink* myNextTLSLink;
     186              :     /// @brief the distance to the upcoming traffic light
     187              :     double myDistance;
     188              : 
     189              :     /// @brief minimum approach speed towards red light
     190              :     double myMinSpeed;
     191              :     /// @brief maximum communication range
     192              :     double myRange;
     193              :     /// @brief maximum speed factor when trying to reach green light
     194              :     double myMaxSpeedFactor;
     195              :     /// @brief Additional time the vehicle shall need to reach the intersection after the signal turns green
     196              :     double myAddSwitchTime;
     197              :     /// @brief if true ignore the current light state, always follow GLOSA's predicted state
     198              :     bool myOverrideSafety;
     199              :     /// @brief if true ignore non-critical speed calculations from the CF model, follow GLOSA's perfect speed calculation
     200              :     bool myIgnoreCFModel;
     201              : 
     202              :     /// @brief original speed factor
     203              :     double myOriginalSpeedFactor;
     204              : 
     205              :     /// @brief If speedFactor is currently beeing changed by the GLOSA device
     206              :     bool mySpeedAdviceActive;
     207              :     /// @brief if true the queue in front of the TLS is used for calculation
     208              :     bool  myUseQueue;
     209              : 
     210              : 
     211              : private:
     212              :     /// @brief Invalidated copy constructor.
     213              :     MSDevice_GLOSA(const MSDevice_GLOSA&);
     214              : 
     215              :     /// @brief Invalidated assignment operator.
     216              :     MSDevice_GLOSA& operator=(const MSDevice_GLOSA&);
     217              : 
     218              : 
     219              : };
        

Generated by: LCOV version 2.0-1