Eclipse SUMO - Simulation of Urban MObility
MSCFModel_Kerner.cpp
Go to the documentation of this file.
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 /****************************************************************************/
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"
31 
32 
33 // ===========================================================================
34 // method definitions
35 // ===========================================================================
37  MSCFModel(vtype),
38  myK(vtype->getParameter().getCFParam(SUMO_ATTR_K, 0.5)),
39  myPhi(vtype->getParameter().getCFParam(SUMO_ATTR_CF_KERNER_PHI, 5.0)),
40  myTauDecel(myDecel * myHeadwayTime) {
41  // Kerner does not drive very precise and may violate minGap on occasion
43 }
44 
45 
47 
48 
49 double
50 MSCFModel_Kerner::finalizeSpeed(MSVehicle* const veh, double vPos) const {
51  const double vNext = MSCFModel::finalizeSpeed(veh, vPos);
53  vars->rand = RandHelper::rand(veh->getRNG());
54  return vNext;
55 }
56 
57 
58 double
59 MSCFModel_Kerner::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double /*predMaxDecel*/, const MSVehicle* const /*pred*/, const CalcReason /*usage*/) const {
60  return MIN2(_v(veh, speed, maxNextSpeed(speed, veh), gap, predSpeed), maxNextSpeed(speed, veh));
61 }
62 
63 
64 double
65 MSCFModel_Kerner::stopSpeed(const MSVehicle* const veh, const double speed, double gap, double /*decel*/, const CalcReason /*usage*/) const {
66  return MIN2(_v(veh, speed, maxNextSpeed(speed, veh), gap, 0), maxNextSpeed(speed, veh));
67 }
68 
69 
74  ret->rand = RandHelper::rand();
75  return ret;
76 }
77 
78 
79 double
80 MSCFModel_Kerner::_v(const MSVehicle* const veh, double speed, double vfree, double gap, double predSpeed) const {
81  if (predSpeed == 0 && gap < 0.01) {
82  return 0;
83  }
84  // !!! in the following, the prior step is not considered!!!
85  double G = MAX2((double) 0, (double)(SPEED2DIST(myK * speed) + myPhi / myAccel * speed * (speed - predSpeed)));
86  double vcond = gap > G ? speed + ACCEL2SPEED(myAccel) : speed + MAX2(ACCEL2SPEED(-myDecel), MIN2(ACCEL2SPEED(myAccel), predSpeed - speed));
87  double vsafe = (double)(-1. * myTauDecel + sqrt(myTauDecel * myTauDecel + (predSpeed * predSpeed) + (2. * myDecel * gap)));
89  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  double v = MAX2((double) 0, MIN4(vfree, va, speed + ACCEL2SPEED(myAccel), vsafe));
92  return v;
93 }
94 
95 
96 MSCFModel*
98  return new MSCFModel_Kerner(vtype);
99 }
#define SPEED2DIST(x)
Definition: SUMOTime.h:45
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:51
@ SUMO_ATTR_CF_KERNER_PHI
@ SUMO_ATTR_COLLISION_MINGAP_FACTOR
@ SUMO_ATTR_K
T MIN4(T a, T b, T c, T d)
Definition: StdDefs.h:103
T MIN3(T a, T b, T c)
Definition: StdDefs.h:89
T MIN2(T a, T b)
Definition: StdDefs.h:76
T MAX2(T a, T b)
Definition: StdDefs.h:82
SumoRNG * getRNG() const
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
~MSCFModel_Kerner()
Destructor.
double myTauDecel
The precomputed value for myDecel*myTau.
double myPhi
Kerner's phi.
double _v(const MSVehicle *const veh, double speed, double vfree, double gap, double predSpeed) const
Returns the "safe" velocity.
double stopSpeed(const MSVehicle *const veh, const double speed, double gap2pred, double decel, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed (no dawdling)
MSCFModel::VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting.
double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
MSCFModel_Kerner(const MSVehicleType *vtype)
Constructor.
The car-following model abstraction.
Definition: MSCFModel.h:55
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:292
virtual double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences. Called at most once per simulation...
Definition: MSCFModel.cpp:187
CalcReason
What the return value of stop/follow/free-Speed is used for.
Definition: MSCFModel.h:77
double myCollisionMinGapFactor
The factor of minGap that must be maintained to avoid a collision event.
Definition: MSCFModel.h:707
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition: MSCFModel.h:701
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition: MSCFModel.h:698
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
MSCFModel::VehicleVariables * getCarFollowVariables() const
Returns the vehicle's car following model variables.
Definition: MSVehicle.h:995
The car-following model and parameter.
Definition: MSVehicleType.h:63
const SUMOVTypeParameter & getParameter() const
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Definition: RandHelper.cpp:94
double getCFParam(const SumoXMLAttr attr, const double defaultValue) const
Returns the named value from the map, or the default if it is not contained there.