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-2018 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;
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 
238 
241 
245  virtual double getImperfection() const {
246  return -1;
247  }
248 
249 
253  virtual double getHeadwayTime() const {
254  return myHeadwayTime;
255  }
257 
258 
259 
260 
263 
276  virtual double maxNextSpeed(double speed, const MSVehicle* const veh) const;
277 
278 
288  virtual double minNextSpeed(double speed, const MSVehicle* const veh = 0) const;
289 
299  virtual double minNextSpeedEmergency(double speed, const MSVehicle* const veh = 0) const;
300 
301 
307  inline double brakeGap(const double speed) const {
308  return brakeGap(speed, myDecel, myHeadwayTime);
309  }
310 
311  static double brakeGap(const double speed, const double decel, const double headwayTime);
312 
313  static double brakeGapEuler(const double speed, const double decel, const double headwayTime);
314 
315  static double freeSpeed(const double currentSpeed, const double decel, const double dist, const double maxSpeed, const bool onInsertion, const double actionStepLength);
316 
322  inline double getSecureGap(const double speed, const double leaderSpeed, const double leaderMaxDecel) const {
323  // The solution approach leaderBrakeGap >= followerBrakeGap is not
324  // secure when the follower can brake harder than the leader because the paths may still cross.
325  // As a workaround we use a value of leaderDecel which errs on the side of caution
326  const double maxDecel = MAX2(myDecel, leaderMaxDecel);
327  double secureGap = MAX2((double) 0, brakeGap(speed, myDecel, myHeadwayTime) - brakeGap(leaderSpeed, maxDecel, 0));
328  return secureGap;
329  }
330 
331  virtual
335  inline double getSpeedAfterMaxDecel(double v) const {
336  return MAX2((double) 0, v - (double) ACCEL2SPEED(myDecel));
337  }
339 
345  SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const;
346 
347 
356  static double estimateArrivalTime(double dist, double speed, double maxSpeed, double accel);
357 
371  static double estimateArrivalTime(double dist, double initialSpeed, double arrivalSpeed, double maxSpeed, double accel, double decel);
372 
379  static double avoidArrivalAccel(double dist, double time, double speed);
380 
381 
386  double getMinimalArrivalSpeed(double dist, double currentSpeed) const;
387 
392  double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const;
393 
394 
408  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());
409 
422  static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed);
423 
424 
425 
437  static double speedAfterTime(const double t, const double oldSpeed, const double dist);
438 
439 
441  static double distAfterTime(double t, double speed, double accel);
442 
443 
444 
445  /* @brief estimate speed while accelerating for the given distance
446  * @param[in] dist The distance during which accelerating takes place
447  * @param[in] v The initial speed
448  * @param[in] accel The acceleration
449  * XXX affected by ticket #860 (the formula is invalid for the Euler position update rule)
450  * XXX (Leo) Migrated estimateSpeedAfterDistance() to MSCFModel from MSVehicle as Jakob suggested (removed inline property, because myType is fw-declared)
451  */
452  double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const;
453 
456 
460  virtual void setMaxAccel(double accel) {
461  myAccel = accel;
462  }
463 
464 
468  virtual void setMaxDecel(double decel) {
469  myDecel = decel;
470  }
471 
472 
476  virtual void setEmergencyDecel(double decel) {
477  myEmergencyDecel = decel;
478  }
479 
480 
484  virtual void setApparentDecel(double decel) {
485  myApparentDecel = decel;
486  }
487 
488 
492  virtual void setImperfection(double imperfection) {
493  UNUSED_PARAMETER(imperfection);
494  }
495 
496 
500  virtual void setHeadwayTime(double headwayTime) {
501  myHeadwayTime = headwayTime;
502  }
504 
513  double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion = false) const;
514 
515 
527  double calculateEmergencyDeceleration(double gap, double egoSpeed, double predSpeed, double predMaxDecel) const;
528 
529 
536  double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion = false, double headway = -1) const;
537 
538 
543  double maximumSafeStopSpeedEuler(double gap, double headway = -1) const;
544 
545 
557  double maximumSafeStopSpeedBallistic(double gap, double currentSpeed, bool onInsertion = false, double headway = -1) const;
558 
559 protected:
560 
569  void applyHeadwayAndSpeedDifferencePerceptionErrors(const MSVehicle* const veh, double speed, double& gap, double& predSpeed, double predMaxDecel, const MSVehicle* const pred) const;
570 
576  void applyHeadwayPerceptionError(const MSVehicle* const veh, double speed, double& gap) const;
577 
578 
579 protected:
582 
584  double myAccel;
585 
587  double myDecel;
592 
595 
596 
597 
598 };
599 
600 
601 #endif /* MSCFModel_h */
602 
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:665
double getApparentDecel() const
Get the vehicle type&#39;s apparent deceleration [m/s^2] (the one regarded by its followers.
Definition: MSCFModel.h:234
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:852
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:307
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:262
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
long long int SUMOTime
Definition: SUMOTime.h:36
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:581
double myApparentDecel
The vehicle&#39;s deceleration as expected by surrounding traffic [m/s^2].
Definition: MSCFModel.h:591
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:54
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:239
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:245
The car-following model abstraction.
Definition: MSCFModel.h:57
MSCFModel(const MSVehicleType *vtype)
Constructor.
Definition: MSCFModel.cpp:55
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:233
double myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:584
T MAX2(T a, T b)
Definition: StdDefs.h:68
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:284
static double avoidArrivalAccel(double dist, double time, double speed)
Computes the acceleration needed to arrive not before the given time.
Definition: MSCFModel.cpp:454
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:33
virtual void setApparentDecel(double decel)
Sets a new value for the apparent deceleration [m/s^2].
Definition: MSCFModel.h:484
virtual double insertionFollowSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle&#39;s safe speed (no dawdling) This method is used during the insertion stage...
Definition: MSCFModel.cpp:273
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
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
static double distAfterTime(double t, double speed, double accel)
calculates the distance travelled after accelerating for time t
Definition: MSCFModel.cpp:345
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:250
static double brakeGapEuler(const double speed, const double decel, const double headwayTime)
Definition: MSCFModel.cpp:88
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:500
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:218
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:335
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:923
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:703
double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update...
Definition: MSCFModel.cpp:478
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:587
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:977
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:497
virtual ~MSCFModel()
Destructor.
Definition: MSCFModel.cpp:66
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:591
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:468
virtual void setMaxAccel(double accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:460
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:785
virtual double getHeadwayTime() const
Get the driver&#39;s desired headway [s].
Definition: MSCFModel.h:253
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:383
virtual void setImperfection(double imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:492
double myEmergencyDecel
The vehicle&#39;s maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:589
double getMinimalArrivalSpeed(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
Definition: MSCFModel.cpp:471
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:370
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:294
double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const
Definition: MSCFModel.cpp:694
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:476
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:322
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:594
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:754
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:1011
Representation of a lane in the micro simulation.
Definition: MSLane.h:71
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) ...