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