LCOV - code coverage report
Current view: top level - src/microsim/cfmodels - MSCFModel_IDM.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 66.7 % 6 4
Test Date: 2024-12-21 15:45:41 Functions: 50.0 % 2 1

            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_IDM.h
      15              : /// @author  Tobias Mayer
      16              : /// @author  Daniel Krajzewicz
      17              : /// @author  Michael Behrisch
      18              : /// @date    Thu, 03 Sep 2009
      19              : ///
      20              : // The Intelligent Driver Model (IDM) car-following model
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : #include "MSCFModel.h"
      26              : #include <microsim/MSLane.h>
      27              : #include <microsim/MSVehicle.h>
      28              : #include <microsim/MSVehicleType.h>
      29              : #include <utils/xml/SUMOXMLDefinitions.h>
      30              : 
      31              : 
      32              : // ===========================================================================
      33              : // class definitions
      34              : // ===========================================================================
      35              : /** @class MSCFModel_IDM
      36              :  * @brief The Intelligent Driver Model (IDM) car-following model
      37              :  * @see MSCFModel
      38              :  */
      39              : class MSCFModel_IDM : public MSCFModel {
      40              : public:
      41              :     /** @brief Constructor
      42              :      *  @param[in] vtype the type for which this model is built and also the parameter object to configure this model
      43              :      *  @param[in] idmm Wether IDM or IDMM shall be built
      44              :      */
      45              :     MSCFModel_IDM(const MSVehicleType* vtype, bool idmm);
      46              : 
      47              : 
      48              :     /** @brief Constructor
      49              :      * @param[in] accel The maximum acceleration
      50              :      * @param[in] decel The maximum deceleration
      51              :      * @param[in] emergencyDecel The maximum emergency deceleration
      52              :      * @param[in] apparentDecel The deceleration as expected by others
      53              :      * @param[in] headwayTime the headway gap
      54              :      * @param[in] adaptationFactor a model constant
      55              :      * @param[in] adaptationTime a model constant
      56              :      * @param[in] internalStepping internal time step size
      57              :      */
      58              :     MSCFModel_IDM(const MSVehicleType* vtype, double accel, double decel, double emergencyDecel, double apparentDecel,
      59              :                   double headwayTime, double adaptationFactor, double adaptationTime,
      60              :                   double internalStepping);
      61              : 
      62              : 
      63              :     /// @brief Destructor
      64              :     ~MSCFModel_IDM();
      65              : 
      66              : 
      67              :     /// @name Implementations of the MSCFModel interface
      68              :     /// @{
      69              : 
      70              :     /** @brief Applies interaction with stops and lane changing model influences
      71              :      * @param[in] veh The ego vehicle
      72              :      * @param[in] vPos The possible velocity
      73              :      * @return The velocity after applying interactions with stops and lane change model influences
      74              :      */
      75              :     double finalizeSpeed(MSVehicle* const veh, double vPos) const;
      76              : 
      77              :     /** @brief Computes the vehicle's safe speed without a leader
      78              :      *
      79              :      * Returns the velocity of the vehicle in dependence to the length of the free street and the target
      80              :      *  velocity at the end of the free range. If onInsertion is true, the vehicle may still brake
      81              :      *  before the next movement.
      82              :      * @param[in] veh The vehicle (EGO)
      83              :      * @param[in] speed The vehicle's speed
      84              :      * @param[in] seen The look ahead distance
      85              :      * @param[in] maxSpeed The maximum allowed speed
      86              :      * @param[in] onInsertion whether speed at insertion is asked for
      87              :      * @return EGO's safe speed
      88              :      */
      89              :     virtual double freeSpeed(const MSVehicle* const veh, double speed, double seen,
      90              :                              double maxSpeed, const bool onInsertion = false, const CalcReason usage = CalcReason::CURRENT) const;
      91              : 
      92              :     /** @brief Computes the vehicle's safe speed (no dawdling)
      93              :      * @param[in] veh The vehicle (EGO)
      94              :      * @param[in] speed The vehicle's speed
      95              :      * @param[in] gap2pred The (net) distance to the LEADER
      96              :      * @param[in] predSpeed The speed of LEADER
      97              :      * @return EGO's safe speed
      98              :      * @see MSCFModel::ffeV
      99              :      */
     100              :     double followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed,
     101              :                        double predMaxDecel, const MSVehicle* const pred = 0, const CalcReason usage = CalcReason::CURRENT) const;
     102              : 
     103              : 
     104              :     /** @brief Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
     105              :      * @param[in] veh The vehicle (EGO)
     106              :      * @param[in] gap2pred The (net) distance to the obstacle
     107              :      * @return EGO's safe speed for approaching a non-moving obstacle
     108              :      * @see MSCFModel::ffeS
     109              :      * @todo generic Interface, models can call for the values they need
     110              :      */
     111              :     double stopSpeed(const MSVehicle* const veh, const double speed, double gap, double decel, const CalcReason usage = CalcReason::CURRENT) const;
     112              : 
     113              : 
     114              :     /** @brief Returns the maximum gap at which an interaction between both vehicles occurs
     115              :      *
     116              :      * "interaction" means that the LEADER influences EGO's speed.
     117              :      * @param[in] veh The EGO vehicle
     118              :      * @param[in] vL LEADER's speed
     119              :      * @return The interaction gap
     120              :      * @todo evaluate signature
     121              :      * @see MSCFModel::interactionGap
     122              :      */
     123              :     double interactionGap(const MSVehicle* const, double vL) const;
     124              : 
     125              : 
     126              :     /** @brief Computes the vehicle's safe speed (no dawdling)
     127              :      * This method is used during the insertion stage. Whereas the method
     128              :      * followSpeed returns the desired speed which may be lower than the safe
     129              :      * speed, this method only considers safety constraints
     130              :      *
     131              :      * Returns the velocity of the vehicle in dependence to the vehicle's and its leader's values and the distance between them.
     132              :      * @param[in] veh The vehicle (EGO)
     133              :      * @param[in] speed The vehicle's speed
     134              :      * @param[in] gap2pred The (net) distance to the LEADER
     135              :      * @param[in] predSpeed The speed of LEADER
     136              :      * @return EGO's safe speed
     137              :      */
     138              :     double insertionFollowSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const;
     139              : 
     140              :     /** @brief Computes the vehicle's safe speed for approaching an obstacle at insertion without constraints
     141              :      *         due to acceleration capabilities and previous speeds.
     142              :      * @param[in] veh The vehicle (EGO)
     143              :      * @param[in] speed The vehicle's speed
     144              :      * @param[in] gap The (net) distance to the obstacle
     145              :      * @return EGO's safe speed for approaching a non-moving obstacle at insertion
     146              :      * @see stopSpeed() and insertionFollowSpeed()
     147              :      *
     148              :      */
     149              :     double insertionStopSpeed(const MSVehicle* const veh, double speed, double gap) const;
     150              : 
     151              :     /** @brief Returns the minimum gap to reserve if the leader is braking at maximum (>=0)
     152              :      * @param[in] veh The vehicle itself, for obtaining other values
     153              :      * @param[in] pred The leader vehicle, for obtaining other values
     154              :      * @param[in] speed EGO's speed
     155              :      * @param[in] leaderSpeed LEADER's speed
     156              :      * @param[in] leaderMaxDecel LEADER's max. deceleration rate
     157              :      */
     158              :     double getSecureGap(const MSVehicle* const veh, const MSVehicle* const pred, const double speed, const double leaderSpeed, const double leaderMaxDecel) const;
     159              : 
     160              :     /** @brief Returns the model's name
     161              :      * @return The model's name
     162              :      * @see MSCFModel::getModelName
     163              :      */
     164            0 :     int getModelID() const {
     165            0 :         return myAdaptationFactor == 1. ? SUMO_TAG_CF_IDM : SUMO_TAG_CF_IDMM;
     166              :     }
     167              : 
     168              :     double minNextSpeed(double speed, const MSVehicle* const veh = 0) const;
     169              :     /// @}
     170              : 
     171              : 
     172              : 
     173              :     /** @brief Duplicates the car-following model
     174              :      * @param[in] vtype The vehicle type this model belongs to (1:1)
     175              :      * @return A duplicate of this car-following model
     176              :      */
     177              :     MSCFModel* duplicate(const MSVehicleType* vtype) const;
     178              : 
     179              : 
     180       273421 :     VehicleVariables* createVehicleVariables() const {
     181       273421 :         if (myAdaptationFactor != 1.) {
     182         6877 :             return new VehicleVariables();
     183              :         }
     184              :         return 0;
     185              :     }
     186              : 
     187              : 
     188              : private:
     189              :     class VehicleVariables : public MSCFModel::VehicleVariables {
     190              :     public:
     191         6877 :         VehicleVariables() : levelOfService(1.) {}
     192              :         /// @brief state variable for remembering speed deviation history (lambda)
     193              :         double levelOfService;
     194              :     };
     195              : 
     196              : 
     197              : private:
     198              :     double _v(const MSVehicle* const veh, const double gap2pred, const double mySpeed,
     199              :               const double predSpeed, const double desSpeed, const bool respectMinGap = true) const;
     200              : 
     201              : 
     202              : private:
     203              :     /// @brief whether the model is IDMM or IDM
     204              :     const bool myIDMM;
     205              : 
     206              :     /// @brief The IDM delta exponent
     207              :     const double myDelta;
     208              : 
     209              :     /// @brief The IDMM adaptation factor beta
     210              :     const double myAdaptationFactor;
     211              : 
     212              :     /// @brief The IDMM adaptation time tau
     213              :     const double myAdaptationTime;
     214              : 
     215              :     /// @brief The number of iterations in speed calculations
     216              :     const int myIterations;
     217              : 
     218              :     /// @brief A computational shortcut
     219              :     const double myTwoSqrtAccelDecel;
     220              : 
     221              : private:
     222              :     /// @brief Invalidated assignment operator
     223              :     MSCFModel_IDM& operator=(const MSCFModel_IDM& s);
     224              : };
        

Generated by: LCOV version 2.0-1