Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSCFModel_PWag2009.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2010-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/****************************************************************************/
21// Scalable model based on Krauss by Peter Wagner
22/****************************************************************************/
23#include <config.h>
24
25#include <microsim/MSVehicle.h>
26#include <microsim/MSLane.h>
27#include "MSCFModel_PWag2009.h"
29
30
31// ===========================================================================
32// method definitions
33// ===========================================================================
35 MSCFModel(vtype),
36 myDawdle(vtype->getParameter().getCFParam(SUMO_ATTR_SIGMA, SUMOVTypeParameter::getDefaultImperfection(vtype->getParameter().vehicleClass))),
37 myTauDecel(myDecel * myHeadwayTime),
38 myDecelDivTau(myDecel / myHeadwayTime),
39 myTauLastDecel(myDecel * vtype->getParameter().getCFParam(SUMO_ATTR_CF_PWAGNER2009_TAULAST, 0.3)),
40 myActionPointProbability(vtype->getParameter().getCFParam(SUMO_ATTR_CF_PWAGNER2009_APPROB, 0.5)) {
41 // PWag2009 does not drive very precise and may violate minGap on occasion
43}
44
45
47
48
49double
50MSCFModel_PWag2009::finalizeSpeed(MSVehicle* const veh, double vPos) const {
51 const double vNext = MSCFModel::finalizeSpeed(veh, vPos);
53 double apref = SPEED2ACCEL(vNext - veh->getSpeed());
54 vars->aOld = apref;
55 return vNext;
56}
57
58double
59MSCFModel_PWag2009::patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
61 UNUSED_PARAMETER(vMin);
62 return vMax;
63}
64
65// in addition, the parameters myTauLast, probAP, and sigmaAcc are needed; sigmaAcc can use myDawdle
66// myTauLast might use the current time-step size, but this yields eventually an extreme model, I would be
67// more careful and set it to something around 0.3 or 0.4, which are among the shortest headways I have
68// seen so far in data ...
69
70double
71MSCFModel_PWag2009::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double /*predMaxDecel*/, const MSVehicle* const /*pred*/, const CalcReason /*usage*/) const {
72 if (predSpeed == 0 && gap < 0.01) {
73 return 0;
74 }
75 const double vsafe = -myTauLastDecel + sqrt(myTauLastDecel * myTauLastDecel + predSpeed * predSpeed + 2.0 * myDecel * gap);
76 const double asafe = SPEED2ACCEL(vsafe - speed);
78 double apref = vars->aOld;
79 if (apref <= asafe && RandHelper::rand(veh->getRNG()) <= myActionPointProbability * TS) {
80 apref = myDecelDivTau * (gap + (predSpeed - speed) * myHeadwayTime - speed * myHeadwayTime) / (speed + myTauDecel);
81 apref = MIN2(apref, myAccel);
82 apref = MAX2(apref, -myDecel);
83 apref += myDawdle * RandHelper::rand((double) - 1., (double)1., veh->getRNG());
84 }
85 if (apref > asafe) {
86 apref = asafe;
87 }
88 return MAX2(0., speed + ACCEL2SPEED(apref));
89}
90
91// uses the safe speed and preferred acceleration with the same NORMAL tau to compute stopSpeed
92double
93MSCFModel_PWag2009::stopSpeed(const MSVehicle* const /* veh */, const double speed, double gap, double /*decel*/, const CalcReason /*usage*/) const {
94 if (gap < 0.01) {
95 return 0.;
96 }
97 const double vsafe = -myTauDecel + sqrt(myTauDecel * myTauDecel + 2.0 * myDecel * gap);
98 const double asafe = SPEED2ACCEL(vsafe - speed);
99// VehicleVariables* vars = (VehicleVariables*)veh->getCarFollowVariables();
100 double apref = myDecelDivTau * (gap - 2 * speed * myHeadwayTime) / (speed + myTauDecel);
101 if (apref <= asafe) {
102 apref = MIN2(apref, myAccel);
103 apref = MAX2(apref, -myDecel);
104 } else {
105 apref = asafe;
106 }
107 return MAX2(0., vsafe + ACCEL2SPEED(apref));
108}
109
110
113 return new MSCFModel_PWag2009(vtype);
114}
#define ACCEL2SPEED(x)
Definition SUMOTime.h:51
#define TS
Definition SUMOTime.h:42
#define SPEED2ACCEL(x)
Definition SUMOTime.h:53
@ SUMO_ATTR_CF_PWAGNER2009_TAULAST
@ SUMO_ATTR_COLLISION_MINGAP_FACTOR
@ SUMO_ATTR_CF_PWAGNER2009_APPROB
@ SUMO_ATTR_SIGMA
#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
SumoRNG * getRNG() const
Scalable model based on Krauss by Peter Wagner.
~MSCFModel_PWag2009()
Destructor.
double myDecelDivTau
The precomputed value for myDecel/myTau.
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 myTauLastDecel
The precomputed value for (minimum headway time)*myDecel.
double myActionPointProbability
The probability for any action.
double patchSpeedBeforeLC(const MSVehicle *veh, double vMin, double vMax) const
apply dawdling
MSCFModel_PWag2009(const MSVehicleType *vtype)
Constructor.
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
double myTauDecel
The precomputed value for myDecel*myTau.
double stopSpeed(const MSVehicle *const veh, const double speed, double gap2pred, double decel, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
The car-following model abstraction.
Definition MSCFModel.h:55
virtual double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences. Called at most once per simulation...
CalcReason
What the return value of stop/follow/free-Speed is used for.
Definition MSCFModel.h:77
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 myAccel
The vehicle's maximum acceleration [m/s^2].
Definition MSCFModel.h:698
double myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
Definition MSCFModel.h:710
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
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.
const SUMOVTypeParameter & getParameter() const
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Structure representing possible vehicle parameter.
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.