Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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-2025 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;
45
46
47// ===========================================================================
48// class definitions
49// ===========================================================================
57class MSCFModel {
58
59public:
60
62 public:
63 virtual ~VehicleVariables();
64 };
65
69 MSCFModel(const MSVehicleType* vtype);
70
71
73 virtual ~MSCFModel();
74
75
89
90
93
100 virtual double finalizeSpeed(MSVehicle* const veh, double vPos) const;
101
102
104 virtual double patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
105 UNUSED_PARAMETER(veh);
106 UNUSED_PARAMETER(vMin);
107 return vMax;
108 }
109
111 virtual double applyStartupDelay(const MSVehicle* veh, const double vMin, const double vMax, const SUMOTime addTime = 0) const;
112
114 virtual double interpolateProfile(const double speed, const std::vector<std::pair<double, double> > profile) const;
115
116
130 virtual double freeSpeed(const MSVehicle* const veh, double speed, double seen,
131 double maxSpeed, const bool onInsertion = false, const CalcReason usage = CalcReason::CURRENT) const;
132
133
144 virtual double followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed,
145 double predMaxDecel, const MSVehicle* const pred = 0, const CalcReason usage = CalcReason::CURRENT) const = 0;
146
147
160 virtual double insertionFollowSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const;
161
162
173 inline double stopSpeed(const MSVehicle* const veh, const double speed, double gap, const CalcReason usage = CalcReason::CURRENT) const {
174 return stopSpeed(veh, speed, gap, myDecel, usage);
175 }
176
188 virtual double stopSpeed(const MSVehicle* const veh, const double speed, double gap, double decel, const CalcReason usage = CalcReason::CURRENT) const = 0;
189
190
200 virtual double insertionStopSpeed(const MSVehicle* const veh, double speed, double gap) const;
201
212 virtual double followSpeedTransient(double duration, const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const;
213
222 virtual double interactionGap(const MSVehicle* const veh, double vL) const;
223
224
229 virtual double maximumLaneSpeedCF(const MSVehicle* const veh, double maxSpeed, double maxSpeedLane) const {
230 double result = MIN2(maxSpeed, maxSpeedLane);
231 applyOwnSpeedPerceptionError(veh, result);
232 return result;
233 }
234
235
239 virtual int getModelID() const = 0;
240
241
246 virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
247
248
253 return 0;
254 }
256
257
261 inline double getMaxAccel() const {
262 return myAccel;
263 }
264
265
269 inline double getMaxDecel() const {
270 return myDecel;
271 }
272
273
277 inline double getEmergencyDecel() const {
278 return myEmergencyDecel;
279 }
280
281
285 inline double getApparentDecel() const {
286 return myApparentDecel;
287 }
288
289
293 inline SUMOTime getStartupDelay() const {
294 return myStartupDelay;
295 }
296
300 virtual double getCurrentAccel(const double speed) const;
301
302
309
310
317
318
321 inline double getCollisionMinGapFactor() const {
323 }
324
327
331 virtual double getImperfection() const {
332 return -1;
333 }
334
335
339 virtual double getHeadwayTime() const {
340 return myHeadwayTime;
341 }
342
344 virtual bool startupDelayStopped() const {
345 return false;
346 }
348
349
350
351
354
367 virtual double maxNextSpeed(double speed, const MSVehicle* const veh) const;
368
369
375 inline virtual double maxNextSafeMin(double speed, const MSVehicle* const veh = 0) const {
376 return maxNextSpeed(speed, veh);
377 }
378
379
389 virtual double minNextSpeed(double speed, const MSVehicle* const veh = 0) const;
390
400 virtual double minNextSpeedEmergency(double speed, const MSVehicle* const veh = 0) const;
401
402
408 double brakeGap(const double speed) const {
409 return brakeGap(speed, myDecel, myHeadwayTime);
410 }
411
412 virtual double brakeGap(const double speed, const double decel, const double headwayTime) const;
413
414 static double brakeGapEuler(const double speed, const double decel, const double headwayTime);
415
416 static double freeSpeed(const double currentSpeed, const double decel, const double dist, const double maxSpeed, const bool onInsertion, const double actionStepLength);
417
425 virtual double getSecureGap(const MSVehicle* const veh, const MSVehicle* const /*pred*/, const double speed, const double leaderSpeed, const double leaderMaxDecel) const;
426
427 virtual
431 inline double getSpeedAfterMaxDecel(double v) const {
432 return MAX2(0., v - ACCEL2SPEED(myDecel));
433 }
435
441 SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const;
442
443
452 static double estimateArrivalTime(double dist, double speed, double maxSpeed, double accel);
453
467 static double estimateArrivalTime(double dist, double initialSpeed, double arrivalSpeed, double maxSpeed, double accel, double decel);
468
475 static double avoidArrivalAccel(double dist, double time, double speed, double maxDecel);
476
477
482 double getMinimalArrivalSpeed(double dist, double currentSpeed) const;
483
488 double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const;
489
490
504 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());
505
518 static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed);
519
520
521
533 static double speedAfterTime(const double t, const double oldSpeed, const double dist);
534
535
537 virtual double distAfterTime(double t, double speed, double accel) const;
538
539
540
541 /* @brief estimate speed while accelerating for the given distance
542 * @param[in] dist The distance during which accelerating takes place
543 * @param[in] v The initial speed
544 * @param[in] accel The acceleration
545 * XXX affected by ticket #860 (the formula is invalid for the Euler position update rule)
546 * XXX (Leo) Migrated estimateSpeedAfterDistance() to MSCFModel from MSVehicle as Jakob suggested (removed inline property, because myType is fw-declared)
547 */
548 double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const;
549
552
556 virtual void setMaxAccel(double accel) {
557 myAccel = accel;
558 }
559
560
564 virtual void setMaxDecel(double decel) {
565 myDecel = decel;
566 }
567
568
572 virtual void setEmergencyDecel(double decel) {
573 myEmergencyDecel = decel;
574 }
575
576
580 virtual void setApparentDecel(double decel) {
581 myApparentDecel = decel;
582 }
583
584
588 inline void setCollisionMinGapFactor(const double factor) {
590 }
591
592
597 myMaxAccelProfile = accelProfile;
598 }
599
604 myDesAccelProfile = accelProfile;
605 }
606
607
611 virtual void setImperfection(double imperfection) {
612 UNUSED_PARAMETER(imperfection);
613 }
614
615
619 virtual void setHeadwayTime(double headwayTime) {
620 myHeadwayTime = headwayTime;
621 }
623
632 double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion = false) const;
633
634
646 double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const;
647
648
657 double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion = false, double headway = -1, bool relaxEmergency = true) const;
658
659
667 double maximumSafeStopSpeedEuler(double gap, double decel, bool onInsertion, double headway) const;
668
669
682 double maximumSafeStopSpeedBallistic(double gap, double decel, double currentSpeed, bool onInsertion = false, double headway = -1) const;
683
691 virtual std::string getParameter(const MSVehicle* veh, const std::string& key) const {
692 UNUSED_PARAMETER(veh);
693 UNUSED_PARAMETER(key);
694 return "";
695 }
696
704 virtual void setParameter(MSVehicle* veh, const std::string& key, const std::string& value) const {
705 UNUSED_PARAMETER(veh);
706 UNUSED_PARAMETER(key);
707 UNUSED_PARAMETER(value);
708 throw InvalidArgument("Setting parameter '" + key + "' is not supported by carFollowModel");
709 }
710
711protected:
712
718 void applyOwnSpeedPerceptionError(const MSVehicle* const veh, double& speed) const;
719
728 void applyHeadwayAndSpeedDifferencePerceptionErrors(const MSVehicle* const veh, double speed, double& gap, double& predSpeed, double predMaxDecel, const MSVehicle* const pred) const;
729
735 void applyHeadwayPerceptionError(const MSVehicle* const veh, double speed, double& gap) const;
736
737
738protected:
741
743 double myAccel;
744
746 double myDecel;
753
756
759
762
765
766
767
768};
long long int SUMOTime
Definition GUI.h:36
#define ACCEL2SPEED(x)
Definition SUMOTime.h:51
T MIN2(T a, T b)
Definition StdDefs.h:76
T MAX2(T a, T b)
Definition StdDefs.h:82
std::map< double, double > LinearApproxMap
The car-following model abstraction.
Definition MSCFModel.h:57
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:588
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:691
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:611
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:252
double getCollisionMinGapFactor() const
Get the factor of minGap that must be maintained to avoid a collision event.
Definition MSCFModel.h:321
double getEmergencyDecel() const
Get the vehicle type's maximal physically possible deceleration [m/s^2].
Definition MSCFModel.h:277
static double brakeGapEuler(const double speed, const double decel, const double headwayTime)
Definition MSCFModel.cpp:92
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:293
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:619
virtual double patchSpeedBeforeLC(const MSVehicle *veh, double vMin, double vMax) const
apply custom speed adaptations within the given speed bounds
Definition MSCFModel.h:104
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:758
virtual void setEmergencyDecel(double decel)
Sets a new value for maximal physically possible deceleration [m/s^2].
Definition MSCFModel.h:572
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:556
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:344
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition MSCFModel.h:564
double myEmergencyDecel
The vehicle's maximum emergency deceleration [m/s^2].
Definition MSCFModel.h:748
LinearApproxHelpers::LinearApproxMap getDesAccelProfile() const
Get the vehicle type's desired acceleration profile depending on the velocity [m/s^2].
Definition MSCFModel.h:314
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:603
virtual void setMaxAccelProfile(const LinearApproxHelpers::LinearApproxMap &accelProfile)
Sets a new value for maximum acceleration profile [m/s^2].
Definition MSCFModel.h:596
CalcReason
What the return value of stop/follow/free-Speed is used for.
Definition MSCFModel.h:79
@ FUTURE
the return value is used for calculating future speeds
Definition MSCFModel.h:83
@ LANE_CHANGE
the return value is used for lane change calculations
Definition MSCFModel.h:87
@ CURRENT
the return value is used for calculating the next speed
Definition MSCFModel.h:81
@ CURRENT_WAIT
the return value is used for calculating junction stop speeds
Definition MSCFModel.h:85
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:375
double myCollisionMinGapFactor
The factor of minGap that must be maintained to avoid a collision event.
Definition MSCFModel.h:752
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:285
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition MSCFModel.h:746
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition MSCFModel.h:261
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition MSCFModel.h:408
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:229
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:331
LinearApproxHelpers::LinearApproxMap myMaxAccelProfile
The vehicle's maximum acceleration profile [m/s^2].
Definition MSCFModel.h:761
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition MSCFModel.h:743
LinearApproxHelpers::LinearApproxMap myDesAccelProfile
The vehicle's desired acceleration profile [m/s^2].
Definition MSCFModel.h:764
LinearApproxHelpers::LinearApproxMap getMaxAccelProfile() const
Get the vehicle type's maximum acceleration profile depending on the velocity [m/s^2].
Definition MSCFModel.h:306
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition MSCFModel.h:740
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:269
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition MSCFModel.h:431
virtual void setApparentDecel(double decel)
Sets a new value for the apparent deceleration [m/s^2].
Definition MSCFModel.h:580
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:704
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:755
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:173
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:750
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:339
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.
#define UNUSED_PARAMETER(x)