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-sim.org/
12 // Copyright (C) 2001-2014 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  SUMOReal decel, SUMOReal headwayTime, SUMOReal k, SUMOReal phi)
44  : MSCFModel(vtype, accel, decel, headwayTime), myK(k), myPhi(phi),
45  myTauDecel(decel* headwayTime) {
46 }
47 
48 
50 
51 
54  const SUMOReal vNext = MSCFModel::moveHelper(veh, vPos);
56  vars->rand = RandHelper::rand();
57  return vNext;
58 }
59 
60 
62 MSCFModel_Kerner::followSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap, SUMOReal predSpeed, SUMOReal /*predMaxDecel*/) const {
63  return MIN2(_v(veh, speed, maxNextSpeed(speed, veh), gap, predSpeed), maxNextSpeed(speed, veh));
64 }
65 
66 
68 MSCFModel_Kerner::stopSpeed(const MSVehicle* const veh, const SUMOReal speed, SUMOReal 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 
82 MSCFModel_Kerner::_v(const MSVehicle* const veh, SUMOReal speed, SUMOReal vfree, SUMOReal gap, SUMOReal predSpeed) const {
83  if (predSpeed == 0 && gap < 0.01) {
84  return 0;
85  }
86  // !!! in the following, the prior step is not considered!!!
87  SUMOReal G = MAX2((SUMOReal) 0, (SUMOReal)(SPEED2DIST(myK * speed) + myPhi / myAccel * speed * (speed - predSpeed)));
88  SUMOReal vcond = gap > G ? speed + ACCEL2SPEED(myAccel) : speed + MAX2(ACCEL2SPEED(-myDecel), MIN2(ACCEL2SPEED(myAccel), predSpeed - speed));
89  SUMOReal vsafe = (SUMOReal)(-1. * myTauDecel + sqrt(myTauDecel * myTauDecel + (predSpeed * predSpeed) + (2. * myDecel * gap)));
91  SUMOReal va = MAX2((SUMOReal) 0, MIN3(vfree, vsafe, vcond)) + vars->rand;
92  SUMOReal v = MAX2((SUMOReal) 0, MIN4(vfree, va, speed + ACCEL2SPEED(myAccel), vsafe));
93  return v;
94 }
95 
96 
97 MSCFModel*
99  return new MSCFModel_Kerner(vtype, myAccel, myDecel, myHeadwayTime, myK, myPhi);
100 }
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
#define SPEED2DIST(x)
Definition: SUMOTime.h:55
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
MSCFModel_Kerner(const MSVehicleType *vtype, SUMOReal accel, SUMOReal decel, SUMOReal headwayTime, SUMOReal k, SUMOReal phi)
Constructor.
SUMOReal _v(const MSVehicle *const veh, SUMOReal speed, SUMOReal vfree, SUMOReal gap, SUMOReal predSpeed) const
Returns the "safe" velocity.
T MIN4(T a, T b, T c, T d)
Definition: StdDefs.h:93
virtual SUMOReal maxNextSpeed(SUMOReal speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:86
The car-following model abstraction.
Definition: MSCFModel.h:58
SUMOReal myAccel
The vehicle's maximum acceleration [m/s^2].
Definition: MSCFModel.h:292
static SUMOReal rand()
Returns a random real number in [0, 1)
Definition: RandHelper.h:62
T MAX2(T a, T b)
Definition: StdDefs.h:72
SUMOReal followSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const
Computes the vehicle's safe speed (no dawdling)
SUMOReal myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:298
The car-following model and parameter.
Definition: MSVehicleType.h:74
SUMOReal moveHelper(MSVehicle *const veh, SUMOReal vPos) const
Applies interaction with stops and lane changing model influences.
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
T MIN2(T a, T b)
Definition: StdDefs.h:66
SUMOReal myTauDecel
The precomputed value for myDecel*myTau.
MSCFModel::VehicleVariables * getCarFollowVariables() const
Returns the vehicle's car following model variables.
Definition: MSVehicle.h:547
virtual SUMOReal moveHelper(MSVehicle *const veh, SUMOReal vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel.cpp:56
SUMOReal myPhi
Kerner's phi.
MSCFModel::VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting...
#define SUMOReal
Definition: config.h:215
T MIN3(T a, T b, T c)
Definition: StdDefs.h:79
SUMOReal stopSpeed(const MSVehicle *const veh, const SUMOReal speed, SUMOReal gap2pred) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling) ...
SUMOReal myDecel
The vehicle's maximum deceleration [m/s^2].
Definition: MSCFModel.h:295
~MSCFModel_Kerner()
Destructor.