Eclipse SUMO - Simulation of Urban MObility
MSCFModel_Wiedemann.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2011-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // The psycho-physical model of Wiedemann
17 // references:
18 // Andre Stebens - Traffic simulation with the Wiedemann model
19 // Werner - Integration von Fahrzeugfolge- und Fahrstreifenwechselmodellen in die Nachtfahrsimulation LucidDrive
20 // Olstam, Tapani - Comparison of Car-following models
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #include <config.h>
28 
29 #include <cmath>
30 #include "MSCFModel_Wiedemann.h"
31 #include <microsim/MSVehicle.h>
32 #include <microsim/MSLane.h>
34 
35 //#define DEBUG_V
36 
37 // ===========================================================================
38 // static members
39 // ===========================================================================
40 
41 // magic constant proposed by Wiedemann (based on real world measurements)
42 const double MSCFModel_Wiedemann::D_MAX = 150;
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
49  MSCFModel(vtype),
50  mySecurity(vtype->getParameter().getCFParam(SUMO_ATTR_CF_WIEDEMANN_SECURITY, 0.5)),
51  myEstimation(vtype->getParameter().getCFParam(SUMO_ATTR_CF_WIEDEMANN_ESTIMATION, 0.5)),
52  myAX(vtype->getLength() + 1. + 2. * mySecurity),
53  myCX(25. *(1. + mySecurity + myEstimation)),
54  myMinAccel(0.2 * myAccel) { // +noise?
55 }
56 
57 
59 
60 
61 double
62 MSCFModel_Wiedemann::finalizeSpeed(MSVehicle* const veh, double vPos) const {
63  const double vNext = MSCFModel::finalizeSpeed(veh, vPos);
65  vars->accelSign = vNext > veh->getSpeed() ? 1. : -1.;
66  return vNext;
67 }
68 
69 
70 double
71 MSCFModel_Wiedemann::followSpeed(const MSVehicle* const veh, double /* speed */, double gap2pred, double predSpeed, double /*predMaxDecel*/, const MSVehicle* const /*pred*/) const {
72  return _v(veh, predSpeed, gap2pred);
73 }
74 
75 
76 double
77 MSCFModel_Wiedemann::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
78  /* Wiedemann does not handle approaching junctions or stops very well:
79  * regime approaching() fails when dv = 0 (i.e. a vehicle inserted with speed 0 does not accelerate to reach a stop)
80  * for dv ~ 0 the standard decision tree will switch to following() which
81  * does a lousy job of closing in on a stop / junction
82  * hence we borrow from Krauss here
83  */
84  return MIN2(maximumSafeStopSpeed(gap, speed, false, veh->getActionStepLengthSecs()), maxNextSpeed(speed, veh));
85 }
86 
87 
88 double
89 MSCFModel_Wiedemann::interactionGap(const MSVehicle* const, double vL) const {
90  UNUSED_PARAMETER(vL);
91  return D_MAX;
92 }
93 
94 
95 MSCFModel*
97  return new MSCFModel_Wiedemann(vtype);
98 }
99 
100 
101 double
102 MSCFModel_Wiedemann::getSecureGap(const MSVehicle* const veh, const MSVehicle* const pred, const double speed, const double leaderSpeed, const double leaderMaxDecel) const {
103  const double bx = (1 + 7 * mySecurity) * sqrt(speed);
104  const double abx = myAX + bx - myType->getLength(); // abx is the brutto gap
105  return MAX2(abx, MSCFModel::getSecureGap(veh, pred, speed, leaderSpeed, leaderMaxDecel));
106 }
107 
108 
109 double
110 MSCFModel_Wiedemann::_v(const MSVehicle* veh, double predSpeed, double gap) const {
112  const double dx = gap + myType->getLength(); // wiedemann uses brutto gap
113  const double v = veh->getSpeed();
114  const double vpref = veh->getMaxSpeed();
115  const double dv = v - predSpeed;
116  // desired minimum following distance at low speed difference
117  const double bx = (1 + 7 * mySecurity) * sqrt(v); // Harding propose a factor of *.8 here
118  const double abx = myAX + bx; // Harding propose a factor of *.8 here
119  const double ex = 2 - myEstimation; // + RandHelper::randNorm(0.5, 0.15)
120  const double sdx = myAX + ex * bx;
121  const double sdv_root = (dx - myAX) / myCX;
122  const double sdv = sdv_root * sdv_root;
123  const double cldv = sdv * ex * ex;
124  const double opdv = cldv * (-1 - 2 * RandHelper::randNorm(0.5, 0.15, veh->getRNG()));
125  // select the regime, get new acceleration, compute new speed based
126  double accel;
127  if (dx <= abx) {
128  accel = emergency(dv, dx);
129  } else if (dx < sdx) {
130  if (dv > cldv) {
131  accel = approaching(dv, dx, abx);
132  } else if (dv > opdv) {
133  accel = following(vars->accelSign);
134  } else {
135  accel = fullspeed(v, vpref, dx, abx);
136  }
137  } else {
138  if (dv > sdv && dx < D_MAX) { //@note other versions have an disjunction instead of conjunction
139  accel = approaching(dv, dx, abx);
140  } else {
141  accel = fullspeed(v, vpref, dx, abx);
142  }
143  }
144  // since we have hard constrainst on accel we may as well use them here
145  accel = MAX2(MIN2(accel, myAccel), -myEmergencyDecel);
146  const double vNew = MAX2(0., v + ACCEL2SPEED(accel)); // don't allow negative speeds
147 #ifdef DEBUG_V
148  if (veh->isSelected()) {
149  std::cout << SIMTIME << " Wiedemann::_v veh=" << veh->getID()
150  << " predSpeed=" << predSpeed << " gap=" << gap
151  << " dv=" << dv << " dx=" << dx << " ax=" << myAX << " bx=" << bx << " abx=" << abx
152  << " sdx=" << sdx << " sdv=" << sdv << " cldv=" << cldv << " opdv=" << opdv
153  << " accel=" << accel << " vNew=" << vNew << "\n";
154  }
155 #endif
156  return vNew;
157 }
158 
159 
160 double
161 MSCFModel_Wiedemann::fullspeed(double v, double vpref, double dx, double abx) const {
162  // maximum acceleration is reduced with increasing speed
163  double bmax = 0.2 + 0.8 * myAccel * (7 - sqrt(v));
164  // if veh just drifted out of a 'following' process the acceleration is reduced
165  double accel = dx <= 2 * abx ? MIN2(myMinAccel, bmax * (dx - abx) / abx) : bmax;
166  if (v > vpref) {
167  accel = - accel;
168  }
169  return accel;
170 }
171 
172 
173 double
174 MSCFModel_Wiedemann::following(double sign) const {
175  return myMinAccel * sign;
176 }
177 
178 
179 double
180 MSCFModel_Wiedemann::approaching(double dv, double dx, double abx) const {
181  // there is singularity in the formula. we do the sanity check outside
182  assert(abx < dx);
183  return 0.5 * dv * dv / (abx - dx); // + predAccel at t-reaction_time if this is value is above a treshold
184 }
185 
186 
187 double
188 MSCFModel_Wiedemann::emergency(double dv, double dx) const {
189  // wiedemann assumes that dx will always be larger than myAX (sumo may
190  // violate this assumption when crashing (-:
191  if (dx > myAX) {
192  double accel = 0.5 * dv * dv / (myAX - dx); // + predAccel at t-reaction_time if this is value is above a treshold
193  // one would assume that in an emergency accel must be negative. However the
194  // wiedemann formula allows for accel = 0 whenever dv = 0
195  assert(accel <= 0);
196  return accel;
197  } else {
198  return -myEmergencyDecel;
199  }
200 
201  // emergency according to C.Werner
202  //return -myEmergencyDecel;
203 }
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:65
UNUSED_PARAMETER
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:31
SUMO_ATTR_CF_WIEDEMANN_ESTIMATION
@ SUMO_ATTR_CF_WIEDEMANN_ESTIMATION
Definition: SUMOXMLDefinitions.h:842
MSCFModel_Wiedemann::VehicleVariables
Definition: MSCFModel_Wiedemann.h:128
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:73
MSCFModel::maxNextSpeed
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:238
MSCFModel_Wiedemann::finalizeSpeed
double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel_Wiedemann.cpp:62
MSCFModel_Wiedemann::mySecurity
const double mySecurity
The driver's security parameter // also 'ZF1'.
Definition: MSCFModel_Wiedemann.h:155
MSCFModel_Wiedemann::MSCFModel_Wiedemann
MSCFModel_Wiedemann(const MSVehicleType *vtype)
Constructor.
Definition: MSCFModel_Wiedemann.cpp:48
ACCEL2SPEED
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:52
MSCFModel_Wiedemann::following
double following(double sign) const
Definition: MSCFModel_Wiedemann.cpp:174
MSCFModel::getSecureGap
virtual double getSecureGap(const MSVehicle *const, const MSVehicle *const, const double speed, const double leaderSpeed, const double leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum (>=0)
Definition: MSCFModel.h:329
MSCFModel_Wiedemann::fullspeed
double fullspeed(double v, double vpref, double dx, double bx) const
Definition: MSCFModel_Wiedemann.cpp:161
MSCFModel_Wiedemann::getSecureGap
double getSecureGap(const MSVehicle *const veh, const MSVehicle *const pred, const double speed, const double leaderSpeed, const double leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum (>=0)
Definition: MSCFModel_Wiedemann.cpp:102
RandHelper::randNorm
static double randNorm(double mean, double variance, std::mt19937 *rng=0)
Access to a random number from a normal distribution.
Definition: RandHelper.h:135
MSCFModel_Wiedemann::approaching
double approaching(double dv, double dx, double abx) const
Definition: MSCFModel_Wiedemann.cpp:180
MSVehicle::getCarFollowVariables
MSCFModel::VehicleVariables * getCarFollowVariables() const
Returns the vehicle's car following model variables.
Definition: MSVehicle.h:910
MSCFModel_Wiedemann.h
MSCFModel::finalizeSpeed
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:164
MSCFModel_Wiedemann::followSpeed
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0) const
Computes the vehicle's safe speed (no dawdling)
Definition: MSCFModel_Wiedemann.cpp:71
MSCFModel_Wiedemann::~MSCFModel_Wiedemann
~MSCFModel_Wiedemann()
Destructor.
Definition: MSCFModel_Wiedemann.cpp:58
MSBaseVehicle::getMaxSpeed
double getMaxSpeed() const
Returns the maximum speed.
Definition: MSBaseVehicle.cpp:165
MSBaseVehicle::isSelected
virtual bool isSelected() const
whether this vehicle is selected in the GUI
Definition: MSBaseVehicle.h:479
MSVehicle.h
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
MSCFModel::myEmergencyDecel
double myEmergencyDecel
The vehicle's maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:622
SIMTIME
#define SIMTIME
Definition: SUMOTime.h:63
MSCFModel_Wiedemann::VehicleVariables::accelSign
double accelSign
state variable for remembering the drift direction
Definition: MSCFModel_Wiedemann.h:132
MSCFModel_Wiedemann::_v
double _v(const MSVehicle *veh, double predSpeed, double gap) const
Definition: MSCFModel_Wiedemann.cpp:110
MSVehicle::getActionStepLengthSecs
double getActionStepLengthSecs() const
Returns the vehicle's action step length in secs, i.e. the interval between two action points.
Definition: MSVehicle.h:512
MSCFModel::maximumSafeStopSpeed
double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap.
Definition: MSCFModel.cpp:711
MSCFModel_Wiedemann::D_MAX
static const double D_MAX
free-flow distance in m
Definition: MSCFModel_Wiedemann.h:170
MSCFModel_Wiedemann::interactionGap
double interactionGap(const MSVehicle *const, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
Definition: MSCFModel_Wiedemann.cpp:89
MSCFModel_Wiedemann::myEstimation
const double myEstimation
The driver's estimation parameter // also 'ZF2'.
Definition: MSCFModel_Wiedemann.h:158
SUMO_ATTR_CF_WIEDEMANN_SECURITY
@ SUMO_ATTR_CF_WIEDEMANN_SECURITY
Definition: SUMOXMLDefinitions.h:841
MSCFModel_Wiedemann::duplicate
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
Definition: MSCFModel_Wiedemann.cpp:96
MSVehicleType::getLength
double getLength() const
Get vehicle's length [m].
Definition: MSVehicleType.h:109
MSCFModel_Wiedemann::emergency
double emergency(double dv, double dx) const
Definition: MSCFModel_Wiedemann.cpp:188
MSBaseVehicle::getID
const std::string & getID() const
Returns the name of the vehicle.
Definition: MSBaseVehicle.cpp:138
MSCFModel::myType
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:614
MSCFModel
The car-following model abstraction.
Definition: MSCFModel.h:56
MSCFModel_Wiedemann::myAX
const double myAX
the minimum front-bumper to front-bumper distance when standing
Definition: MSCFModel_Wiedemann.h:161
config.h
MSVehicle::getSpeed
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:476
RandHelper.h
MSCFModel::myAccel
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition: MSCFModel.h:617
MSLane.h
MSCFModel_Wiedemann::myCX
const double myCX
perception threshold modifier
Definition: MSCFModel_Wiedemann.h:164
MSCFModel_Wiedemann::myMinAccel
const double myMinAccel
The vehicle's minimum acceleration [m/s^2] // also b_null.
Definition: MSCFModel_Wiedemann.h:167
MSCFModel_Wiedemann::stopSpeed
double stopSpeed(const MSVehicle *const veh, const double speed, double gap) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
Definition: MSCFModel_Wiedemann.cpp:77
MSBaseVehicle::getRNG
std::mt19937 * getRNG() const
Definition: MSBaseVehicle.cpp:758
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79