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-2020 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 <utils/common/StdDefs.h>
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 // ===========================================================================
38 class MSVehicleType;
39 class MSVehicle;
40 class MSLane;
41 class MSPerson;
42 class MSLink;
43 
44 
45 // ===========================================================================
46 // class definitions
47 // ===========================================================================
55 class MSCFModel {
56 
57 public:
58 
60  public:
61  virtual ~VehicleVariables();
62  };
63 
67  MSCFModel(const MSVehicleType* vtype);
68 
69 
71  virtual ~MSCFModel();
72 
73 
76 
83  virtual double finalizeSpeed(MSVehicle* const veh, double vPos) const;
84 
85 
87  virtual double patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
88  UNUSED_PARAMETER(veh);
89  UNUSED_PARAMETER(vMin);
90  return vMax;
91  }
92 
93 
106  virtual double freeSpeed(const MSVehicle* const veh, double speed, double seen,
107  double maxSpeed, const bool onInsertion = false) const;
108 
109 
119  virtual double followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const = 0;
120 
121 
134  virtual double insertionFollowSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const;
135 
136 
146  virtual double stopSpeed(const MSVehicle* const veh, const double speed, double gap) const = 0;
147 
148 
158  virtual double insertionStopSpeed(const MSVehicle* const veh, double speed, double gap) const;
159 
170  virtual double followSpeedTransient(double duration, const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const;
171 
180  virtual double interactionGap(const MSVehicle* const veh, double vL) const;
181 
182 
186  virtual int getModelID() const = 0;
187 
188 
193  virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
194 
195 
200  return 0;
201  }
203 
204 
208  inline double getMaxAccel() const {
209  return myAccel;
210  }
211 
212 
216  inline double getMaxDecel() const {
217  return myDecel;
218  }
219 
220 
224  inline double getEmergencyDecel() const {
225  return myEmergencyDecel;
226  }
227 
228 
232  inline double getApparentDecel() const {
233  return myApparentDecel;
234  }
235 
238  inline double getCollisionMinGapFactor() const {
240  }
241 
242 
245 
249  virtual double getImperfection() const {
250  return -1;
251  }
252 
253 
257  virtual double getHeadwayTime() const {
258  return myHeadwayTime;
259  }
261 
262 
263 
264 
267 
280  virtual double maxNextSpeed(double speed, const MSVehicle* const veh) const;
281 
282 
292  virtual double minNextSpeed(double speed, const MSVehicle* const veh = 0) const;
293 
303  virtual double minNextSpeedEmergency(double speed, const MSVehicle* const veh = 0) const;
304 
305 
311  inline double brakeGap(const double speed) const {
312  return brakeGap(speed, myDecel, myHeadwayTime);
313  }
314 
315  static double brakeGap(const double speed, const double decel, const double headwayTime);
316 
317  static double brakeGapEuler(const double speed, const double decel, const double headwayTime);
318 
319  static double freeSpeed(const double currentSpeed, const double decel, const double dist, const double maxSpeed, const bool onInsertion, const double actionStepLength);
320 
328  inline virtual double getSecureGap(const MSVehicle* const /*veh*/, const MSVehicle* const /*pred*/, const double speed, const double leaderSpeed, const double leaderMaxDecel) const {
329  // The solution approach leaderBrakeGap >= followerBrakeGap is not
330  // secure when the follower can brake harder than the leader because the paths may still cross.
331  // As a workaround we use a value of leaderDecel which errs on the side of caution
332  const double maxDecel = MAX2(myDecel, leaderMaxDecel);
333  double secureGap = MAX2((double) 0, brakeGap(speed, myDecel, myHeadwayTime) - brakeGap(leaderSpeed, maxDecel, 0));
334  return secureGap;
335  }
336 
337  virtual
341  inline double getSpeedAfterMaxDecel(double v) const {
342  return MAX2((double) 0, v - (double) ACCEL2SPEED(myDecel));
343  }
345 
351  SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const;
352 
353 
362  static double estimateArrivalTime(double dist, double speed, double maxSpeed, double accel);
363 
377  static double estimateArrivalTime(double dist, double initialSpeed, double arrivalSpeed, double maxSpeed, double accel, double decel);
378 
385  static double avoidArrivalAccel(double dist, double time, double speed, double maxDecel);
386 
387 
392  double getMinimalArrivalSpeed(double dist, double currentSpeed) const;
393 
398  double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const;
399 
400 
414  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());
415 
428  static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed);
429 
430 
431 
443  static double speedAfterTime(const double t, const double oldSpeed, const double dist);
444 
445 
447  static double distAfterTime(double t, double speed, double accel);
448 
449 
450 
451  /* @brief estimate speed while accelerating for the given distance
452  * @param[in] dist The distance during which accelerating takes place
453  * @param[in] v The initial speed
454  * @param[in] accel The acceleration
455  * XXX affected by ticket #860 (the formula is invalid for the Euler position update rule)
456  * XXX (Leo) Migrated estimateSpeedAfterDistance() to MSCFModel from MSVehicle as Jakob suggested (removed inline property, because myType is fw-declared)
457  */
458  double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const;
459 
462 
466  virtual void setMaxAccel(double accel) {
467  myAccel = accel;
468  }
469 
470 
474  virtual void setMaxDecel(double decel) {
475  myDecel = decel;
476  }
477 
478 
482  virtual void setEmergencyDecel(double decel) {
483  myEmergencyDecel = decel;
484  }
485 
486 
490  virtual void setApparentDecel(double decel) {
491  myApparentDecel = decel;
492  }
493 
494 
498  virtual void setImperfection(double imperfection) {
499  UNUSED_PARAMETER(imperfection);
500  }
501 
502 
506  virtual void setHeadwayTime(double headwayTime) {
507  myHeadwayTime = headwayTime;
508  }
510 
519  double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion = false) const;
520 
521 
533  double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const;
534 
535 
542  double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion = false, double headway = -1) const;
543 
544 
549  double maximumSafeStopSpeedEuler(double gap, double headway = -1) const;
550 
551 
563  double maximumSafeStopSpeedBallistic(double gap, double currentSpeed, bool onInsertion = false, double headway = -1) const;
564 
572  virtual std::string getParameter(const MSVehicle* veh, const std::string& key) const {
573  UNUSED_PARAMETER(veh);
574  UNUSED_PARAMETER(key);
575  return "";
576  }
577 
585  virtual void setParameter(MSVehicle* veh, const std::string& key, const std::string& value) const {
586  UNUSED_PARAMETER(veh);
587  UNUSED_PARAMETER(key);
588  UNUSED_PARAMETER(value);
589  }
590 
591 protected:
592 
601  void applyHeadwayAndSpeedDifferencePerceptionErrors(const MSVehicle* const veh, double speed, double& gap, double& predSpeed, double predMaxDecel, const MSVehicle* const pred) const;
602 
608  void applyHeadwayPerceptionError(const MSVehicle* const veh, double speed, double& gap) const;
609 
610 
611 protected:
614 
616  double myAccel;
617 
619  double myDecel;
626 
629 
630 
631 
632 };
633 
634 
635 
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:49
long long int SUMOTime
Definition: SUMOTime.h:31
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:29
T MAX2(T a, T b)
Definition: StdDefs.h:79
The car-following model abstraction.
Definition: MSCFModel.h:55
double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const
Definition: MSCFModel.cpp:701
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:237
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:328
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:501
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:254
virtual std::string getParameter(const MSVehicle *veh, const std::string &key) const
try to get the given parameter for this carFollowingModel
Definition: MSCFModel.h:572
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:298
virtual void setImperfection(double imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:498
double maximumSafeStopSpeedBallistic(double gap, 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:788
double getCollisionMinGapFactor() const
Get the factor of minGap that must be maintained to avoid a collision event.
Definition: MSCFModel.h:238
double getEmergencyDecel() const
Get the vehicle type's maximal phisically possible deceleration [m/s^2].
Definition: MSCFModel.h:224
static double brakeGapEuler(const double speed, const double decel, const double headwayTime)
Definition: MSCFModel.cpp:88
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:222
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:458
double getMinimalArrivalSpeed(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
Definition: MSCFModel.cpp:475
virtual void setHeadwayTime(double headwayTime)
Sets a new value for desired headway [s].
Definition: MSCFModel.h:506
virtual double patchSpeedBeforeLC(const MSVehicle *veh, double vMin, double vMax) const
apply custom speed adaptations within the given speed bounds
Definition: MSCFModel.h:87
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const =0
Duplicates the car-following model.
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:243
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:277
virtual void setEmergencyDecel(double decel)
Sets a new value for maximal physically possible deceleration [m/s^2].
Definition: MSCFModel.h:482
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:374
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:1017
virtual void setMaxAccel(double accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:466
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:672
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:595
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:163
virtual double freeSpeed(const MSVehicle *const veh, double speed, double seen, double maxSpeed, const bool onInsertion=false) const
Computes the vehicle's safe speed without a leader.
Definition: MSCFModel.cpp:266
virtual ~MSCFModel()
Destructor.
Definition: MSCFModel.cpp:66
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:474
double myEmergencyDecel
The vehicle's maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:621
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting.
Definition: MSCFModel.h:199
double maximumSafeStopSpeedEuler(double gap, double headway=-1) const
Returns the maximum next velocity for stopping within gap when using the semi-implicit Euler update.
Definition: MSCFModel.cpp:760
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:981
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:855
double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap.
Definition: MSCFModel.cpp:710
virtual double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0) const =0
Computes the vehicle's follow speed (no dawdling)
double myCollisionMinGapFactor
The factor of minGap that must be maintained to avoid a collision event.
Definition: MSCFModel.h:625
double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const
Returns the minimal deceleration for following the given leader safely.
Definition: MSCFModel.cpp:927
static double distAfterTime(double t, double speed, double accel)
calculates the distance travelled after accelerating for time t
Definition: MSCFModel.cpp:349
MSCFModel(const MSVehicleType *vtype)
Constructor.
Definition: MSCFModel.cpp:54
double getApparentDecel() const
Get the vehicle type's apparent deceleration [m/s^2] (the one regarded by its followers.
Definition: MSCFModel.h:232
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition: MSCFModel.h:619
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition: MSCFModel.h:208
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition: MSCFModel.h:311
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:249
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition: MSCFModel.h:616
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:613
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:216
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:341
virtual void setApparentDecel(double decel)
Sets a new value for the apparent deceleration [m/s^2].
Definition: MSCFModel.h:490
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:585
double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update.
Definition: MSCFModel.cpp:482
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:387
double myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:628
double myApparentDecel
The vehicle's deceleration as expected by surrounding traffic [m/s^2].
Definition: MSCFModel.h:623
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:288
virtual double stopSpeed(const MSVehicle *const veh, const double speed, double gap) const =0
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Definition: MSCFModel.h:257
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
The car-following model and parameter.
Definition: MSVehicleType.h:62