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.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // car-following model by B. Kerner
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <microsim/MSVehicle.h>
33 #include <microsim/MSLane.h>
34 #include "MSCFModel_Kerner.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
42  double decel, double emergencyDecel, double apparentDecel,
43  double headwayTime, double k, double phi) :
44  MSCFModel(vtype, accel, decel, emergencyDecel, apparentDecel, headwayTime),
45  myK(k), myPhi(phi),
46  myTauDecel(decel * headwayTime) {
47 }
48 
49 
51 
52 
53 double
54 MSCFModel_Kerner::moveHelper(MSVehicle* const veh, double vPos) const {
55  const double vNext = MSCFModel::moveHelper(veh, vPos);
57  vars->rand = RandHelper::rand();
58  return vNext;
59 }
60 
61 
62 double
63 MSCFModel_Kerner::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double /*predMaxDecel*/) const {
64  return MIN2(_v(veh, speed, maxNextSpeed(speed, veh), gap, predSpeed), maxNextSpeed(speed, veh));
65 }
66 
67 
68 double
69 MSCFModel_Kerner::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
70  return MIN2(_v(veh, speed, maxNextSpeed(speed, veh), gap, 0), maxNextSpeed(speed, veh));
71 }
72 
73 
77  ret->rand = RandHelper::rand();
78  return ret;
79 }
80 
81 
82 double
83 MSCFModel_Kerner::_v(const MSVehicle* const veh, double speed, double vfree, double gap, double predSpeed) const {
84  if (predSpeed == 0 && gap < 0.01) {
85  return 0;
86  }
87  // !!! in the following, the prior step is not considered!!!
88  double G = MAX2((double) 0, (double)(SPEED2DIST(myK * speed) + myPhi / myAccel * speed * (speed - predSpeed)));
89  double vcond = gap > G ? speed + ACCEL2SPEED(myAccel) : speed + MAX2(ACCEL2SPEED(-myDecel), MIN2(ACCEL2SPEED(myAccel), predSpeed - speed));
90  double vsafe = (double)(-1. * myTauDecel + sqrt(myTauDecel * myTauDecel + (predSpeed * predSpeed) + (2. * myDecel * gap)));
92  double va = MAX2((double) 0, MIN3(vfree, vsafe, vcond)) + vars->rand;
93  double v = MAX2((double) 0, MIN4(vfree, va, speed + ACCEL2SPEED(myAccel), vsafe));
94  return v;
95 }
96 
97 
98 MSCFModel*
101 }
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
MSCFModel::VehicleVariables * getCarFollowVariables() const
Returns the vehicle&#39;s car following model variables.
Definition: MSVehicle.h:891
#define SPEED2DIST(x)
Definition: SUMOTime.h:54
double myApparentDecel
The vehicle&#39;s deceleration as expected by surrounding traffic [m/s^2].
Definition: MSCFModel.h:541
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:60
T MIN4(T a, T b, T c, T d)
Definition: StdDefs.h:94
The car-following model abstraction.
Definition: MSCFModel.h:59
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:64
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:204
double myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:534
T MAX2(T a, T b)
Definition: StdDefs.h:73
virtual double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel.cpp:155
double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
The car-following model and parameter.
Definition: MSVehicleType.h:72
MSCFModel::VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting...
T MIN2(T a, T b)
Definition: StdDefs.h:67
double myPhi
Kerner&#39;s phi.
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:537
MSCFModel_Kerner(const MSVehicleType *vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double headwayTime, double k, double phi)
Constructor.
double _v(const MSVehicle *const veh, double speed, double vfree, double gap, double predSpeed) const
Returns the "safe" velocity.
double myEmergencyDecel
The vehicle&#39;s maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:539
double myTauDecel
The precomputed value for myDecel*myTau.
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle&#39;s safe speed (no dawdling)
double stopSpeed(const MSVehicle *const veh, const double speed, double gap2pred) const
Computes the vehicle&#39;s safe speed for approaching a non-moving obstacle (no dawdling) ...
T MIN3(T a, T b, T c)
Definition: StdDefs.h:80
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:544
#define G
~MSCFModel_Kerner()
Destructor.