Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSCFModel.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-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// The car-following model abstraction
22/****************************************************************************/
23#pragma once
24#include <config.h>
25
26#include <cmath>
27#include <string>
28#include <vector>
32
33#define INVALID_SPEED 299792458 + 1 // nothing can go faster than the speed of light!
34// Factor that the minimum emergency decel is increased by in corresponding situations
35#define EMERGENCY_DECEL_AMPLIFIER 1.2
36
37// ===========================================================================
38// class declarations
39// ===========================================================================
40class MSVehicleType;
41class MSVehicle;
42class MSLane;
43class MSPerson;
44class MSLink;
45class OutputDevice;
47
48
49// ===========================================================================
50// class definitions
51// ===========================================================================
59class MSCFModel {
60
61public:
62
64 public:
65 virtual ~VehicleVariables();
66
72 virtual void saveState(OutputDevice& out, const MSCFModel& cfm) const;
73
79 virtual void loadState(const SUMOSAXAttributes& attrs);
80 };
81
85 MSCFModel(const MSVehicleType* vtype);
86
87
89 virtual ~MSCFModel();
90
91
105
106
109
116 virtual double finalizeSpeed(MSVehicle* const veh, double vPos) const;
117
118
120 virtual double patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
121 UNUSED_PARAMETER(veh);
122 UNUSED_PARAMETER(vMin);
123 return vMax;
124 }
125
127 virtual double applyStartupDelay(const MSVehicle* veh, const double vMin, const double vMax, const SUMOTime addTime = 0) const;
128
130 virtual double interpolateProfile(const double speed, const std::vector<std::pair<double, double> > profile) const;
131
132
146 virtual double freeSpeed(const MSVehicle* const veh, double speed, double seen,
147 double maxSpeed, const bool onInsertion = false, const CalcReason usage = CalcReason::CURRENT) const;
148
149
160 virtual double followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed,
161 double predMaxDecel, const MSVehicle* const pred = 0, const CalcReason usage = CalcReason::CURRENT) const = 0;
162
163
176 virtual double insertionFollowSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const;
177
178
189 inline double stopSpeed(const MSVehicle* const veh, const double speed, double gap, const CalcReason usage = CalcReason::CURRENT) const {
190 return stopSpeed(veh, speed, gap, myDecel, usage);
191 }
192
204 virtual double stopSpeed(const MSVehicle* const veh, const double speed, double gap, double decel, const CalcReason usage = CalcReason::CURRENT) const = 0;
205
206
216 virtual double insertionStopSpeed(const MSVehicle* const veh, double speed, double gap) const;
217
228 virtual double followSpeedTransient(double duration, const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const;
229
238 virtual double interactionGap(const MSVehicle* const veh, double vL) const;
239
240
245 virtual double maximumLaneSpeedCF(const MSVehicle* const veh, double maxSpeed, double maxSpeedLane) const {
246 double result = MIN2(maxSpeed, maxSpeedLane);
247 applyOwnSpeedPerceptionError(veh, result);
248 return result;
249 }
250
251
255 virtual int getModelID() const = 0;
256
257
262 virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
263
264
269 return 0;
270 }
272
273
277 inline double getMaxAccel() const {
278 return myAccel;
279 }
280
281
285 inline double getMaxDecel() const {
286 return myDecel;
287 }
288
289
293 inline double getEmergencyDecel() const {
294 return myEmergencyDecel;
295 }
296
297
301 inline double getApparentDecel() const {
302 return myApparentDecel;
303 }
304
305
309 inline SUMOTime getStartupDelay() const {
310 return myStartupDelay;
311 }
312
316 virtual double getCurrentAccel(const double speed) const;
317
318
325
326
333
334
337 inline double getCollisionMinGapFactor() const {
339 }
340
343
347 virtual double getImperfection() const {
348 return -1;
349 }
350
351
355 virtual double getHeadwayTime() const {
356 return myHeadwayTime;
357 }
358
360 virtual bool startupDelayStopped() const {
361 return false;
362 }
364
365
366
367
370
383 virtual double maxNextSpeed(double speed, const MSVehicle* const veh) const;
384
385
391 inline virtual double maxNextSafeMin(double speed, const MSVehicle* const veh = 0) const {
392 return maxNextSpeed(speed, veh);
393 }
394
395
405 virtual double minNextSpeed(double speed, const MSVehicle* const veh = 0) const;
406
416 virtual double minNextSpeedEmergency(double speed, const MSVehicle* const veh = 0) const;
417
418
424 double brakeGap(const double speed) const {
425 return brakeGap(speed, myDecel, myHeadwayTime);
426 }
427
428 virtual double brakeGap(const double speed, const double decel, const double headwayTime) const;
429
430 static double brakeGapEuler(const double speed, const double decel, const double headwayTime);
431
432 static double freeSpeed(const double currentSpeed, const double decel, const double dist, const double maxSpeed, const bool onInsertion, const double actionStepLength);
433
441 virtual double getSecureGap(const MSVehicle* const veh, const MSVehicle* const /*pred*/, const double speed, const double leaderSpeed, const double leaderMaxDecel) const;
442
443 virtual
447 inline double getSpeedAfterMaxDecel(double v) const {
448 return MAX2(0., v - ACCEL2SPEED(myDecel));
449 }
451
457 SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const;
458
459
468 static double estimateArrivalTime(double dist, double speed, double maxSpeed, double accel);
469
483 static double estimateArrivalTime(double dist, double initialSpeed, double arrivalSpeed, double maxSpeed, double accel, double decel);
484
491 static double avoidArrivalAccel(double dist, double time, double speed, double maxDecel);
492
493
498 double getMinimalArrivalSpeed(double dist, double currentSpeed) const;
499
504 double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const;
505
506
520 static double gapExtrapolation(const double duration, const double currentGap, double v1, double v2, double a1 = 0, double a2 = 0, const double maxV1 = std::numeric_limits<double>::max(), const double maxV2 = std::numeric_limits<double>::max());
521
534 static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed);
535
536
537
549 static double speedAfterTime(const double t, const double oldSpeed, const double dist);
550
551
553 virtual double distAfterTime(double t, double speed, double accel) const;
554
555
556
557 /* @brief estimate speed while accelerating for the given distance
558 * @param[in] dist The distance during which accelerating takes place
559 * @param[in] v The initial speed
560 * @param[in] accel The acceleration
561 * XXX affected by ticket #860 (the formula is invalid for the Euler position update rule)
562 * XXX (Leo) Migrated estimateSpeedAfterDistance() to MSCFModel from MSVehicle as Jakob suggested (removed inline property, because myType is fw-declared)
563 */
564 double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const;
565
568
572 virtual void setMaxAccel(double accel) {
573 myAccel = accel;
574 }
575
576
580 virtual void setMaxDecel(double decel) {
581 myDecel = decel;
582 }
583
584
588 virtual void setEmergencyDecel(double decel) {
589 myEmergencyDecel = decel;
590 }
591
592
596 virtual void setApparentDecel(double decel) {
597 myApparentDecel = decel;
598 }
599
600
604 inline void setCollisionMinGapFactor(const double factor) {
606 }
607
608
613 myMaxAccelProfile = accelProfile;
614 }
615
620 myDesAccelProfile = accelProfile;
621 }
622
623
627 virtual void setImperfection(double imperfection) {
628 UNUSED_PARAMETER(imperfection);
629 }
630
631
635 virtual void setHeadwayTime(double headwayTime) {
636 myHeadwayTime = headwayTime;
637 }
639
648 double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion = false) const;
649
650
662 double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const;
663
664
673 double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion = false, double headway = -1, bool relaxEmergency = true) const;
674
675
683 double maximumSafeStopSpeedEuler(double gap, double decel, bool onInsertion, double headway) const;
684
685
698 double maximumSafeStopSpeedBallistic(double gap, double decel, double currentSpeed, bool onInsertion = false, double headway = -1) const;
699
707 virtual std::string getParameter(const MSVehicle* veh, const std::string& key) const {
708 UNUSED_PARAMETER(veh);
709 UNUSED_PARAMETER(key);
710 return "";
711 }
712
720 virtual void setParameter(MSVehicle* veh, const std::string& key, const std::string& value) const {
721 UNUSED_PARAMETER(veh);
722 UNUSED_PARAMETER(key);
723 UNUSED_PARAMETER(value);
724 throw InvalidArgument("Setting parameter '" + key + "' is not supported by carFollowModel");
725 }
726
727protected:
728
734 void applyOwnSpeedPerceptionError(const MSVehicle* const veh, double& speed) const;
735
744 void applyHeadwayAndSpeedDifferencePerceptionErrors(const MSVehicle* const veh, double speed, double& gap, double& predSpeed, double predMaxDecel, const MSVehicle* const pred) const;
745
751 void applyHeadwayPerceptionError(const MSVehicle* const veh, double speed, double& gap) const;
752
753
754protected:
757
759 double myAccel;
760
762 double myDecel;
769
772
775
778
781
782
783
784};
long long int SUMOTime
Definition GUI.h:36
#define ACCEL2SPEED(x)
Definition SUMOTime.h:54
T MIN2(T a, T b)
Definition StdDefs.h:80
T MAX2(T a, T b)
Definition StdDefs.h:86
std::map< double, double > LinearApproxMap
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the vehicle variables from the given description.
Definition MSCFModel.cpp:82
virtual void saveState(OutputDevice &out, const MSCFModel &cfm) const
Saves the vehicle variables.
Definition MSCFModel.cpp:76
The car-following model abstraction.
Definition MSCFModel.h:59
double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const
virtual double stopSpeed(const MSVehicle *const veh, const double speed, double gap, double decel, const CalcReason usage=CalcReason::CURRENT) const =0
Computes the vehicle'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.
void setCollisionMinGapFactor(const double factor)
Sets a new value for the factor of minGap that must be maintained to avoid a collision event.
Definition MSCFModel.h:604
virtual double getCurrentAccel(const double speed) const
Get the vehicle type's maximum acceleration [m/s^2].
static double gapExtrapolation(const double duration, const double currentGap, double v1, double v2, double a1=0, double a2=0, const double maxV1=std::numeric_limits< double >::max(), const double maxV2=std::numeric_limits< double >::max())
return the resulting gap if, starting with gap currentGap, two vehicles continue with constant accele...
virtual double minNextSpeedEmergency(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed after emergency braking, given the current speed (depends on the numerical ...
virtual std::string getParameter(const MSVehicle *veh, const std::string &key) const
try to get the given parameter for this carFollowingModel
Definition MSCFModel.h:707
virtual double followSpeedTransient(double duration, const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle's follow speed that avoids a collision for the given amount of time.
virtual void setImperfection(double imperfection)
Sets a new value for driver imperfection.
Definition MSCFModel.h:627
virtual double applyStartupDelay(const MSVehicle *veh, const double vMin, const double vMax, const SUMOTime addTime=0) const
apply speed adaptation on startup
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting.
Definition MSCFModel.h:268
double getCollisionMinGapFactor() const
Get the factor of minGap that must be maintained to avoid a collision event.
Definition MSCFModel.h:337
double getEmergencyDecel() const
Get the vehicle type's maximal physically possible deceleration [m/s^2].
Definition MSCFModel.h:293
static double brakeGapEuler(const double speed, const double decel, const double headwayTime)
virtual double interactionGap(const MSVehicle *const veh, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
static double avoidArrivalAccel(double dist, double time, double speed, double maxDecel)
Computes the acceleration needed to arrive not before the given time.
SUMOTime getStartupDelay() const
Get the vehicle type's startupDelay.
Definition MSCFModel.h:309
double getMinimalArrivalSpeed(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
virtual void setHeadwayTime(double headwayTime)
Sets a new value for desired headway [s].
Definition MSCFModel.h:635
virtual double patchSpeedBeforeLC(const MSVehicle *veh, double vMin, double vMax) const
apply custom speed adaptations within the given speed bounds
Definition MSCFModel.h:120
virtual double freeSpeed(const MSVehicle *const veh, double speed, double seen, double maxSpeed, const bool onInsertion=false, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed without a leader.
virtual double minNextSpeed(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed given the current speed (depends on the numerical update scheme and its ste...
virtual double insertionFollowSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0) const
Computes the vehicle's safe speed (no dawdling) This method is used during the insertion stage....
SUMOTime myStartupDelay
The startup delay after halting [s].
Definition MSCFModel.h:774
virtual void setEmergencyDecel(double decel)
Sets a new value for maximal physically possible deceleration [m/s^2].
Definition MSCFModel.h:588
SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const
Computes the minimal time needed to cover a distance given the desired speed at arrival.
void applyHeadwayPerceptionError(const MSVehicle *const veh, double speed, double &gap) const
Overwrites gap by the perceived value obtained from the vehicle's driver state.
virtual void setMaxAccel(double accel)
Sets a new value for maximum acceleration [m/s^2].
Definition MSCFModel.h:572
static double speedAfterTime(const double t, const double oldSpeed, const double dist)
Calculates the speed after a time t \in [0,TS] given the initial speed and the distance traveled in a...
static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed)
Calculates the time at which the position passedPosition has been passed In case of a ballistic updat...
virtual double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences. Called at most once per simulation...
virtual ~MSCFModel()
Destructor.
Definition MSCFModel.cpp:70
double maximumSafeStopSpeedEuler(double gap, double decel, bool onInsertion, double headway) const
Returns the maximum next velocity for stopping within gap when using the semi-implicit Euler update.
virtual bool startupDelayStopped() const
whether startupDelay should be applied after stopping
Definition MSCFModel.h:360
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition MSCFModel.h:580
double myEmergencyDecel
The vehicle's maximum emergency deceleration [m/s^2].
Definition MSCFModel.h:764
LinearApproxHelpers::LinearApproxMap getDesAccelProfile() const
Get the vehicle type's desired acceleration profile depending on the velocity [m/s^2].
Definition MSCFModel.h:330
void applyHeadwayAndSpeedDifferencePerceptionErrors(const MSVehicle *const veh, double speed, double &gap, double &predSpeed, double predMaxDecel, const MSVehicle *const pred) const
Overwrites gap2pred and predSpeed by the perceived values obtained from the vehicle's driver state,...
double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion=false) const
Returns the maximum safe velocity for following the given leader.
virtual void setDesAccelProfile(const LinearApproxHelpers::LinearApproxMap &accelProfile)
Sets a new value for desired acceleration profile [m/s^2].
Definition MSCFModel.h:619
virtual void setMaxAccelProfile(const LinearApproxHelpers::LinearApproxMap &accelProfile)
Sets a new value for maximum acceleration profile [m/s^2].
Definition MSCFModel.h:612
CalcReason
What the return value of stop/follow/free-Speed is used for.
Definition MSCFModel.h:95
@ FUTURE
the return value is used for calculating future speeds
Definition MSCFModel.h:99
@ LANE_CHANGE
the return value is used for lane change calculations
Definition MSCFModel.h:103
@ CURRENT
the return value is used for calculating the next speed
Definition MSCFModel.h:97
@ CURRENT_WAIT
the return value is used for calculating junction stop speeds
Definition MSCFModel.h:101
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)
virtual double maxNextSafeMin(double speed, const MSVehicle *const veh=0) const
Returns the maximum speed given the current speed and regarding driving dynamics.
Definition MSCFModel.h:391
double myCollisionMinGapFactor
The factor of minGap that must be maintained to avoid a collision event.
Definition MSCFModel.h:768
double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const
Returns the minimal deceleration for following the given leader safely.
double getApparentDecel() const
Get the vehicle type's apparent deceleration [m/s^2] (the one regarded by its followers.
Definition MSCFModel.h:301
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition MSCFModel.h:762
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition MSCFModel.h:277
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition MSCFModel.h:424
virtual double maximumLaneSpeedCF(const MSVehicle *const veh, double maxSpeed, double maxSpeedLane) const
Returns the maximum velocity the CF-model wants to achieve in the next step.
Definition MSCFModel.h:245
virtual int getModelID() const =0
Returns the model's ID; the XML-Tag number is used.
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.
void applyOwnSpeedPerceptionError(const MSVehicle *const veh, double &speed) const
Overwrites sped by the perceived values obtained from the vehicle's driver state,.
virtual double interpolateProfile(const double speed, const std::vector< std::pair< double, double > > profile) const
Get current interpolated value from a profile.
virtual double getImperfection() const
Get the driver's imperfection.
Definition MSCFModel.h:347
LinearApproxHelpers::LinearApproxMap myMaxAccelProfile
The vehicle's maximum acceleration profile [m/s^2].
Definition MSCFModel.h:777
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition MSCFModel.h:759
LinearApproxHelpers::LinearApproxMap myDesAccelProfile
The vehicle's desired acceleration profile [m/s^2].
Definition MSCFModel.h:780
LinearApproxHelpers::LinearApproxMap getMaxAccelProfile() const
Get the vehicle type's maximum acceleration profile depending on the velocity [m/s^2].
Definition MSCFModel.h:322
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition MSCFModel.h:756
virtual double distAfterTime(double t, double speed, double accel) const
calculates the distance traveled after accelerating for time t
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
Definition MSCFModel.h:285
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition MSCFModel.h:447
virtual void setApparentDecel(double decel)
Sets a new value for the apparent deceleration [m/s^2].
Definition MSCFModel.h:596
virtual void setParameter(MSVehicle *veh, const std::string &key, const std::string &value) const
try to set the given parameter for this carFollowingModel
Definition MSCFModel.h:720
double maximumSafeStopSpeedBallistic(double gap, double decel, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap when using the ballistic positional update.
double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update.
static double estimateArrivalTime(double dist, double speed, double maxSpeed, double accel)
Computes the time needed to travel a distance dist given an initial speed and constant acceleration....
virtual 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 =0
Computes the vehicle's follow speed (no dawdling)
double myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
Definition MSCFModel.h:771
double stopSpeed(const MSVehicle *const veh, const double speed, double gap, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
Definition MSCFModel.h:189
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const =0
Duplicates the car-following model.
double myApparentDecel
The vehicle's deceleration as expected by surrounding traffic [m/s^2].
Definition MSCFModel.h:766
virtual double insertionStopSpeed(const MSVehicle *const veh, double speed, double gap) const
Computes the vehicle's safe speed for approaching an obstacle at insertion without constraints due to...
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Definition MSCFModel.h:355
Representation of a lane in the micro simulation.
Definition MSLane.h:84
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
The car-following model and parameter.
Static storage of an output device and its base (abstract) implementation.
Encapsulated SAX-Attributes.
#define UNUSED_PARAMETER(x)