LCOV - code coverage report
Current view: top level - src/microsim/cfmodels - MSCFModel_Kerner.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 92.9 % 28 26
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_Kerner.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Laura Bieker
      17              : /// @author  Michael Behrisch
      18              : /// @date    03.04.2010
      19              : ///
      20              : // car-following model by B. Kerner
      21              : // Implementation based on "B. S. Kerner, S. L. Klenov, A. Brakemeier, Testbed for Wireless Vehicle Communication: a
      22              : // Simulation Approach based on Three-Phase Traffic Theory"
      23              : // https://arxiv.org/abs/0712.2711
      24              : /****************************************************************************/
      25              : #include <config.h>
      26              : 
      27              : #include <microsim/MSVehicle.h>
      28              : #include <microsim/MSLane.h>
      29              : #include "MSCFModel_Kerner.h"
      30              : #include <utils/common/RandHelper.h>
      31              : 
      32              : 
      33              : // ===========================================================================
      34              : // method definitions
      35              : // ===========================================================================
      36          227 : MSCFModel_Kerner::MSCFModel_Kerner(const MSVehicleType* vtype) :
      37              :     MSCFModel(vtype),
      38          227 :     myK(vtype->getParameter().getCFParam(SUMO_ATTR_K, 0.5)),
      39          227 :     myPhi(vtype->getParameter().getCFParam(SUMO_ATTR_CF_KERNER_PHI, 5.0)),
      40          227 :     myTauDecel(myDecel * myHeadwayTime) {
      41              :     // Kerner does not drive very precise and may violate minGap on occasion
      42          227 :     myCollisionMinGapFactor = vtype->getParameter().getCFParam(SUMO_ATTR_COLLISION_MINGAP_FACTOR, 0.1);
      43          227 : }
      44              : 
      45              : 
      46          454 : MSCFModel_Kerner::~MSCFModel_Kerner() {}
      47              : 
      48              : 
      49              : double
      50      4304818 : MSCFModel_Kerner::finalizeSpeed(MSVehicle* const veh, double vPos) const {
      51      4304818 :     const double vNext = MSCFModel::finalizeSpeed(veh, vPos);
      52              :     VehicleVariables* vars = (VehicleVariables*)veh->getCarFollowVariables();
      53      4304818 :     vars->rand = RandHelper::rand(veh->getRNG());
      54      4304818 :     return vNext;
      55              : }
      56              : 
      57              : 
      58              : double
      59     29718276 : MSCFModel_Kerner::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double /*predMaxDecel*/, const MSVehicle* const /*pred*/, const CalcReason /*usage*/) const {
      60     29718276 :     return MIN2(_v(veh, speed, maxNextSpeed(speed, veh), gap, predSpeed), maxNextSpeed(speed, veh));
      61              : }
      62              : 
      63              : 
      64              : double
      65     12284357 : MSCFModel_Kerner::stopSpeed(const MSVehicle* const veh, const double speed, double gap, double /*decel*/, const CalcReason /*usage*/) const {
      66     12284357 :     return MIN2(_v(veh, speed, maxNextSpeed(speed, veh), gap, 0), maxNextSpeed(speed, veh));
      67              : }
      68              : 
      69              : 
      70              : MSCFModel::VehicleVariables*
      71         6829 : MSCFModel_Kerner::createVehicleVariables() const {
      72         6829 :     VehicleVariables* ret = new VehicleVariables();
      73              :     /// XXX should use egoVehicle->getRNG()
      74         6829 :     ret->rand = RandHelper::rand();
      75         6829 :     return ret;
      76              : }
      77              : 
      78              : 
      79              : double
      80     42002633 : MSCFModel_Kerner::_v(const MSVehicle* const veh, double speed, double vfree, double gap, double predSpeed) const {
      81     42002633 :     if (predSpeed == 0 && gap < 0.01) {
      82              :         return 0;
      83              :     }
      84              :     // !!! in the following, the prior step is not considered!!!
      85     41927897 :     double G = MAX2((double) 0, (double)(SPEED2DIST(myK * speed) + myPhi / myAccel * speed * (speed - predSpeed)));
      86     50429467 :     double vcond = gap > G ? speed + ACCEL2SPEED(myAccel) : speed + MAX2(ACCEL2SPEED(-myDecel), MIN2(ACCEL2SPEED(myAccel), predSpeed - speed));
      87     41927897 :     double vsafe = (double)(-1. * myTauDecel + sqrt(myTauDecel * myTauDecel + (predSpeed * predSpeed) + (2. * myDecel * gap)));
      88              :     VehicleVariables* vars = (VehicleVariables*)veh->getCarFollowVariables();
      89     41927897 :     double va = MAX2((double) 0, MIN3(vfree, vsafe, vcond)) + vars->rand;
      90              :     //std::cout << SIMTIME << " veh=" << veh->getID() << " speed=" << speed << " gap=" << gap << " G=" << G << " predSpeed=" << predSpeed << " vfree=" << vfree << " vsafe=" << vsafe << " vcond=" << vcond << " rand=" << vars->rand << "\n";
      91     41927897 :     double v = MAX2((double) 0, MIN4(vfree, va, speed + ACCEL2SPEED(myAccel), vsafe));
      92              :     return v;
      93              : }
      94              : 
      95              : 
      96              : MSCFModel*
      97            0 : MSCFModel_Kerner::duplicate(const MSVehicleType* vtype) const {
      98            0 :     return new MSCFModel_Kerner(vtype);
      99              : }
        

Generated by: LCOV version 2.0-1