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 /****************************************************************************/
18 // The car-following model abstraction
19 /****************************************************************************/
20 #ifndef MSCFModel_h
21 #define MSCFModel_h
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <cmath>
29 #include <string>
30 #include <utils/common/StdDefs.h>
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 // ===========================================================================
40 class MSVehicleType;
41 class MSVehicle;
42 class MSLane;
43 class MSPerson;
44 class MSLink;
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
57 class MSCFModel {
58 
59 public:
60 
62  public:
63  virtual ~VehicleVariables();
64  };
65 
69  MSCFModel(const MSVehicleType* vtype);
70 
71 
73  virtual ~MSCFModel();
74 
75 
78 
85  virtual double finalizeSpeed(MSVehicle* const veh, double vPos) const;
86 
87 
89  virtual double patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
90  UNUSED_PARAMETER(veh);
91  UNUSED_PARAMETER(vMin);
92  return vMax;
93  }
94 
95 
108  virtual double freeSpeed(const MSVehicle* const veh, double speed, double seen,
109  double maxSpeed, const bool onInsertion = false) const;
110 
111 
121  virtual double followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const = 0;
122 
123 
136  virtual double insertionFollowSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle* const pred = 0) const;
137 
138 
148  virtual double stopSpeed(const MSVehicle* const veh, const double speed, double gap) const = 0;
149 
150 
160  virtual double insertionStopSpeed(const MSVehicle* const veh, double speed, double gap) const;
161 
172  virtual double followSpeedTransient(double duration, const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const;
173 
182  virtual double interactionGap(const MSVehicle* const veh, double vL) const;
183 
184 
188  virtual int getModelID() const = 0;
189 
190 
195  virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
196 
197 
202  return 0;
203  }
205 
206 
210  inline double getMaxAccel() const {
211  return myAccel;
212  }
213 
214 
218  inline double getMaxDecel() const {
219  return myDecel;
220  }
221 
222 
226  inline double getEmergencyDecel() const {
227  return myEmergencyDecel;
228  }
229 
230 
234  inline double getApparentDecel() const {
235  return myApparentDecel;
236  }
237 
240  inline double getCollisionMinGapFactor() const {
242  }
243 
244 
247 
251  virtual double getImperfection() const {
252  return -1;
253  }
254 
255 
259  virtual double getHeadwayTime() const {
260  return myHeadwayTime;
261  }
263 
264 
265 
266 
269 
282  virtual double maxNextSpeed(double speed, const MSVehicle* const veh) const;
283 
284 
294  virtual double minNextSpeed(double speed, const MSVehicle* const veh = 0) const;
295 
305  virtual double minNextSpeedEmergency(double speed, const MSVehicle* const veh = 0) const;
306 
307 
313  inline double brakeGap(const double speed) const {
314  return brakeGap(speed, myDecel, myHeadwayTime);
315  }
316 
317  static double brakeGap(const double speed, const double decel, const double headwayTime);
318 
319  static double brakeGapEuler(const double speed, const double decel, const double headwayTime);
320 
321  static double freeSpeed(const double currentSpeed, const double decel, const double dist, const double maxSpeed, const bool onInsertion, const double actionStepLength);
322 
328  inline virtual double getSecureGap(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 #endif /* MSCFModel_h */
636 
static double speedAfterTime(const double t, const double oldSpeed, const double dist)
Calculates the speed after a time t [0,TS] given the initial speed and the distance traveled in an i...
Definition: MSCFModel.cpp:674
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
double getApparentDecel() const
Get the vehicle type&#39;s apparent deceleration [m/s^2] (the one regarded by its followers.
Definition: MSCFModel.h:234
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 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:857
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver&#39;s reaction time tau (i...
Definition: MSCFModel.h:313
virtual double freeSpeed(const MSVehicle *const veh, double speed, double seen, double maxSpeed, const bool onInsertion=false) const
Computes the vehicle&#39;s safe speed without a leader.
Definition: MSCFModel.cpp:268
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:35
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:613
double myApparentDecel
The vehicle&#39;s deceleration as expected by surrounding traffic [m/s^2].
Definition: MSCFModel.h:623
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:53
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:245
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const =0
Duplicates the car-following model.
virtual double getImperfection() const
Get the driver&#39;s imperfection.
Definition: MSCFModel.h:251
The car-following model abstraction.
Definition: MSCFModel.h:57
MSCFModel(const MSVehicleType *vtype)
Constructor.
Definition: MSCFModel.cpp:56
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting...
Definition: MSCFModel.h:201
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:239
double myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:616
T MAX2(T a, T b)
Definition: StdDefs.h:80
double getCollisionMinGapFactor() const
Get the factor of minGap that must be maintained to avoid a collision event.
Definition: MSCFModel.h:240
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:460
virtual double insertionStopSpeed(const MSVehicle *const veh, double speed, double gap) const
Computes the vehicle&#39;s safe speed for approaching an obstacle at insertion without constraints due to...
Definition: MSCFModel.cpp:290
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:32
virtual void setApparentDecel(double decel)
Sets a new value for the apparent deceleration [m/s^2].
Definition: MSCFModel.h:490
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
The car-following model and parameter.
Definition: MSVehicleType.h:66
double getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:210
virtual double insertionFollowSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0) const
Computes the vehicle&#39;s safe speed (no dawdling) This method is used during the insertion stage...
Definition: MSCFModel.cpp:279
static double distAfterTime(double t, double speed, double accel)
calculates the distance travelled after accelerating for time t
Definition: MSCFModel.cpp:351
virtual int getModelID() const =0
Returns the model&#39;s ID; the XML-Tag number is used.
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:256
virtual double getSecureGap(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 brakeGapEuler(const double speed, const double decel, const double headwayTime)
Definition: MSCFModel.cpp:90
double getEmergencyDecel() const
Get the vehicle type&#39;s maximal phisically possible deceleration [m/s^2].
Definition: MSCFModel.h:226
virtual void setHeadwayTime(double headwayTime)
Sets a new value for desired headway [s].
Definition: MSCFModel.h:506
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:224
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:341
double getMaxDecel() const
Get the vehicle type&#39;s maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:218
double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const
Returns the minimal deceleration for following the given leader safely.
Definition: MSCFModel.cpp:929
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:712
double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update...
Definition: MSCFModel.cpp:484
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:619
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&#39;s driver state...
Definition: MSCFModel.cpp:983
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:503
virtual ~MSCFModel()
Destructor.
Definition: MSCFModel.cpp:68
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:597
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:474
virtual void setMaxAccel(double accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:466
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:790
virtual double getHeadwayTime() const
Get the driver&#39;s desired headway [s].
Definition: MSCFModel.h:259
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:389
virtual void setImperfection(double imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:498
double myEmergencyDecel
The vehicle&#39;s maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:621
double getMinimalArrivalSpeed(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
Definition: MSCFModel.cpp:477
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:376
virtual double followSpeedTransient(double duration, const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle&#39;s follow speed that avoids a collision for the given amount of time...
Definition: MSCFModel.cpp:300
double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const
Definition: MSCFModel.cpp:703
virtual double patchSpeedBeforeLC(const MSVehicle *veh, double vMin, double vMax) const
apply custom speed adaptations within the given speed bounds
Definition: MSCFModel.h:89
virtual void setEmergencyDecel(double decel)
Sets a new value for maximal physically possible deceleration [m/s^2].
Definition: MSCFModel.h:482
double myCollisionMinGapFactor
The factor of minGap that must be maintained to avoid a collision event.
Definition: MSCFModel.h:625
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:628
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:762
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&#39;s follow speed (no dawdling)
void applyHeadwayPerceptionError(const MSVehicle *const veh, double speed, double &gap) const
Overwrites gap by the perceived value obtained from the vehicle&#39;s driver state.
Definition: MSCFModel.cpp:1017
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
virtual double stopSpeed(const MSVehicle *const veh, const double speed, double gap) const =0
Computes the vehicle&#39;s safe speed for approaching a non-moving obstacle (no dawdling) ...