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-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 // The psycho-physical model of Wiedemann
20 // references:
21 // Andre Stebens - Traffic simulation with the Wiedemann model
22 // Werner - Integration von Fahrzeugfolge- und Fahrstreifenwechselmodellen in die Nachtfahrsimulation LucidDrive
23 // Olstam, Tapani - Comparison of Car-following models
24 /****************************************************************************/
25 
26 
27 // ===========================================================================
28 // included modules
29 // ===========================================================================
30 #ifdef _MSC_VER
31 #include <windows_config.h>
32 #else
33 #include <config.h>
34 #endif
35 
36 #include <cmath>
37 #include "MSCFModel_Wiedemann.h"
38 #include <microsim/MSVehicle.h>
39 #include <microsim/MSLane.h>
41 
42 
43 // ===========================================================================
44 // static members
45 // ===========================================================================
46 
47 // magic constant proposed by Wiedemann (based on real world measurements)
48 const double MSCFModel_Wiedemann::D_MAX = 150;
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
55  double accel, double decel, double emergencyDecel, double apparentDecel,
56  double security, double estimation) :
57  MSCFModel(vtype, accel, decel, emergencyDecel, apparentDecel, 1.0),
58  mySecurity(security),
59  myEstimation(estimation),
60  myAX(vtype->getLength() + 1. + 2. * security),
61  myCX(25. *(1. + security + estimation)),
62  myMinAccel(0.2 * myAccel) { // +noise?
63 }
64 
65 
67 
68 
69 double
70 MSCFModel_Wiedemann::moveHelper(MSVehicle* const veh, double vPos) const {
71  const double vNext = MSCFModel::moveHelper(veh, vPos);
73  vars->accelSign = vNext > veh->getSpeed() ? 1. : -1.;
74  return vNext;
75 }
76 
77 
78 double
79 MSCFModel_Wiedemann::followSpeed(const MSVehicle* const veh, double /* speed */, double gap2pred, double predSpeed, double /*predMaxDecel*/) const {
80  return _v(veh, predSpeed, gap2pred);
81 }
82 
83 
84 double
85 MSCFModel_Wiedemann::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
86  /* Wiedemann does not handle approaching junctions or stops very well:
87  * regime approaching() fails when dv = 0 (i.e. a vehicle inserted with speed 0 does not accelerate to reach a stop)
88  * for dv ~ 0 the standard decision tree will switch to following() which
89  * does a lousy job of closing in on a stop / junction
90  * hence we borrow from Krauss here
91  */
92  return MAX2(getSpeedAfterMaxDecel(speed), MIN2(krauss_vsafe(gap, 0), maxNextSpeed(speed, veh)));
93 }
94 
95 
96 double
97 MSCFModel_Wiedemann::interactionGap(const MSVehicle* const , double vL) const {
98  UNUSED_PARAMETER(vL);
99  return D_MAX;
100 }
101 
102 
103 MSCFModel*
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  const double bx = myAX + (1 + 7 * mySecurity) * sqrt(v); // Harding propose a factor of *.8 here
117  const double ex = 2 - myEstimation; // + RandHelper::randNorm(0.5, 0.15)
118  const double sdx = myAX + ex * (bx - myAX);
119  const double sdv_root = (dx - myAX) / myCX;
120  const double sdv = sdv_root * sdv_root;
121  const double cldv = sdv * ex * ex;
122  const double opdv = cldv * (-1 - 2 * RandHelper::randNorm(0.5, 0.15));
123  // select the regime, get new acceleration, compute new speed based
124  double accel;
125  if (dx <= bx) {
126  accel = emergency(dv, dx);
127  } else if (dx < sdx) {
128  if (dv > cldv) {
129  accel = approaching(dv, dx, bx);
130  } else if (dv > opdv) {
131  accel = following(vars->accelSign);
132  } else {
133  accel = fullspeed(v, vpref, dx, bx);
134  }
135  } else {
136  if (dv > sdv && dx < D_MAX) { //@note other versions have an disjunction instead of conjunction
137  accel = approaching(dv, dx, bx);
138  } else {
139  accel = fullspeed(v, vpref, dx, bx);
140  }
141  }
142  // since we have hard constrainst on accel we may as well use them here
143  accel = MAX2(MIN2(accel, myAccel), -myDecel);
144  const double vNew = MAX2(0., v + ACCEL2SPEED(accel)); // don't allow negative speeds
145  return vNew;
146 }
147 
148 
149 double
150 MSCFModel_Wiedemann::fullspeed(double v, double vpref, double dx, double bx) const {
151  double bmax = 0.2 + 0.8 * myAccel * (7 - sqrt(v));
152  // if veh just drifted out of a 'following' process the acceleration is reduced
153  double accel = dx <= 2 * bx ? MIN2(myMinAccel, bmax * (dx - bx) / bx) : bmax;
154  if (v > vpref) {
155  accel = - accel;
156  }
157  return accel;
158 }
159 
160 
161 double
162 MSCFModel_Wiedemann::following(double sign) const {
163  return myMinAccel * sign;
164 }
165 
166 
167 double
168 MSCFModel_Wiedemann::approaching(double dv, double dx, double bx) const {
169  // there is singularity in the formula. we do the sanity check outside
170  assert(bx < dx);
171  return 0.5 * dv * dv / (bx - dx); // + predAccel at t-reaction_time if this is value is above a treshold
172 }
173 
174 
175 double
176 MSCFModel_Wiedemann::emergency(double /* dv */, double /* dx */) const {
177  /* emergency according to A.Stebens
178  // wiedemann assumes that dx will always be larger than myAX (sumo may
179  // violate this assumption when crashing (-:
180  if (dx > myAX) {
181  double accel = 0.5 * dv * dv / (myAX - dx); // + predAccel at t-reaction_time if this is value is above a treshold
182  // one would assume that in an emergency accel must be negative. However the
183  // wiedemann formula allows for accel = 0 whenever dv = 0
184  assert(accel <= 0);
185  return accel;
186  } else {
187  return = -myDecel;
188  }
189  */
190 
191  // emergency according to C.Werner
192  return -myDecel;
193 }
194 
195 
196 
197 // XXX: This could be replaced by maximumSafeStopSpeed(), refs. #2575
198 double
199 MSCFModel_Wiedemann::krauss_vsafe(double gap, double predSpeed) const {
200  if (predSpeed == 0 && gap < 0.01) {
201  return 0;
202  }
203  const double tauDecel = myDecel * myHeadwayTime;
204  const double speedReduction = ACCEL2SPEED(myDecel);
205  const int predSteps = int(predSpeed / speedReduction);
206  const double leaderContrib = 2. * myDecel * (gap + SPEED2DIST(predSteps * predSpeed - speedReduction * predSteps * (predSteps + 1) / 2));
207  return (double)(-tauDecel + sqrt(tauDecel * tauDecel + leaderContrib));
208 }
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
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:531
#define SPEED2DIST(x)
Definition: SUMOTime.h:54
double krauss_vsafe(double gap, double predSpeed) const
vsafe from krauss since Wiedemann is deficient at approaching
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
const double myCX
perception threshold modifier
const double mySecurity
The driver&#39;s security parameter // also &#39;ZF1&#39;.
The car-following model abstraction.
Definition: MSCFModel.h:59
double stopSpeed(const MSVehicle *const veh, const double speed, double gap) const
Computes the vehicle&#39;s safe speed for approaching a non-moving obstacle (no dawdling) ...
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 following(double sign) const
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
The car-following model and parameter.
Definition: MSVehicleType.h:72
double getMaxSpeed() const
Returns the maximum speed.
double interactionGap(const MSVehicle *const, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
static double randNorm(double mean, double variance, std::mt19937 *rng=0)
Access to a random number from a normal distribution.
Definition: RandHelper.h:136
double _v(const MSVehicle *veh, double predSpeed, double gap) const
static const double D_MAX
free-flow distance in m
double emergency(double dv, double dx) const
~MSCFModel_Wiedemann()
Destructor.
T MIN2(T a, T b)
Definition: StdDefs.h:67
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:318
double accelSign
state variable for remembering the drift direction
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:537
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 approaching(double dv, double dx, double bx) const
double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
const double myMinAccel
The vehicle&#39;s minimum acceleration [m/s^2].
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
double myEmergencyDecel
The vehicle&#39;s maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:539
double getLength() const
Get vehicle&#39;s length [m].
const double myEstimation
The driver&#39;s estimation parameter // also &#39;ZF2&#39;.
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:544
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:482
const double myAX
front-bumper to front-bumper distance
MSCFModel_Wiedemann(const MSVehicleType *vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double security, double estimation)
Constructor.
double fullspeed(double v, double vpref, double dx, double bx) const