Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSCFModel_Wiedemann.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2011-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// The psycho-physical model of Wiedemann
21// references:
22// Andre Stebens - Traffic simulation with the Wiedemann model
23// Werner - Integration von Fahrzeugfolge- und Fahrstreifenwechselmodellen in die Nachtfahrsimulation LucidDrive
24// Olstam, Tapani - Comparison of Car-following models
25// Higgs, B. et.al - Analysis of theWiedemann car following model over different speeds using naturalistic data.
26// Ahmed, H.U.; Huang, Y.; Lu, P. - A Review of Car-Following Models and Modeling Tools forHuman and Autonomous-Ready Driving Behaviors in Micro-Simulation
27
28/****************************************************************************/
29#include <config.h>
30
31#include <cmath>
32#include "MSCFModel_Wiedemann.h"
33#include <microsim/MSVehicle.h>
34#include <microsim/MSLane.h>
36
37//#define DEBUG_V
38
39// ===========================================================================
40// static members
41// ===========================================================================
42
43// magic constant proposed by Wiedemann (based on real world measurements)
44const double MSCFModel_Wiedemann::D_MAX = 150;
45
46#define B_MIN_MULT 0
47#define B_MIN_ADD -1
48#define PRED_DECEL_MULT 0.5
49#define PRED_DECEL_MULT_EMERGENCY 0.55
50
51// ===========================================================================
52// method definitions
53// ===========================================================================
55 MSCFModel(vtype),
56 mySecurity(vtype->getParameter().getCFParam(SUMO_ATTR_CF_WIEDEMANN_SECURITY, 0.5)),
57 myEstimation(vtype->getParameter().getCFParam(SUMO_ATTR_CF_WIEDEMANN_ESTIMATION, 0.5)),
58 myAX(vtype->getLength() + 1. + 2. * mySecurity),
59 myCX(25. *(1. + mySecurity + myEstimation)),
60 myMinAccel(0.2 * myAccel),
61 myMaxApproachingDecel((myDecel + myEmergencyDecel) / 2) {
62 // Wiedemann does not drive very precise and may violate minGap on occasion
64}
65
66
68
69
70double
71MSCFModel_Wiedemann::finalizeSpeed(MSVehicle* const veh, double vPos) const {
72 const double vNext = MSCFModel::finalizeSpeed(veh, vPos);
74 vars->accelSign = vNext > veh->getSpeed() ? 1. : -1.;
75 return vNext;
76}
77
78
79double
80MSCFModel_Wiedemann::followSpeed(const MSVehicle* const veh, double /* speed */, double gap2pred, double predSpeed, double /*predMaxDecel*/, const MSVehicle* const pred, const CalcReason /*usage*/) const {
81 return _v(veh, predSpeed, gap2pred, pred != nullptr ? pred->getAcceleration() : 0);
82}
83
84
85double
86MSCFModel_Wiedemann::stopSpeed(const MSVehicle* const veh, const double speed, double gap, double decel, const CalcReason /*usage*/) 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 MIN2(maximumSafeStopSpeed(gap, decel, speed, false, veh->getActionStepLengthSecs()), maxNextSpeed(speed, veh));
94}
95
96
97double
98MSCFModel_Wiedemann::interactionGap(const MSVehicle* const, double vL) const {
100 return D_MAX;
101}
102
103
106 return new MSCFModel_Wiedemann(vtype);
107}
108
109
110double
111MSCFModel_Wiedemann::getSecureGap(const MSVehicle* const veh, const MSVehicle* const pred, const double speed, const double leaderSpeed, const double leaderMaxDecel) const {
112 const double bx = (1 + 7 * mySecurity) * sqrt(speed);
113 const double abx = myAX + bx - myType->getLength(); // abx is the brutto gap
114 return MAX2(abx, MSCFModel::getSecureGap(veh, pred, speed, leaderSpeed, leaderMaxDecel));
115}
116
117
118double
119MSCFModel_Wiedemann::_v(const MSVehicle* veh, double predSpeed, double gap, double predAccel) const {
121 const double dx = gap + myType->getLength(); // wiedemann uses brutto gap
122 const double v = veh->getSpeed();
123 const double vpref = veh->getMaxSpeed();
124 const double dv = v - predSpeed;
125 // desired minimum following distance at low speed difference
126 const double bx = (1 + 7 * mySecurity) * sqrt(v); // Harding propose a factor of *.8 here
127 const double abx = myAX + bx; // Harding propose a factor of *.8 here
128 const double ex = 2 - myEstimation; // + RandHelper::randNorm(0.5, 0.15)
129 const double sdx = myAX + ex * bx;
130 const double sdv_root = (dx - myAX) / myCX;
131 const double sdv = sdv_root * sdv_root;
132 const double cldv = sdv * ex * ex;
133 const double opdv = cldv * (-1 - 2 * RandHelper::randNorm(0.5, 0.15, veh->getRNG()));
134 // D_MAX is too low to brake safely when driving at speeds above 36m/s
135 const double dmax = MAX2(D_MAX, brakeGap(v, myDecel, 0));
136 // select the regime, get new acceleration, compute new speed based
137 double accel;
138 int branch = 0;
139 if (dx <= abx) {
140 accel = emergency(dv, dx, predAccel, v, gap, abx, bx);
141 branch = 1;
142 } else if (dx < sdx) {
143 if (dv > cldv) {
144 accel = approaching(dv, dx, abx, predAccel);
145 branch = 2;
146 } else if (dv > opdv) {
147 accel = following(vars->accelSign);
148 branch = 3;
149 } else {
150 accel = fullspeed(v, vpref, dx, abx);
151 branch = 4;
152 }
153 } else {
154 if (dv > sdv && dx < dmax) { //@note other versions have an disjunction instead of conjunction
155 accel = approaching(dv, dx, abx, predAccel);
156 branch = 5;
157 } else {
158 accel = fullspeed(v, vpref, dx, abx);
159 branch = 6;
160 }
161 }
162 // since we have hard constraints on accel we may as well use them here
163#ifdef DEBUG_V
164 const double rawAccel = accel;
165#endif
166 accel = MAX2(MIN2(accel, myAccel), -myEmergencyDecel);
167 const double vNew = MAX2(0., v + ACCEL2SPEED(accel)); // don't allow negative speeds
168#ifdef DEBUG_V
169 if (veh->isSelected() && !MSGlobals::gComputeLC) {
170 std::cout << SIMTIME << " Wiedemann::_v veh=" << veh->getID()
171 << " v=" << v << " pV=" << predSpeed << " pA=" << predAccel << " gap=" << gap
172 << " dv=" << dv << " dx=" << dx << " ax=" << myAX << " bx=" << bx << " abx=" << abx
173 << " sdx=" << sdx << " sdv=" << sdv << " cldv=" << cldv << " opdv=" << opdv
174 << " branch=" << branch << " rawAccel=" << rawAccel
175 << " accel=" << accel << " vNew=" << vNew << "\n";
176 }
177#else
178 UNUSED_PARAMETER(branch);
179#endif
180 return vNew;
181}
182
183
184double
185MSCFModel_Wiedemann::fullspeed(double v, double vpref, double dx, double abx) const {
186 // maximum acceleration is reduced with increasing speed
187 double bmax = 0.2 + 0.8 * myAccel * (7 - sqrt(v));
188 // if veh just drifted out of a 'following' process the acceleration is reduced
189 double accel = dx <= 2 * abx ? MIN2(myMinAccel, bmax * (dx - abx) / abx) : bmax;
190 if (v > vpref) {
191 accel = - accel;
192 }
193 return accel;
194}
195
196
197double
199 return myMinAccel * sign;
200}
201
202
203double
204MSCFModel_Wiedemann::approaching(double dv, double dx, double abx, double predAccel) const {
205 // there is singularity in the formula. we do the sanity check outside
206 assert(abx < dx);
207 // @note: the original model does not have a limit on maximum deceleration here.
208 // We add this to avoid cascading emergency deceleration
209 // also, the multiplier on predAccel is always 1 in the original model
210 return MAX2(0.5 * dv * dv / (abx - dx) + predAccel * PRED_DECEL_MULT, -myMaxApproachingDecel);
211}
212
213
214double
215MSCFModel_Wiedemann::emergency(double dv, double dx, double predAccel, double v, double gap, double abx, double bx) const {
216 // wiedemann assumes that dx will always be larger than myAX (sumo may
217 // violate this assumption when crashing (-:
218 //
219 // predAccel is called b_(n-1) in the literature and it's multipleir is always 1
220
221 if (dx > myAX) {
222 const double bmin = B_MIN_ADD + B_MIN_MULT * v;
223 const double accel = (0.5 * dv * dv / (myAX - dx)
224 + predAccel * PRED_DECEL_MULT_EMERGENCY
225 + bmin * (abx - gap) / bx);
226 return accel;
227 } else {
228 return -myEmergencyDecel;
229 }
230
231 // emergency according to C.Werner
232 //return -myEmergencyDecel;
233}
#define PRED_DECEL_MULT
#define B_MIN_ADD
#define PRED_DECEL_MULT_EMERGENCY
#define B_MIN_MULT
#define ACCEL2SPEED(x)
Definition SUMOTime.h:51
#define SIMTIME
Definition SUMOTime.h:62
@ SUMO_ATTR_CF_WIEDEMANN_SECURITY
@ SUMO_ATTR_COLLISION_MINGAP_FACTOR
@ SUMO_ATTR_CF_WIEDEMANN_ESTIMATION
#define UNUSED_PARAMETER(x)
Definition StdDefs.h:30
T MIN2(T a, T b)
Definition StdDefs.h:76
T MAX2(T a, T b)
Definition StdDefs.h:82
double getMaxSpeed() const
Returns the maximum speed (the minimum of desired and technical maximum speed)
virtual bool isSelected() const
whether this vehicle is selected in the GUI
SumoRNG * getRNG() const
double accelSign
state variable for remembering the drift direction
The Wiedemann Model car-following model.
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
double following(double sign) const
double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
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)
const double myMinAccel
The vehicle's minimum acceleration [m/s^2] // also b_null.
double approaching(double dv, double dx, double abx, double predAccel) const
double stopSpeed(const MSVehicle *const veh, const double speed, double gap, double decel, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
const double myMaxApproachingDecel
The maximum deceleration when approaching.
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed (no dawdling)
double _v(const MSVehicle *veh, double predSpeed, double gap, double predAccel) const
static const double D_MAX
free-flow distance in m
const double myEstimation
The driver's estimation parameter // also 'ZF2'.
double fullspeed(double v, double vpref, double dx, double bx) const
MSCFModel_Wiedemann(const MSVehicleType *vtype)
Constructor.
double emergency(double dv, double dx, double predAccel, double v, double gap, double abx, double bx) const
const double myAX
the minimum front-bumper to front-bumper distance when standing
const double myCX
perception threshold modifier
double interactionGap(const MSVehicle *const, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
const double mySecurity
The driver's security parameter // also 'ZF1'.
The car-following model abstraction.
Definition MSCFModel.h:55
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
virtual double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences. Called at most once per simulation...
double myEmergencyDecel
The vehicle's maximum emergency deceleration [m/s^2].
Definition MSCFModel.h:703
CalcReason
What the return value of stop/follow/free-Speed is used for.
Definition MSCFModel.h:77
virtual double getSecureGap(const MSVehicle *const veh, 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)
double myCollisionMinGapFactor
The factor of minGap that must be maintained to avoid a collision event.
Definition MSCFModel.h:707
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition MSCFModel.h:701
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition MSCFModel.h:380
double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion=false, double headway=-1, bool relaxEmergency=true) const
Returns the maximum next velocity for stopping within gap.
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition MSCFModel.h:698
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition MSCFModel.h:695
static bool gComputeLC
whether the simulationLoop is in the lane changing phase
Definition MSGlobals.h:140
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
double getActionStepLengthSecs() const
Returns the vehicle's action step length in secs, i.e. the interval between two action points.
Definition MSVehicle.h:533
double getAcceleration() const
Returns the vehicle's acceleration in m/s (this is computed as the last step's mean acceleration in c...
Definition MSVehicle.h:514
double getSpeed() const
Returns the vehicle's current speed.
Definition MSVehicle.h:490
MSCFModel::VehicleVariables * getCarFollowVariables() const
Returns the vehicle's car following model variables.
Definition MSVehicle.h:986
The car-following model and parameter.
double getLength() const
Get vehicle's length [m].
const SUMOVTypeParameter & getParameter() const
const std::string & getID() const
Returns the id.
Definition Named.h:74
static double randNorm(double mean, double variance, SumoRNG *rng=nullptr)
Access to a random number from a normal distribution.
double getCFParam(const SumoXMLAttr attr, const double defaultValue) const
Returns the named value from the map, or the default if it is not contained there.