LCOV - code coverage report
Current view: top level - src/microsim/cfmodels - MSCFModel_KraussOrig1.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 93.8 % 32 30
Test Date: 2024-12-21 15:45:41 Functions: 88.9 % 9 8

            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_KraussOrig1.cpp
      15              : /// @author  Tobias Mayer
      16              : /// @author  Daniel Krajzewicz
      17              : /// @author  Jakob Erdmann
      18              : /// @author  Michael Behrisch
      19              : /// @author  Laura Bieker
      20              : /// @date    Mon, 04 Aug 2009
      21              : ///
      22              : // The original Krauss (1998) car-following model and parameter
      23              : /****************************************************************************/
      24              : #include <config.h>
      25              : 
      26              : #include <microsim/MSVehicle.h>
      27              : #include <microsim/MSLane.h>
      28              : #include "MSCFModel_KraussOrig1.h"
      29              : #include <microsim/lcmodels/MSAbstractLaneChangeModel.h>
      30              : #include <utils/common/RandHelper.h>
      31              : #include <microsim/MSGlobals.h>
      32              : 
      33              : // ===========================================================================
      34              : // DEBUG constants
      35              : // ===========================================================================
      36              : //#define DEBUG_COND (veh->getID()=="disabled")
      37              : 
      38              : // ===========================================================================
      39              : // method definitions
      40              : // ===========================================================================
      41       310582 : MSCFModel_KraussOrig1::MSCFModel_KraussOrig1(const MSVehicleType* vtype) :
      42              :     MSCFModel(vtype),
      43       310582 :     myDawdle(vtype->getParameter().getCFParam(SUMO_ATTR_SIGMA, SUMOVTypeParameter::getDefaultImperfection(vtype->getParameter().vehicleClass))),
      44       310582 :     myTauDecel(myDecel * myHeadwayTime) {
      45       310582 : }
      46              : 
      47              : 
      48       292906 : MSCFModel_KraussOrig1::~MSCFModel_KraussOrig1() {}
      49              : 
      50              : double
      51      5835313 : MSCFModel_KraussOrig1::patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
      52              :     UNUSED_PARAMETER(veh);
      53      5835313 :     const double vDawdle = MAX2(vMin, dawdle(vMax, veh->getRNG()));
      54      5835313 :     return vDawdle;
      55              : }
      56              : 
      57              : 
      58              : double
      59     34222427 : MSCFModel_KraussOrig1::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double predMaxDecel, const MSVehicle* const /*pred*/, const CalcReason /*usage*/) const {
      60     34222427 :     if (MSGlobals::gSemiImplicitEulerUpdate) {
      61     33434192 :         return MIN2(vsafe(gap, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)); // XXX: and why not cap with minNextSpeed!? (Leo)
      62              :     } else {
      63       788235 :         return MAX2(MIN2(maximumSafeFollowSpeed(gap, speed, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)), minNextSpeed(speed));
      64              :     }
      65              : }
      66              : 
      67              : 
      68              : double
      69     14934473 : MSCFModel_KraussOrig1::stopSpeed(const MSVehicle* const veh, const double speed, double gap, double decel, const CalcReason /*usage*/) const {
      70     14934473 :     if (MSGlobals::gSemiImplicitEulerUpdate) {
      71     14171160 :         return MIN2(vsafe(gap, 0., 0.), maxNextSpeed(speed, veh));
      72              :     } else {
      73              :         // XXX: using this here is probably in the spirit of Krauss, but we should consider,
      74              :         // if the original vsafe should be kept instead (Leo), refs. #2575
      75       763313 :         return MIN2(maximumSafeStopSpeedBallistic(gap, decel, speed), maxNextSpeed(speed, veh));
      76              :     }
      77              : }
      78              : 
      79              : 
      80              : double
      81      5835313 : MSCFModel_KraussOrig1::dawdle(double speed, SumoRNG* rng) const {
      82      5835313 :     if (!MSGlobals::gSemiImplicitEulerUpdate) {
      83              :         // in case of the ballistic update, negative speeds indicate
      84              :         // a desired stop before the completion of the next timestep.
      85              :         // We do not allow dawdling to overwrite this indication
      86       389449 :         if (speed < 0) {
      87              :             return speed;
      88              :         }
      89              :     }
      90      5826208 :     return MAX2(0., speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand(rng)));
      91              : }
      92              : 
      93              : 
      94              : /** Returns the SK-vsafe. */
      95     47605352 : double MSCFModel_KraussOrig1::vsafe(double gap, double predSpeed, double /* predMaxDecel */) const {
      96     47605352 :     if (predSpeed == 0 && gap < 0.01) {
      97              :         return 0;
      98     47435898 :     } else if (predSpeed == 0 &&  gap <= ACCEL2SPEED(myDecel)) {
      99              :         // workaround for #2310
     100      1549697 :         return MIN2(ACCEL2SPEED(myDecel), DIST2SPEED(gap));
     101              :     }
     102              :     double vsafe = (double)(-1. * myTauDecel
     103     45886201 :                             + sqrt(
     104     45886201 :                                 myTauDecel * myTauDecel
     105     45886201 :                                 + (predSpeed * predSpeed)
     106     45886201 :                                 + (2. * myDecel * gap)
     107     45886201 :                             ));
     108              :     assert(vsafe >= 0);
     109     45886201 :     return vsafe;
     110              : }
     111              : 
     112              : 
     113              : MSCFModel*
     114            0 : MSCFModel_KraussOrig1::duplicate(const MSVehicleType* vtype) const {
     115            0 :     return new MSCFModel_KraussOrig1(vtype);
     116              : }
     117              : 
     118              : 
     119              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1