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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // The car-following model abstraction
18 /****************************************************************************/
19 #ifndef MSCFModel_h
20 #define MSCFModel_h
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <cmath>
28 #include <string>
29 #include <utils/common/StdDefs.h>
31 
32 #define INVALID_SPEED 299792458 + 1 // nothing can go faster than the speed of light!
33 // Factor that the minimum emergency decel is increased by in corresponding situations
34 #define EMERGENCY_DECEL_AMPLIFIER 1.2
35 
36 // ===========================================================================
37 // class declarations
38 // ===========================================================================
39 class MSVehicleType;
40 class MSVehicle;
41 class MSLane;
42 class MSPerson;
43 class MSLink;
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
56 class MSCFModel {
57 
58 public:
59 
61  public:
62  virtual ~VehicleVariables();
63  };
64 
68  MSCFModel(const MSVehicleType* vtype);
69 
70 
72  virtual ~MSCFModel();
73 
74 
77 
84  virtual double finalizeSpeed(MSVehicle* const veh, double vPos) const;
85 
86 
88  virtual double patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
89  UNUSED_PARAMETER(veh);
90  UNUSED_PARAMETER(vMin);
91  return vMax;
92  }
93 
94 
107  virtual double freeSpeed(const MSVehicle* const veh, double speed, double seen,
108  double maxSpeed, const bool onInsertion = false) const;
109 
110 
120  virtual double followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const = 0;
121 
122 
135  virtual double insertionFollowSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const;
136 
137 
147  virtual double stopSpeed(const MSVehicle* const veh, const double speed, double gap) const = 0;
148 
149 
159  virtual double insertionStopSpeed(const MSVehicle* const veh, double speed, double gap) const;
160 
171  virtual double followSpeedTransient(double duration, const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const;
172 
181  virtual double interactionGap(const MSVehicle* const veh, double vL) const;
182 
183 
187  virtual int getModelID() const = 0;
188 
189 
194  virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
195 
196 
201  return 0;
202  }
204 
205 
209  inline double getMaxAccel() const {
210  return myAccel;
211  }
212 
213 
217  inline double getMaxDecel() const {
218  return myDecel;
219  }
220 
221 
225  inline double getEmergencyDecel() const {
226  return myEmergencyDecel;
227  }
228 
229 
233  inline double getApparentDecel() const {
234  return myApparentDecel;
235  }
236 
239  inline double getCollisionMinGapFactor() const {
241  }
242 
243 
246 
250  virtual double getImperfection() const {
251  return -1;
252  }
253 
254 
258  virtual double getHeadwayTime() const {
259  return myHeadwayTime;
260  }
262 
263 
264 
265 
268 
281  virtual double maxNextSpeed(double speed, const MSVehicle* const veh) const;
282 
283 
293  virtual double minNextSpeed(double speed, const MSVehicle* const veh = 0) const;
294 
304  virtual double minNextSpeedEmergency(double speed, const MSVehicle* const veh = 0) const;
305 
306 
312  inline double brakeGap(const double speed) const {
313  return brakeGap(speed, myDecel, myHeadwayTime);
314  }
315 
316  static double brakeGap(const double speed, const double decel, const double headwayTime);
317 
318  static double brakeGapEuler(const double speed, const double decel, const double headwayTime);
319 
320  static double freeSpeed(const double currentSpeed, const double decel, const double dist, const double maxSpeed, const bool onInsertion, const double actionStepLength);
321 
329  inline virtual double getSecureGap(const MSVehicle* const /*veh*/, const MSVehicle* const /*pred*/, const double speed, const double leaderSpeed, const double leaderMaxDecel) const {
330  // The solution approach leaderBrakeGap >= followerBrakeGap is not
331  // secure when the follower can brake harder than the leader because the paths may still cross.
332  // As a workaround we use a value of leaderDecel which errs on the side of caution
333  const double maxDecel = MAX2(myDecel, leaderMaxDecel);
334  double secureGap = MAX2((double) 0, brakeGap(speed, myDecel, myHeadwayTime) - brakeGap(leaderSpeed, maxDecel, 0));
335  return secureGap;
336  }
337 
338  virtual
342  inline double getSpeedAfterMaxDecel(double v) const {
343  return MAX2((double) 0, v - (double) ACCEL2SPEED(myDecel));
344  }
346 
352  SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const;
353 
354 
363  static double estimateArrivalTime(double dist, double speed, double maxSpeed, double accel);
364 
378  static double estimateArrivalTime(double dist, double initialSpeed, double arrivalSpeed, double maxSpeed, double accel, double decel);
379 
386  static double avoidArrivalAccel(double dist, double time, double speed, double maxDecel);
387 
388 
393  double getMinimalArrivalSpeed(double dist, double currentSpeed) const;
394 
399  double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const;
400 
401 
415  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());
416 
429  static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed);
430 
431 
432 
444  static double speedAfterTime(const double t, const double oldSpeed, const double dist);
445 
446 
448  static double distAfterTime(double t, double speed, double accel);
449 
450 
451 
452  /* @brief estimate speed while accelerating for the given distance
453  * @param[in] dist The distance during which accelerating takes place
454  * @param[in] v The initial speed
455  * @param[in] accel The acceleration
456  * XXX affected by ticket #860 (the formula is invalid for the Euler position update rule)
457  * XXX (Leo) Migrated estimateSpeedAfterDistance() to MSCFModel from MSVehicle as Jakob suggested (removed inline property, because myType is fw-declared)
458  */
459  double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const;
460 
463 
467  virtual void setMaxAccel(double accel) {
468  myAccel = accel;
469  }
470 
471 
475  virtual void setMaxDecel(double decel) {
476  myDecel = decel;
477  }
478 
479 
483  virtual void setEmergencyDecel(double decel) {
484  myEmergencyDecel = decel;
485  }
486 
487 
491  virtual void setApparentDecel(double decel) {
492  myApparentDecel = decel;
493  }
494 
495 
499  virtual void setImperfection(double imperfection) {
500  UNUSED_PARAMETER(imperfection);
501  }
502 
503 
507  virtual void setHeadwayTime(double headwayTime) {
508  myHeadwayTime = headwayTime;
509  }
511 
520  double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion = false) const;
521 
522 
534  double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const;
535 
536 
543  double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion = false, double headway = -1) const;
544 
545 
550  double maximumSafeStopSpeedEuler(double gap, double headway = -1) const;
551 
552 
564  double maximumSafeStopSpeedBallistic(double gap, double currentSpeed, bool onInsertion = false, double headway = -1) const;
565 
573  virtual std::string getParameter(const MSVehicle* veh, const std::string& key) const {
574  UNUSED_PARAMETER(veh);
575  UNUSED_PARAMETER(key);
576  return "";
577  }
578 
586  virtual void setParameter(MSVehicle* veh, const std::string& key, const std::string& value) const {
587  UNUSED_PARAMETER(veh);
588  UNUSED_PARAMETER(key);
589  UNUSED_PARAMETER(value);
590  }
591 
592 protected:
593 
602  void applyHeadwayAndSpeedDifferencePerceptionErrors(const MSVehicle* const veh, double speed, double& gap, double& predSpeed, double predMaxDecel, const MSVehicle* const pred) const;
603 
609  void applyHeadwayPerceptionError(const MSVehicle* const veh, double speed, double& gap) const;
610 
611 
612 protected:
615 
617  double myAccel;
618 
620  double myDecel;
627 
630 
631 
632 
633 };
634 
635 
636 #endif /* MSCFModel_h */
637 
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:65
MSCFModel::VehicleVariables::~VehicleVariables
virtual ~VehicleVariables()
Definition: MSCFModel.cpp:70
UNUSED_PARAMETER
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:31
MSCFModel::brakeGap
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition: MSCFModel.h:312
MSCFModel::getMaxAccel
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition: MSCFModel.h:209
MSCFModel::maximumSafeFollowSpeed
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:856
MSCFModel::getMaxDecel
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:217
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSCFModel::getImperfection
virtual double getImperfection() const
Get the driver's imperfection.
Definition: MSCFModel.h:250
MSCFModel::setEmergencyDecel
virtual void setEmergencyDecel(double decel)
Sets a new value for maximal physically possible deceleration [m/s^2].
Definition: MSCFModel.h:483
MSCFModel::maxNextSpeed
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:238
MSCFModel::maximumSafeStopSpeedBallistic
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:789
MSCFModel::gapExtrapolation
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:502
MSCFModel::setImperfection
virtual void setImperfection(double imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:499
ACCEL2SPEED
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:52
MSCFModel::getSecureGap
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:329
MSCFModel::estimateArrivalTime
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:388
MSCFModel::getApparentDecel
double getApparentDecel() const
Get the vehicle type's apparent deceleration [m/s^2] (the one regarded by its followers.
Definition: MSCFModel.h:233
MSCFModel::applyHeadwayAndSpeedDifferencePerceptionErrors
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:982
MSCFModel::getMinimalArrivalTime
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:375
MSPerson
Definition: MSPerson.h:63
FileHelpers.h
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
MSCFModel::getMinimalArrivalSpeed
double getMinimalArrivalSpeed(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
Definition: MSCFModel.cpp:476
MSCFModel::setApparentDecel
virtual void setApparentDecel(double decel)
Sets a new value for the apparent deceleration [m/s^2].
Definition: MSCFModel.h:491
MSCFModel::finalizeSpeed
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:164
MSCFModel::setHeadwayTime
virtual void setHeadwayTime(double headwayTime)
Sets a new value for desired headway [s].
Definition: MSCFModel.h:507
MSCFModel::interactionGap
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:223
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
MSCFModel::myEmergencyDecel
double myEmergencyDecel
The vehicle's maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:622
MSCFModel::freeSpeed
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:267
MSCFModel::setMaxDecel
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:475
MSCFModel::setParameter
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:586
MSCFModel::patchSpeedBeforeLC
virtual double patchSpeedBeforeLC(const MSVehicle *veh, double vMin, double vMax) const
apply custom speed adaptations within the given speed bounds
Definition: MSCFModel.h:88
MSCFModel::maximumSafeStopSpeed
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:711
MSCFModel::insertionFollowSpeed
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:278
MSCFModel::myHeadwayTime
double myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:629
MSCFModel::insertionStopSpeed
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:289
MSCFModel::minNextSpeedEmergency
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:255
MSCFModel::avoidArrivalAccel
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:459
MSCFModel::setMaxAccel
virtual void setMaxAccel(double accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:467
MSCFModel::speedAfterTime
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:673
MSCFModel::duplicate
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const =0
Duplicates the car-following model.
MSCFModel::MSCFModel
MSCFModel(const MSVehicleType *vtype)
Constructor.
Definition: MSCFModel.cpp:55
MSCFModel::getParameter
virtual std::string getParameter(const MSVehicle *veh, const std::string &key) const
try to get the given parameter for this carFollowingModel
Definition: MSCFModel.h:573
MSCFModel::myCollisionMinGapFactor
double myCollisionMinGapFactor
The factor of minGap that must be maintained to avoid a collision event.
Definition: MSCFModel.h:626
MSCFModel::createVehicleVariables
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting.
Definition: MSCFModel.h:200
MSCFModel::minNextSpeed
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:244
MSCFModel::VehicleVariables
Definition: MSCFModel.h:60
MSCFModel::getSpeedAfterMaxDecel
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:342
MSCFModel::getHeadwayTime
virtual double getHeadwayTime() const
Get the driver's desired headway [s].
Definition: MSCFModel.h:258
MSCFModel::stopSpeed
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)
MSCFModel::followSpeedTransient
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:299
MSCFModel::myDecel
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition: MSCFModel.h:620
MSCFModel::calculateEmergencyDeceleration
double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const
Returns the minimal deceleration for following the given leader safely.
Definition: MSCFModel.cpp:928
MSCFModel::getCollisionMinGapFactor
double getCollisionMinGapFactor() const
Get the factor of minGap that must be maintained to avoid a collision event.
Definition: MSCFModel.h:239
MSCFModel::getEmergencyDecel
double getEmergencyDecel() const
Get the vehicle type's maximal phisically possible deceleration [m/s^2].
Definition: MSCFModel.h:225
MSCFModel::myType
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:614
MSCFModel
The car-following model abstraction.
Definition: MSCFModel.h:56
config.h
MSCFModel::passingTime
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:596
StdDefs.h
MSCFModel::brakeGapEuler
static double brakeGapEuler(const double speed, const double decel, const double headwayTime)
Definition: MSCFModel.cpp:89
MSCFModel::myAccel
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition: MSCFModel.h:617
MSCFModel::getModelID
virtual int getModelID() const =0
Returns the model's ID; the XML-Tag number is used.
MSCFModel::estimateSpeedAfterDistance
double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const
Definition: MSCFModel.cpp:702
MSCFModel::applyHeadwayPerceptionError
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:1018
MSCFModel::maximumSafeStopSpeedEuler
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:761
MSCFModel::distAfterTime
static double distAfterTime(double t, double speed, double accel)
calculates the distance travelled after accelerating for time t
Definition: MSCFModel.cpp:350
MSCFModel::followSpeed
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)
MSCFModel::getMinimalArrivalSpeedEuler
double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update.
Definition: MSCFModel.cpp:483
MSCFModel::~MSCFModel
virtual ~MSCFModel()
Destructor.
Definition: MSCFModel.cpp:67
MSCFModel::myApparentDecel
double myApparentDecel
The vehicle's deceleration as expected by surrounding traffic [m/s^2].
Definition: MSCFModel.h:624
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79