LCOV - code coverage report
Current view: top level - src/microsim/cfmodels - MSCFModel_EIDM.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 90.0 % 20 18
Test Date: 2024-12-21 15:45:41 Functions: 80.0 % 5 4

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-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    MSCFModel_EIDM.h
      15              : /// @author  Dominik Salles
      16              : /// @date    Fri, 06 Jul 2018
      17              : 
      18              : /// Originalfile MSCFModel_IDM.cpp from
      19              : /// @author  Tobias Mayer
      20              : /// @author  Daniel Krajzewicz
      21              : /// @author  Michael Behrisch
      22              : /// @date    Thu, 03 Sep 2009
      23              : ///
      24              : // The Extended Intelligent Driver Model (EIDM) car-following model
      25              : //
      26              : // Publication: Salles, Dominik, S. Kaufmann and H. Reuss. “Extending the Intelligent Driver
      27              : // Model in SUMO and Verifying the Drive Off Trajectories with Aerial
      28              : // Measurements.” (2020).
      29              : /****************************************************************************/
      30              : #ifndef MSCFMODEL_EIDM_H
      31              : #define MSCFMODEL_EIDM_H
      32              : 
      33              : // ===========================================================================
      34              : // included modules
      35              : // ===========================================================================
      36              : #include <config.h>
      37              : 
      38              : #include "MSCFModel.h"
      39              : #include <microsim/MSLane.h>
      40              : #include <microsim/MSVehicle.h>
      41              : #include <microsim/MSVehicleType.h>
      42              : #include <microsim/lcmodels/MSAbstractLaneChangeModel.h>
      43              : #include <utils/xml/SUMOXMLDefinitions.h>
      44              : 
      45              : 
      46              : // ===========================================================================
      47              : // class definitions
      48              : // ===========================================================================
      49              : /** @class MSCFModel_EIDM
      50              :  * @brief The Extended Intelligent Driver Model (EIDM) car-following model
      51              :  * @see MSCFModel
      52              :  */
      53              : class MSCFModel_EIDM : public MSCFModel {
      54              : public:
      55              :     /** @brief Constructor
      56              :      *  @param[in] vtype the type for which this model is built and also the parameter object to configure this model
      57              :      */
      58              :     MSCFModel_EIDM(const MSVehicleType* vtype);
      59              : 
      60              :     /// @brief Destructor
      61              :     ~MSCFModel_EIDM();
      62              : 
      63              :     /// @name Implementations of the MSCFModel interface
      64              :     /// @{
      65              : 
      66              :     /** @brief Computes the vehicle's safe speed (no dawdling)
      67              :      * This method is used during the insertion stage. Whereas the method
      68              :      * followSpeed returns the desired speed which may be lower than the safe
      69              :      * speed, this method only considers safety constraints
      70              :      *
      71              :      * Returns the velocity of the vehicle in dependence to the vehicle's and its leader's values and the distance between them.
      72              :      * @param[in] veh The vehicle (EGO)
      73              :      * @param[in] speed The vehicle's speed
      74              :      * @param[in] gap2pred The (net) distance to the LEADER
      75              :      * @param[in] predSpeed The speed of LEADER
      76              :      * @return EGO's safe speed
      77              :      */
      78              :     double insertionFollowSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const;
      79              : 
      80              : 
      81              :     /** @brief Computes the vehicle's safe speed for approaching an obstacle at insertion without constraints
      82              :      *         due to acceleration capabilities and previous speeds.
      83              :      * @param[in] veh The vehicle (EGO)
      84              :      * @param[in] speed The vehicle's speed
      85              :      * @param[in] gap The (net) distance to the obstacle
      86              :      * @return EGO's safe speed for approaching a non-moving obstacle at insertion
      87              :      * @see stopSpeed() and insertionFollowSpeed()
      88              :      *
      89              :      */
      90              :     double insertionStopSpeed(const MSVehicle* const veh, double speed, double gap) const;
      91              : 
      92              : 
      93              :     /** @brief Returns the maximum safe velocity for following the given leader
      94              :      * @param[in] gap2pred The (net) distance to the LEADER
      95              :      * @param[in] egoSpeed The FOLLOWERS's speed
      96              :      * @param[in] predSpeed The LEADER's speed
      97              :      * @param[in] predMaxDecel The LEADER's maximum deceleration
      98              :      * @param[in] onInsertion Indicator whether the call is triggered during vehicle insertion
      99              :      * @return the safe velocity
     100              :      */
     101              :     double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion = false, const CalcReason usage = CalcReason::CURRENT) const;
     102              : 
     103              : 
     104              :     /** @brief Returns the maximum next velocity for stopping within gap
     105              :      * @param[in] gap The (net) distance to the desired stopping point
     106              :      * @param[in] currentSpeed The current speed of the ego vehicle
     107              :      * @param[in] onInsertion Indicator whether the call is triggered during vehicle insertion
     108              :      * @param[in] headway The desired time headway to be included in the calculations (default argument -1 induces the use of myHeadway)
     109              :      */
     110              :     double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion = false, double headway = -1) const;
     111              : 
     112              : 
     113              :     /** @brief Applies interaction with stops and lane changing model influences
     114              :      * @param[in] veh The ego vehicle
     115              :      * @param[in] vPos The possible velocity
     116              :      * @return The velocity after applying interactions with stops and lane change model influences
     117              :      */
     118              :     double finalizeSpeed(MSVehicle* const veh, double vPos) const;
     119              : 
     120              : 
     121              :     /** @brief Computes the vehicle's safe speed
     122              :      * @param[in] veh The vehicle (EGO)
     123              :      * @param[in] speed The vehicle's speed
     124              :      * @param[in] gap2pred The (net) distance to the LEADER
     125              :      * @param[in] predSpeed The speed of LEADER
     126              :      * @return EGO's safe speed
     127              :      * @see MSCFModel::ffeV
     128              :      */
     129              :     double followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed,
     130              :                        double predMaxDecel, const MSVehicle* const pred = 0, const CalcReason usage = CalcReason::CURRENT) const;
     131              : 
     132              : 
     133              :     /** @brief Computes the vehicle's safe speed for approaching a non-moving obstacle
     134              :      * @param[in] veh The vehicle (EGO)
     135              :      * @param[in] gap2pred The (net) distance to the obstacle
     136              :      * @return EGO's safe speed for approaching a non-moving obstacle
     137              :      * @see MSCFModel::ffeS
     138              :      * @todo generic Interface, models can call for the values they need
     139              :      */
     140              :     double stopSpeed(const MSVehicle* const veh, const double speed, double gap, double decel, const CalcReason usage = CalcReason::CURRENT) const;
     141              : 
     142              : 
     143              :     /** @brief Computes the vehicle's safe speed without a leader
     144              :      *
     145              :      * Returns the velocity of the vehicle in dependence to the length of the free street and the target
     146              :      *  velocity at the end of the free range. If onInsertion is true, the vehicle may still brake
     147              :      *  before the next movement.
     148              :      * @param[in] veh The vehicle (EGO)
     149              :      * @param[in] speed The vehicle's speed
     150              :      * @param[in] seen The look ahead distance
     151              :      * @param[in] maxSpeed The maximum allowed speed
     152              :      * @param[in] onInsertion whether speed at insertion is asked for
     153              :      * @return EGO's safe speed
     154              :      */
     155              :     double freeSpeed(const MSVehicle* const veh, double speed, double seen,
     156              :                      double maxSpeed, const bool onInsertion = false, const CalcReason usage = CalcReason::CURRENT) const;
     157              : 
     158              :     static double freeSpeed(const double currentSpeed, const double decel, const double dist, const double maxSpeed, const bool onInsertion);
     159              : 
     160              :     /** @brief Returns the maximum gap at which an interaction between both vehicles occurs
     161              :      *
     162              :      * "interaction" means that the LEADER influences EGO's speed.
     163              :      * @param[in] veh The EGO vehicle
     164              :      * @param[in] vL LEADER's speed
     165              :      * @return The interaction gap
     166              :      * @todo evaluate signature
     167              :      * @see MSCFModel::interactionGap
     168              :      */
     169              :     double interactionGap(const MSVehicle* const, double vL) const;
     170              : 
     171              :     /** @brief Returns the minimum gap to reserve if the leader is braking at maximum (>=0)
     172              :       * @param[in] speed EGO's speed
     173              :       * @param[in] leaderSpeed LEADER's speed
     174              :       * @param[in] leaderMaxDecel LEADER's max. deceleration rate
     175              :       */
     176              :     double getSecureGap(const MSVehicle* const veh, const MSVehicle* const /*pred*/, const double speed, const double leaderSpeed, const double leaderMaxDecel) const;
     177              : 
     178              :     /** @brief Returns the distance the vehicle needs to halt including driver's reaction time tau (i.e. desired headway),
     179              :      * assuming that during the reaction time, the speed remains constant
     180              :      * @param[in] speed The vehicle's current speed
     181              :      * @return The distance needed to halt
     182              :      */
     183     48879820 :     double brakeGap(const double speed, const double decel, const double headwayTime) const {
     184     48879820 :         if (MSGlobals::gComputeLC) {
     185       244220 :             return MSCFModel::brakeGap(speed, decel, headwayTime);
     186              :         } else {
     187              :             // myDecel + 1.0 does not work correctly with the junction model and impatience > 0.
     188              :             // Vehicles may first be disregarded because their own arrivalTimeBraking is high (TIME2STEPS(30)).
     189              :             // This is amplified by this brakeGap-Term, because they "think" they could still brake in time (low brakeGap),
     190              :             // but actually 1.0 was only added for braking at traffic lights. But then when seen < brakeGap(v) happens (see MSVehicle: arrivalTimeBraking),
     191              :             // they realize, that they will soon arrive at the junction and other vehicles are notified to maybe then brake hard!
     192     97271200 :             return MSCFModel::brakeGap(speed, MAX2(decel, myDecel + 1.0), headwayTime);
     193              :         }
     194              :     }
     195              : 
     196              :     /** @brief Returns the maximum speed given the current speed and regarding driving dynamics
     197              :      * @param[in] speed The vehicle's current speed
     198              :      * @param[in] speed The vehicle itself, for obtaining other values
     199              :      * @return The maximum possible speed for the next step taking driving dynamics into account
     200              :      */
     201         4166 :     double maxNextSafeMin(double speed, const MSVehicle* const veh = 0) const {
     202              :         UNUSED_PARAMETER(speed);
     203              :         UNUSED_PARAMETER(veh);
     204         4166 :         return 0;
     205              :     }
     206              : 
     207              :     /** @brief Returns the maximum velocity the CF-model wants to achieve in the next step
     208              :      * @param[in] maxSpeed The maximum achievable speed in the next step
     209              :      * @param[in] maxSpeedLane The maximum speed the vehicle wants to drive on this lane (Speedlimit*SpeedFactor)
     210              :      */
     211      5752359 :     double maximumLaneSpeedCF(const MSVehicle* const /*veh*/, double maxSpeed, double /*maxSpeedLane*/) const {
     212      5752359 :         return maxSpeed;
     213              :     }
     214              : 
     215              :     /** @brief Returns the model's name
     216              :     * @return The model's name
     217              :     * @see MSCFModel::getModelName
     218              :     */
     219            0 :     int getModelID() const {
     220            0 :         return SUMO_TAG_CF_EIDM;
     221              :     }
     222              : 
     223              :     /** @brief Duplicates the car-following model
     224              :      * @param[in] vtype The vehicle type this model belongs to (1:1)
     225              :      * @return A duplicate of this car-following model
     226              :      */
     227              :     MSCFModel* duplicate(const MSVehicleType* vtype) const;
     228              : 
     229              :     // @brief Variables that are stored throughout a call to the car-following functions
     230         6985 :     VehicleVariables* createVehicleVariables() const {
     231         6985 :         VehicleVariables* ret = new VehicleVariables();
     232         6985 :         ret->minaccel = 100;
     233         6985 :         ret->wouldacc = 100;
     234              :         ret->lastacc = 0;
     235         6985 :         ret->realacc = 100;
     236              :         ret->lastrealacc = 0;
     237         6985 :         ret->realleaderacc = 100;
     238              :         ret->lastleaderacc = 0;
     239              :         ret->v0_int = 0;
     240              :         ret->v0_old = 0;
     241         6985 :         ret->t_off = -10.;
     242              :         ret->myw_gap = 0.;
     243              :         ret->myw_speed = 0.;
     244              :         ret->myw_error = 0.;
     245              :         ret->myv_est_l = 0.;
     246              :         ret->myv_est = 0.;
     247              :         ret->mys_est = 0.;
     248         6985 :         ret->myrespectMinGap = true;
     249              :         ret->myap_update = 0;
     250         6985 :         return ret;
     251              :     }
     252              : 
     253              : 
     254              : private:
     255         6985 :     class VehicleVariables : public MSCFModel::VehicleVariables {
     256              :     public:
     257              :         double minaccel; // @brief saves the intended accel-value between multiple stopSpeed/followSpeed calls to then check which call actually updated the vehicles acceleration (accel-value is without coolness and drive-off)
     258              :         double wouldacc; // @brief saves the intended accel-value the CF-model would output, if there is no reaction time (accel-value is without coolness and drive-off)
     259              :         double lastacc; // @brief saves the intended accel-value when the driver was last updated (reaction time) (accel-value is without coolness and drive-off)
     260              :         double realacc; // @brief saves the resulting accel-value between multiple stopSpeed/followSpeed calls that the CF-model will eventually output
     261              :         double lastrealacc; // @brief saves the resulting accel-value the CF-model eventually outputted when the driver was last updated (reaction time)
     262              :         double realleaderacc; // @brief saves the leader accel-value from the call that resulted in the new speed
     263              :         double lastleaderacc; // @brief saves the leader accel-value from the call that resulted in the new speed when the driver was last updated (reaction time)
     264              :         double v0_int; // @brief is the internal desired speed of the vehicle
     265              :         double v0_old; // @brief is the previous desired speed of the vehicle needed for calculation purpose
     266              :         double t_off; // @brief is the time when the vehicle starts driving off
     267              :         double myw_gap; // @brief is the Wiener Process for the gap error calculation
     268              :         double myw_speed; // @brief is the Wiener Process for the speed error calculation
     269              :         double myw_error; // @brief is the Wiener Process for the driving error calculation
     270              :         double myv_est_l; // @brief saves the speed of the leading vehicle / 0 for a stop at the last driver update (reaction time)
     271              :         double myv_est; // @brief saves the speed of the vehicle at the last driver update (reaction time)
     272              :         double mys_est; // @brief saves the gap to leading vehicle / next stop at the last driver update (reaction time)
     273              :         bool myrespectMinGap; // @brief saves the information, if minGap was added to the desired gap s* at the last driver update (reaction time)
     274              :         int myap_update; // @brief is a number counting the simulation steps since the last driver/vehicle update (reaction time)
     275              :         std::vector<std::pair<double, double>> stop; // @brief saves the intended accelerations and distances from all stopSpeed-calculations of the current time step
     276              :     };
     277              : 
     278              : private:
     279              : 
     280              :     /** @brief Applies dawdling / driving error
     281              :     * @param[in] veh The ego vehicle
     282              :     * @param[in] vMin The minimum possible speed in the next time step
     283              :     * @param[in] vMax The wanted speed in the next time step
     284              :     * @return The corrected speed with dawdling / driving error
     285              :     */
     286              :     double patchSpeedBeforeLCEIDM(const MSVehicle* veh, double vMin, double vMax, const VehicleVariables* vars) const;
     287              : 
     288              :     // @brief calculates the slow to start term when driving off
     289              :     double slowToStartTerm(MSVehicle* const veh, const double newSpeed, const double currentSpeed, const double vMax, VehicleVariables* vars) const;
     290              : 
     291              :     // @brief contains the main CF-model calculations
     292              :     double _v(const MSVehicle* const veh, const double gap2pred, const double mySpeed,
     293              :               const double predSpeed, const double desSpeed, const bool respectMinGap, const int update, const CalcReason usage) const;
     294              : 
     295              :     // @brief calculates the internal desired speed for the vehicle depending on myTpreview and upcoming turns, intersections and speed limit changes
     296              :     void internalspeedlimit(MSVehicle* const veh, const double oldV) const;
     297              : 
     298              :     // @brief calculates the SecureGap similar to the MSCFModel-SecureGap-function, yet adding a targetDecel to decelerate with
     299              :     double internalsecuregap(const MSVehicle* const veh, const double speed, const double leaderSpeed, const double targetDecel) const;
     300              : 
     301              : private:
     302              :     // @brief The IDM delta exponent
     303              :     const double myDelta;
     304              : 
     305              :     // @brief A computational shortcut
     306              :     const double myTwoSqrtAccelDecel;
     307              : 
     308              :     // @brief The number of iterations in speed calculations
     309              :     const int myIterations;
     310              : 
     311              :     // @brief Correlation time of the Wiener Process for the driving error
     312              :     const double myTPersDrive;
     313              : 
     314              :     // @brief The maximal reaction time
     315              :     const double myTreaction;
     316              : 
     317              :     // @brief The preview distance time for the desired speed
     318              :     const double myTpreview;
     319              : 
     320              :     // @brief Correlation time of the Wiener Process for the estimation errors
     321              :     const double myTPersEstimate;
     322              : 
     323              :     // @brief Coolness Parameter of the Enhanced Intelligent Driver Model
     324              :     const double myCcoolness;
     325              : 
     326              :     // @brief Estimation error magnitude of the leading vehicle's speed
     327              :     const double mySigmaleader;
     328              : 
     329              :     // @brief Estimation error magnitude of the distance to the leading vehicle / next stop
     330              :     const double mySigmagap;
     331              : 
     332              :     // @brief Driving error magnitude
     333              :     const double mySigmaerror;
     334              : 
     335              :     // @brief Maximal jerk value
     336              :     const double myJerkmax;
     337              : 
     338              :     // @brief Maximal negative acceleration value before reacting instantaneously to the change in intended acceleration
     339              :     const double myEpsilonacc;
     340              : 
     341              :     // @brief Time until the maximal acceleration when driving off
     342              :     const double myTaccmax;
     343              : 
     344              :     // @brief Flatness of the drive off acceleration term
     345              :     const double myMflatness;
     346              : 
     347              :     // @brief Shift of the drive off acceleration term
     348              :     const double myMbegin;
     349              : 
     350              :     // @brief 1=simulate with the acceleration depending on the vehicle dynamics, 0=don't
     351              :     const bool myUseVehDynamics;
     352              : 
     353              :     // @brief number of vehicles in front, that are used to update the acceleration
     354              :     //const int myMaxVehPreview;
     355              : 
     356              : private:
     357              :     /// @brief Invalidated assignment operator
     358              :     MSCFModel_EIDM& operator=(const MSCFModel_EIDM& s);
     359              : };
     360              : 
     361              : #endif /* MSCFMODEL_EIDM_H */
        

Generated by: LCOV version 2.0-1