SUMO - Simulation of Urban MObility
MSCFModel_Kerner.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // car-following model by B. Kerner
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <microsim/MSVehicle.h>
34 #include <microsim/MSLane.h>
35 #include "MSCFModel_Kerner.h"
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
43  double decel, double emergencyDecel, double headwayTime, double k, double phi) :
44  MSCFModel(vtype, accel, decel, emergencyDecel, decel, headwayTime), myK(k), myPhi(phi),
45  myTauDecel(decel * headwayTime) {
46 }
47 
48 
50 
51 
52 double
53 MSCFModel_Kerner::moveHelper(MSVehicle* const veh, double vPos) const {
54  const double vNext = MSCFModel::moveHelper(veh, vPos);
56  vars->rand = RandHelper::rand();
57  return vNext;
58 }
59 
60 
61 double
62 MSCFModel_Kerner::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double /*predMaxDecel*/) const {
63  return MIN2(_v(veh, speed, maxNextSpeed(speed, veh), gap, predSpeed), maxNextSpeed(speed, veh));
64 }
65 
66 
67 double
68 MSCFModel_Kerner::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
69  return MIN2(_v(veh, speed, maxNextSpeed(speed, veh), gap, 0), maxNextSpeed(speed, veh));
70 }
71 
72 
76  ret->rand = RandHelper::rand();
77  return ret;
78 }
79 
80 
81 double
82 MSCFModel_Kerner::_v(const MSVehicle* const veh, double speed, double vfree, double gap, double predSpeed) const {
83  if (predSpeed == 0 && gap < 0.01) {
84  return 0;
85  }
86  // !!! in the following, the prior step is not considered!!!
87  double G = MAX2((double) 0, (double)(SPEED2DIST(myK * speed) + myPhi / myAccel * speed * (speed - predSpeed)));
88  double vcond = gap > G ? speed + ACCEL2SPEED(myAccel) : speed + MAX2(ACCEL2SPEED(-myDecel), MIN2(ACCEL2SPEED(myAccel), predSpeed - speed));
89  double vsafe = (double)(-1. * myTauDecel + sqrt(myTauDecel * myTauDecel + (predSpeed * predSpeed) + (2. * myDecel * gap)));
91  double va = MAX2((double) 0, MIN3(vfree, vsafe, vcond)) + vars->rand;
92  double v = MAX2((double) 0, MIN4(vfree, va, speed + ACCEL2SPEED(myAccel), vsafe));
93  return v;
94 }
95 
96 
97 MSCFModel*
100 }
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:805
#define SPEED2DIST(x)
Definition: SUMOTime.h:55
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
T MIN4(T a, T b, T c, T d)
Definition: StdDefs.h:91
The car-following model abstraction.
Definition: MSCFModel.h:60
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:193
double myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:466
T MAX2(T a, T b)
Definition: StdDefs.h:70
virtual double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel.cpp:147
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:74
MSCFModel::VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting...
static double rand()
Returns a random real number in [0, 1)
Definition: RandHelper.h:62
T MIN2(T a, T b)
Definition: StdDefs.h:64
double myPhi
Kerner&#39;s phi.
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:469
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:471
MSCFModel_Kerner(const MSVehicleType *vtype, double accel, double decel, double emergencyDecel, double headwayTime, double k, double phi)
Constructor.
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:77
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:476
#define G
~MSCFModel_Kerner()
Destructor.