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.org/sumo
3// Copyright (C) 2001-2022 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(double maxSpeed, double maxSpeedLane) const {
225 return MIN2(maxSpeed, maxSpeedLane);
226 }
227
228
232 virtual int getModelID() const = 0;
233
234
239 virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
240
241
246 return 0;
247 }
249
250
254 inline double getMaxAccel() const {
255 return myAccel;
256 }
257
258
262 inline double getMaxDecel() const {
263 return myDecel;
264 }
265
266
270 inline double getEmergencyDecel() const {
271 return myEmergencyDecel;
272 }
273
274
278 inline double getApparentDecel() const {
279 return myApparentDecel;
280 }
281
285 inline SUMOTime getStartupDelay() const {
286 return myStartupDelay;
287 }
288
291 inline double getCollisionMinGapFactor() const {
293 }
294
297
301 virtual double getImperfection() const {
302 return -1;
303 }
304
305
309 virtual double getHeadwayTime() const {
310 return myHeadwayTime;
311 }
313
314
315
316
319
332 virtual double maxNextSpeed(double speed, const MSVehicle* const veh) const;
333
334
340 inline virtual double maxNextSafeMin(double speed, const MSVehicle* const veh = 0) const {
341 return maxNextSpeed(speed, veh);
342 }
343
344
354 virtual double minNextSpeed(double speed, const MSVehicle* const veh = 0) const;
355
365 virtual double minNextSpeedEmergency(double speed, const MSVehicle* const veh = 0) const;
366
367
373 double brakeGap(const double speed) const {
374 return brakeGap(speed, myDecel, myHeadwayTime);
375 }
376
377 virtual double brakeGap(const double speed, const double decel, const double headwayTime) const;
378
379 static double brakeGapEuler(const double speed, const double decel, const double headwayTime);
380
381 static double freeSpeed(const double currentSpeed, const double decel, const double dist, const double maxSpeed, const bool onInsertion, const double actionStepLength);
382
390 inline virtual double getSecureGap(const MSVehicle* const /*veh*/, const MSVehicle* const /*pred*/, const double speed, const double leaderSpeed, const double leaderMaxDecel) const {
391 // The solution approach leaderBrakeGap >= followerBrakeGap is not
392 // secure when the follower can brake harder than the leader because the paths may still cross.
393 // As a workaround we use a value of leaderDecel which errs on the side of caution
394 const double maxDecel = MAX2(myDecel, leaderMaxDecel);
395 double secureGap = MAX2((double) 0, brakeGap(speed, myDecel, myHeadwayTime) - brakeGap(leaderSpeed, maxDecel, 0));
396 return secureGap;
397 }
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
605 double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion = false, double headway = -1) const;
606
607
615 double maximumSafeStopSpeedEuler(double gap, double decel, bool onInsertion, double headway) const;
616
617
630 double maximumSafeStopSpeedBallistic(double gap, double decel, double currentSpeed, bool onInsertion = false, double headway = -1) const;
631
639 virtual std::string getParameter(const MSVehicle* veh, const std::string& key) const {
640 UNUSED_PARAMETER(veh);
641 UNUSED_PARAMETER(key);
642 return "";
643 }
644
652 virtual void setParameter(MSVehicle* veh, const std::string& key, const std::string& value) const {
653 UNUSED_PARAMETER(veh);
654 UNUSED_PARAMETER(key);
655 UNUSED_PARAMETER(value);
656 }
657
658protected:
659
668 void applyHeadwayAndSpeedDifferencePerceptionErrors(const MSVehicle* const veh, double speed, double& gap, double& predSpeed, double predMaxDecel, const MSVehicle* const pred) const;
669
675 void applyHeadwayPerceptionError(const MSVehicle* const veh, double speed, double& gap) const;
676
677
678protected:
681
683 double myAccel;
684
686 double myDecel;
693
696
699
700
701
702};
703
704
705
long long int SUMOTime
Definition: GUI.h:36
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:50
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
T MIN2(T a, T b)
Definition: StdDefs.h:71
T MAX2(T a, T b)
Definition: StdDefs.h:77
The car-following model abstraction.
Definition: MSCFModel.h:55
double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const
Definition: MSCFModel.cpp:743
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:270
virtual double getSecureGap(const MSVehicle *const, 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.h:390
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:542
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:287
virtual std::string getParameter(const MSVehicle *veh, const std::string &key) const
try to get the given parameter for this carFollowingModel
Definition: MSCFModel.h:639
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:331
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:235
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting.
Definition: MSCFModel.h:245
double getCollisionMinGapFactor() const
Get the factor of minGap that must be maintained to avoid a collision event.
Definition: MSCFModel.h:291
double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap.
Definition: MSCFModel.cpp:752
double getEmergencyDecel() const
Get the vehicle type's maximal phisically possible deceleration [m/s^2].
Definition: MSCFModel.h:270
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:255
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:499
SUMOTime getStartupDelay() const
Get the vehicle type's startupDelay.
Definition: MSCFModel.h:285
double getMinimalArrivalSpeed(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
Definition: MSCFModel.cpp:516
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:299
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:276
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:310
SUMOTime myStartupDelay
The startup delay after halting [s].
Definition: MSCFModel.h:698
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:407
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:1066
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:714
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:636
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:165
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:802
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:688
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:1030
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:897
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 maxNextSafeMin(double speed, const MSVehicle *const veh=0) const
Returns the maximum speed given the current speed and regarding driving dynamics.
Definition: MSCFModel.h:340
double myCollisionMinGapFactor
The factor of minGap that must be maintained to avoid a collision event.
Definition: MSCFModel.h:692
double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const
Returns the minimal deceleration for following the given leader safely.
Definition: MSCFModel.cpp:977
virtual double maximumLaneSpeedCF(double maxSpeed, double maxSpeedLane) const
Returns the maximum velocity the CF-model wants to achieve in the next step.
Definition: MSCFModel.h:224
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:278
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition: MSCFModel.h:686
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition: MSCFModel.h:254
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition: MSCFModel.h:373
virtual int getModelID() const =0
Returns the model's ID; the XML-Tag number is used.
virtual double getImperfection() const
Get the driver's imperfection.
Definition: MSCFModel.h:301
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition: MSCFModel.h:683
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:680
virtual double distAfterTime(double t, double speed, double accel) const
calculates the distance travelled after accelerating for time t
Definition: MSCFModel.cpp:381
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:262
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:652
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:830
double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update.
Definition: MSCFModel.cpp:523
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:428
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:695
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:690
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:321
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Definition: MSCFModel.h:309
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