Eclipse SUMO - Simulation of Urban MObility
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-2023 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>
30
31#define INVALID_SPEED 299792458 + 1 // nothing can go faster than the speed of light!
32// Factor that the minimum emergency decel is increased by in corresponding situations
33#define EMERGENCY_DECEL_AMPLIFIER 1.2
34
35// ===========================================================================
36// class declarations
37// ===========================================================================
38class MSVehicleType;
39class MSVehicle;
40class MSLane;
41class MSPerson;
42class MSLink;
43
44
45// ===========================================================================
46// class definitions
47// ===========================================================================
55class MSCFModel {
56
57public:
58
60 public:
61 virtual ~VehicleVariables();
62 };
63
67 MSCFModel(const MSVehicleType* vtype);
68
69
71 virtual ~MSCFModel();
72
73
86 };
87
88
91
98 virtual double finalizeSpeed(MSVehicle* const veh, double vPos) const;
99
100
102 virtual double patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
103 UNUSED_PARAMETER(veh);
104 UNUSED_PARAMETER(vMin);
105 return vMax;
106 }
107
109 virtual double applyStartupDelay(const MSVehicle* veh, const double vMin, const double vMax, const SUMOTime addTime = 0) const;
110
111
125 virtual double freeSpeed(const MSVehicle* const veh, double speed, double seen,
126 double maxSpeed, const bool onInsertion = false, const CalcReason usage = CalcReason::CURRENT) const;
127
128
139 virtual double followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed,
140 double predMaxDecel, const MSVehicle* const pred = 0, const CalcReason usage = CalcReason::CURRENT) const = 0;
141
142
155 virtual double insertionFollowSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const;
156
157
168 inline double stopSpeed(const MSVehicle* const veh, const double speed, double gap, const CalcReason usage = CalcReason::CURRENT) const {
169 return stopSpeed(veh, speed, gap, myDecel, usage);
170 }
171
183 virtual double stopSpeed(const MSVehicle* const veh, const double speed, double gap, double decel, const CalcReason usage = CalcReason::CURRENT) const = 0;
184
185
195 virtual double insertionStopSpeed(const MSVehicle* const veh, double speed, double gap) const;
196
207 virtual double followSpeedTransient(double duration, const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const;
208
217 virtual double interactionGap(const MSVehicle* const veh, double vL) const;
218
219
224 virtual double maximumLaneSpeedCF(const MSVehicle* const veh, double maxSpeed, double maxSpeedLane) const {
225 double result = MIN2(maxSpeed, maxSpeedLane);
226 applyOwnSpeedPerceptionError(veh, result);
227 return result;
228 }
229
230
234 virtual int getModelID() const = 0;
235
236
241 virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
242
243
248 return 0;
249 }
251
252
256 inline double getMaxAccel() const {
257 return myAccel;
258 }
259
260
264 inline double getMaxDecel() const {
265 return myDecel;
266 }
267
268
272 inline double getEmergencyDecel() const {
273 return myEmergencyDecel;
274 }
275
276
280 inline double getApparentDecel() const {
281 return myApparentDecel;
282 }
283
287 inline SUMOTime getStartupDelay() const {
288 return myStartupDelay;
289 }
290
293 inline double getCollisionMinGapFactor() const {
295 }
296
299
303 virtual double getImperfection() const {
304 return -1;
305 }
306
307
311 virtual double getHeadwayTime() const {
312 return myHeadwayTime;
313 }
314
316 virtual bool startupDelayStopped() const {
317 return false;
318 }
320
321
322
323
326
339 virtual double maxNextSpeed(double speed, const MSVehicle* const veh) const;
340
341
347 inline virtual double maxNextSafeMin(double speed, const MSVehicle* const veh = 0) const {
348 return maxNextSpeed(speed, veh);
349 }
350
351
361 virtual double minNextSpeed(double speed, const MSVehicle* const veh = 0) const;
362
372 virtual double minNextSpeedEmergency(double speed, const MSVehicle* const veh = 0) const;
373
374
380 double brakeGap(const double speed) const {
381 return brakeGap(speed, myDecel, myHeadwayTime);
382 }
383
384 virtual double brakeGap(const double speed, const double decel, const double headwayTime) const;
385
386 static double brakeGapEuler(const double speed, const double decel, const double headwayTime);
387
388 static double freeSpeed(const double currentSpeed, const double decel, const double dist, const double maxSpeed, const bool onInsertion, const double actionStepLength);
389
397 virtual double getSecureGap(const MSVehicle* const veh, const MSVehicle* const /*pred*/, const double speed, const double leaderSpeed, const double leaderMaxDecel) const;
398
399 virtual
403 inline double getSpeedAfterMaxDecel(double v) const {
404 return MAX2(0., v - ACCEL2SPEED(myDecel));
405 }
407
413 SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const;
414
415
424 static double estimateArrivalTime(double dist, double speed, double maxSpeed, double accel);
425
439 static double estimateArrivalTime(double dist, double initialSpeed, double arrivalSpeed, double maxSpeed, double accel, double decel);
440
447 static double avoidArrivalAccel(double dist, double time, double speed, double maxDecel);
448
449
454 double getMinimalArrivalSpeed(double dist, double currentSpeed) const;
455
460 double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const;
461
462
476 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());
477
490 static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed);
491
492
493
505 static double speedAfterTime(const double t, const double oldSpeed, const double dist);
506
507
509 virtual double distAfterTime(double t, double speed, double accel) const;
510
511
512
513 /* @brief estimate speed while accelerating for the given distance
514 * @param[in] dist The distance during which accelerating takes place
515 * @param[in] v The initial speed
516 * @param[in] accel The acceleration
517 * XXX affected by ticket #860 (the formula is invalid for the Euler position update rule)
518 * XXX (Leo) Migrated estimateSpeedAfterDistance() to MSCFModel from MSVehicle as Jakob suggested (removed inline property, because myType is fw-declared)
519 */
520 double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const;
521
524
528 virtual void setMaxAccel(double accel) {
529 myAccel = accel;
530 }
531
532
536 virtual void setMaxDecel(double decel) {
537 myDecel = decel;
538 }
539
540
544 virtual void setEmergencyDecel(double decel) {
545 myEmergencyDecel = decel;
546 }
547
548
552 virtual void setApparentDecel(double decel) {
553 myApparentDecel = decel;
554 }
555
556
560 virtual void setImperfection(double imperfection) {
561 UNUSED_PARAMETER(imperfection);
562 }
563
564
568 virtual void setHeadwayTime(double headwayTime) {
569 myHeadwayTime = headwayTime;
570 }
572
581 double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion = false) const;
582
583
595 double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const;
596
597
606 double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion = false, double headway = -1, bool relaxEmergency = true) const;
607
608
616 double maximumSafeStopSpeedEuler(double gap, double decel, bool onInsertion, double headway) const;
617
618
631 double maximumSafeStopSpeedBallistic(double gap, double decel, double currentSpeed, bool onInsertion = false, double headway = -1) const;
632
640 virtual std::string getParameter(const MSVehicle* veh, const std::string& key) const {
641 UNUSED_PARAMETER(veh);
642 UNUSED_PARAMETER(key);
643 return "";
644 }
645
653 virtual void setParameter(MSVehicle* veh, const std::string& key, const std::string& value) const {
654 UNUSED_PARAMETER(veh);
655 UNUSED_PARAMETER(key);
656 UNUSED_PARAMETER(value);
657 throw InvalidArgument("Setting parameter '" + key + "' is not supported by carFollowModel");
658 }
659
660protected:
661
667 void applyOwnSpeedPerceptionError(const MSVehicle* const veh, double& speed) const;
668
677 void applyHeadwayAndSpeedDifferencePerceptionErrors(const MSVehicle* const veh, double speed, double& gap, double& predSpeed, double predMaxDecel, const MSVehicle* const pred) const;
678
684 void applyHeadwayPerceptionError(const MSVehicle* const veh, double speed, double& gap) const;
685
686
687protected:
690
692 double myAccel;
693
695 double myDecel;
702
705
708
709
710
711};
712
713
714
long long int SUMOTime
Definition: GUI.h:36
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:51
#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
The car-following model abstraction.
Definition: MSCFModel.h:55
double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const
Definition: MSCFModel.cpp:765
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.
Definition: MSCFModel.cpp:292
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...
Definition: MSCFModel.cpp:564
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 ...
Definition: MSCFModel.cpp:309
virtual std::string getParameter(const MSVehicle *veh, const std::string &key) const
try to get the given parameter for this carFollowingModel
Definition: MSCFModel.h:640
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.
Definition: MSCFModel.cpp:353
virtual void setImperfection(double imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:560
virtual double applyStartupDelay(const MSVehicle *veh, const double vMin, const double vMax, const SUMOTime addTime=0) const
apply speed adaptation on startup
Definition: MSCFModel.cpp:257
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting.
Definition: MSCFModel.h:247
double getCollisionMinGapFactor() const
Get the factor of minGap that must be maintained to avoid a collision event.
Definition: MSCFModel.h:293
double getEmergencyDecel() const
Get the vehicle type's maximal phisically possible deceleration [m/s^2].
Definition: MSCFModel.h:272
static double brakeGapEuler(const double speed, const double decel, const double headwayTime)
Definition: MSCFModel.cpp:90
virtual double interactionGap(const MSVehicle *const veh, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
Definition: MSCFModel.cpp:277
static double avoidArrivalAccel(double dist, double time, double speed, double maxDecel)
Computes the acceleration needed to arrive not before the given time.
Definition: MSCFModel.cpp:521
SUMOTime getStartupDelay() const
Get the vehicle type's startupDelay.
Definition: MSCFModel.h:287
double getMinimalArrivalSpeed(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
Definition: MSCFModel.cpp:538
virtual void setHeadwayTime(double headwayTime)
Sets a new value for desired headway [s].
Definition: MSCFModel.h:568
virtual double patchSpeedBeforeLC(const MSVehicle *veh, double vMin, double vMax) const
apply custom speed adaptations within the given speed bounds
Definition: MSCFModel.h:102
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.
Definition: MSCFModel.cpp:321
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...
Definition: MSCFModel.cpp:298
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....
Definition: MSCFModel.cpp:332
SUMOTime myStartupDelay
The startup delay after halting [s].
Definition: MSCFModel.h:707
virtual void setEmergencyDecel(double decel)
Sets a new value for maximal physically possible deceleration [m/s^2].
Definition: MSCFModel.h:544
SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const
Computes the minimal time needed to cover a distance given the desired speed at arrival.
Definition: MSCFModel.cpp:429
void applyHeadwayPerceptionError(const MSVehicle *const veh, double speed, double &gap) const
Overwrites gap by the perceived value obtained from the vehicle's driver state.
Definition: MSCFModel.cpp:1099
virtual void setMaxAccel(double accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:528
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...
Definition: MSCFModel.cpp:736
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...
Definition: MSCFModel.cpp:658
virtual double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences. Called at most once per simulation...
Definition: MSCFModel.cpp:187
virtual ~MSCFModel()
Destructor.
Definition: MSCFModel.cpp:68
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.
Definition: MSCFModel.cpp:827
virtual bool startupDelayStopped() const
whether startupDelay should be applied after stopping
Definition: MSCFModel.h:316
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:536
double myEmergencyDecel
The vehicle's maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:697
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,...
Definition: MSCFModel.cpp:1063
double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion=false) const
Returns the maximum safe velocity for following the given leader.
Definition: MSCFModel.cpp:922
CalcReason
What the return value of stop/follow/free-Speed is used for.
Definition: MSCFModel.h:77
@ FUTURE
the return value is used for calculating future speeds
Definition: MSCFModel.h:81
@ LANE_CHANGE
the return value is used for lane change calculations
Definition: MSCFModel.h:85
@ CURRENT
the return value is used for calculating the next speed
Definition: MSCFModel.h:79
@ CURRENT_WAIT
the return value is used for calculating junction stop speeds
Definition: MSCFModel.h:83
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)
Definition: MSCFModel.cpp:166
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:347
double myCollisionMinGapFactor
The factor of minGap that must be maintained to avoid a collision event.
Definition: MSCFModel.h:701
double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const
Returns the minimal deceleration for following the given leader safely.
Definition: MSCFModel.cpp:1002
MSCFModel(const MSVehicleType *vtype)
Constructor.
Definition: MSCFModel.cpp:55
double getApparentDecel() const
Get the vehicle type's apparent deceleration [m/s^2] (the one regarded by its followers.
Definition: MSCFModel.h:280
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition: MSCFModel.h:695
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition: MSCFModel.h:256
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
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:224
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.
Definition: MSCFModel.cpp:774
void applyOwnSpeedPerceptionError(const MSVehicle *const veh, double &speed) const
Overwrites sped by the perceived values obtained from the vehicle's driver state,.
Definition: MSCFModel.cpp:1054
virtual double getImperfection() const
Get the driver's imperfection.
Definition: MSCFModel.h:303
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition: MSCFModel.h:692
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:689
virtual double distAfterTime(double t, double speed, double accel) const
calculates the distance travelled after accelerating for time t
Definition: MSCFModel.cpp:403
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:264
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:403
virtual void setApparentDecel(double decel)
Sets a new value for the apparent deceleration [m/s^2].
Definition: MSCFModel.h:552
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:653
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.
Definition: MSCFModel.cpp:855
double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update.
Definition: MSCFModel.cpp:545
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....
Definition: MSCFModel.cpp:450
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:704
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:168
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:699
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...
Definition: MSCFModel.cpp:343
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Definition: MSCFModel.h:311
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.
Definition: MSVehicleType.h:63