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-2026 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"
30
31
32// ===========================================================================
33// method definitions
34// ===========================================================================
36 MSCFModel(vtype),
37 myDawdle(vtype->getParameter().getCFParam(SUMO_ATTR_SIGMA, SUMOVTypeParameter::getDefaultImperfection(vtype->getParameter().vehicleClass))),
38 myTauDecel(myDecel * myHeadwayTime),
39 myDecelDivTau(myDecel / myHeadwayTime),
40 myTauLastDecel(myDecel * vtype->getParameter().getCFParam(SUMO_ATTR_CF_PWAGNER2009_TAULAST, 0.3)),
41 myActionPointProbability(vtype->getParameter().getCFParam(SUMO_ATTR_CF_PWAGNER2009_APPROB, 0.5)) {
42 // PWag2009 does not drive very precise and may violate minGap on occasion
44}
45
46
48
49
50void
53 out.writeAttr(SUMO_ATTR_ID, "PWagner2009");
54 std::ostringstream internals;
55 internals << aOld;
56 out.writeAttr(SUMO_ATTR_STATE, internals.str());
57 out.closeTag();
58}
59
60
61void
63 bool ok = true;
64 const std::string cfmID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
65 if (cfmID != "PWagner2009") {
66 throw ProcessError(TLF("incompatible carFollowModel '%' when loading state for PWagner2009", cfmID));
67 }
68 std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
69 bis >> aOld;
70}
71
72
73double
74MSCFModel_PWag2009::finalizeSpeed(MSVehicle* const veh, double vPos) const {
75 const double vNext = MSCFModel::finalizeSpeed(veh, vPos);
77 double apref = SPEED2ACCEL(vNext - veh->getSpeed());
78 vars->aOld = apref;
79 return vNext;
80}
81
82double
83MSCFModel_PWag2009::patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
85 UNUSED_PARAMETER(vMin);
86 return vMax;
87}
88
89// in addition, the parameters myTauLast, probAP, and sigmaAcc are needed; sigmaAcc can use myDawdle
90// myTauLast might use the current time-step size, but this yields eventually an extreme model, I would be
91// more careful and set it to something around 0.3 or 0.4, which are among the shortest headways I have
92// seen so far in data ...
93
94double
95MSCFModel_PWag2009::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double /*predMaxDecel*/, const MSVehicle* const /*pred*/, const CalcReason /*usage*/) const {
96 if (predSpeed == 0 && gap < 0.01) {
97 return 0;
98 }
99 const double vsafe = -myTauLastDecel + sqrt(myTauLastDecel * myTauLastDecel + predSpeed * predSpeed + 2.0 * myDecel * gap);
100 const double asafe = SPEED2ACCEL(vsafe - speed);
102 double apref = vars->aOld;
103 if (apref <= asafe && RandHelper::rand(veh->getRNG()) <= myActionPointProbability * TS) {
104 apref = myDecelDivTau * (gap + (predSpeed - speed) * myHeadwayTime - speed * myHeadwayTime) / (speed + myTauDecel);
105 apref = MIN2(apref, myAccel);
106 apref = MAX2(apref, -myDecel);
107 apref += myDawdle * RandHelper::rand((double) - 1., (double)1., veh->getRNG());
108 }
109 if (apref > asafe) {
110 apref = asafe;
111 }
112 return MAX2(0., speed + ACCEL2SPEED(apref));
113}
114
115// uses the safe speed and preferred acceleration with the same NORMAL tau to compute stopSpeed
116double
117MSCFModel_PWag2009::stopSpeed(const MSVehicle* const /* veh */, const double speed, double gap, double /*decel*/, const CalcReason /*usage*/) const {
118 if (gap < 0.01) {
119 return 0.;
120 }
121 const double vsafe = -myTauDecel + sqrt(myTauDecel * myTauDecel + 2.0 * myDecel * gap);
122 const double asafe = SPEED2ACCEL(vsafe - speed);
123// VehicleVariables* vars = (VehicleVariables*)veh->getCarFollowVariables();
124 double apref = myDecelDivTau * (gap - 2 * speed * myHeadwayTime) / (speed + myTauDecel);
125 if (apref <= asafe) {
126 apref = MIN2(apref, myAccel);
127 apref = MAX2(apref, -myDecel);
128 } else {
129 apref = asafe;
130 }
131 return MAX2(0., vsafe + ACCEL2SPEED(apref));
132}
133
134
137 return new MSCFModel_PWag2009(vtype);
138}
#define TLF(string,...)
Definition MsgHandler.h:306
#define ACCEL2SPEED(x)
Definition SUMOTime.h:54
#define TS
Definition SUMOTime.h:45
#define SPEED2ACCEL(x)
Definition SUMOTime.h:56
@ SUMO_TAG_CFM_VARIABLES
@ SUMO_ATTR_CF_PWAGNER2009_TAULAST
@ SUMO_ATTR_COLLISION_MINGAP_FACTOR
@ SUMO_ATTR_CF_PWAGNER2009_APPROB
@ SUMO_ATTR_ID
@ SUMO_ATTR_SIGMA
@ SUMO_ATTR_STATE
The state of a link.
T MIN2(T a, T b)
Definition StdDefs.h:80
T MAX2(T a, T b)
Definition StdDefs.h:86
SumoRNG * getRNG() const
void saveState(OutputDevice &out, const MSCFModel &cfm) const
Saves the vehicle variables.
void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the vehicle variables from the given description.
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:59
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:95
double myCollisionMinGapFactor
The factor of minGap that must be maintained to avoid a collision event.
Definition MSCFModel.h:768
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition MSCFModel.h:762
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition MSCFModel.h:759
double myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
Definition MSCFModel.h:771
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:994
The car-following model and parameter.
const SUMOVTypeParameter & getParameter() const
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
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.
#define UNUSED_PARAMETER(x)