SUMO - Simulation of Urban MObility
MSCFModel.h
Go to the documentation of this file.
1 /****************************************************************************/
10 // The car-following model abstraction
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 #ifndef MSCFModel_h
24 #define MSCFModel_h
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <cmath>
36 #include <string>
37 #include <utils/common/StdDefs.h>
39 
40 #define INVALID_SPEED 299792458 + 1 // nothing can go faster than the speed of light!
41 
42 // ===========================================================================
43 // class declarations
44 // ===========================================================================
45 class MSVehicleType;
46 class MSVehicle;
47 class MSLane;
48 
49 
50 // ===========================================================================
51 // class definitions
52 // ===========================================================================
60 class MSCFModel {
61 
62 public:
63 
65  public:
66  virtual ~VehicleVariables();
67  };
68 
72  MSCFModel(const MSVehicleType* vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double headwayTime);
73 
74 
76  virtual ~MSCFModel();
77 
78 
81 
87  virtual double moveHelper(MSVehicle* const veh, double vPos) const;
88 
89 
102  virtual double freeSpeed(const MSVehicle* const veh, double speed, double seen,
103  double maxSpeed, const bool onInsertion = false) const;
104 
105 
115  virtual double followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const = 0;
116 
117 
130  virtual double insertionFollowSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const;
131 
132 
142  virtual double stopSpeed(const MSVehicle* const veh, const double speed, double gap) const = 0;
143 
144 
154  virtual double insertionStopSpeed(const MSVehicle* const veh, double speed, double gap) const;
155 
166  virtual double followSpeedTransient(double duration, const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const;
167 
176  virtual double interactionGap(const MSVehicle* const veh, double vL) const;
177 
178 
182  virtual int getModelID() const = 0;
183 
184 
189  virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
190 
191 
196  return 0;
197  }
199 
200 
204  inline double getMaxAccel() const {
205  return myAccel;
206  }
207 
208 
212  inline double getMaxDecel() const {
213  return myDecel;
214  }
215 
216 
220  inline double getEmergencyDecel() const {
221  return myEmergencyDecel;
222  }
223 
224 
228  inline double getApparentDecel() const {
229  return myApparentDecel;
230  }
231 
232 
235 
239  virtual double getImperfection() const {
240  return -1;
241  }
242 
243 
247  virtual double getHeadwayTime() const {
248  return myHeadwayTime;
249  }
251 
252 
253 
254 
257 
270  virtual double maxNextSpeed(double speed, const MSVehicle* const veh) const;
271 
272 
282  virtual double minNextSpeed(double speed, const MSVehicle* const veh = 0) const;
283 
284 
290  inline double brakeGap(const double speed) const {
291  return brakeGap(speed, myDecel, myHeadwayTime);
292  }
293 
294  static double brakeGap(const double speed, const double decel, const double headwayTime);
295 
296  static double brakeGapEuler(const double speed, const double decel, const double headwayTime);
297 
298  static double freeSpeed(const double currentSpeed, const double decel, const double dist, const double maxSpeed, const bool onInsertion);
299 
305  inline double getSecureGap(const double speed, const double leaderSpeed, const double leaderMaxDecel) const {
306  // The solution approach leaderBrakeGap >= followerBrakeGap is not
307  // secure when the follower can brake harder than the leader because the paths may still cross.
308  // As a workaround we lower the value of followerDecel which errs on the side of caution
309  //
310  // xxx (Leo, refs #2548) This is somewhat different from the approach in maximumSafeFollowSpeed, where
311  // the leaderMaxDecel is increased instead. This is no perfect estimate either,
312  // but without taking into account the reaction time tau it is less conservative than decreasing followDecel.
313  // Consider replacement by 'const leaderMaxDecel = MAX2(myDecel, leaderMaxDecel);' below and 'followDecel = myDecel;'
314  // With maximumSafeSpeed = maximumSafeFollowSpeed(*secureGap*, speed, leaderSpeed, leaderMaxDecel) we should have:
315  // assert(maximumSafeSpeed <= speed + NUMERICAL_EPS && maximumSafeSpeed >= speed - NUMERICAL_EPS);
316 
317  // XXX: this should fix #2548 (postponed after merge of branch {ticket860}):
318  // const double maxDecel = MAX2(myDecel, leaderMaxDecel);
319  // double secureGap = MAX2((double) 0, brakeGap(speed, myDecel, myHeadwayTime) - brakeGap(leaderSpeed, maxDecel, 0));
320 
321  const double followDecel = MIN2(myDecel, leaderMaxDecel);
322  // XXX: returning 0 can be wrong if the leader is slower than the follower! Why not return negative values? (Leo)
323  double secureGap = MAX2((double) 0, brakeGap(speed, followDecel, myHeadwayTime) - brakeGap(leaderSpeed, leaderMaxDecel, 0));
324  return secureGap;
325  }
326 
327  virtual
331  inline double getSpeedAfterMaxDecel(double v) const {
332  return MAX2((double) 0, v - (double) ACCEL2SPEED(myDecel));
333  }
335 
341  SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const;
342 
343 
352  double estimateArrivalTime(double dist, double speed, double maxSpeed, double accel) const;
353 
354 
359  double getMinimalArrivalSpeed(double dist, double currentSpeed) const;
360 
365  double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const;
366 
367 
381  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());
382 
395  static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed);
396 
397 
398 
410  static double speedAfterTime(const double t, const double oldSpeed, const double dist);
411 
412 
414  static double distAfterTime(double t, double speed, double decel);
415 
416 
417 
418  /* @brief estimate speed while accelerating for the given distance
419  * @param[in] dist The distance during which accelerating takes place
420  * @param[in] v The initial speed
421  * @param[in] accel The acceleration
422  * XXX affected by ticket #860 (the formula is invalid for the Euler position update rule)
423  * XXX (Leo) Migrated estimateSpeedAfterDistance() to MSCFModel from MSVehicle as Jakob suggested (removed inline property, because myType is fw-declared)
424  */
425  double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const;
426 
429 
433  virtual void setMaxAccel(double accel) {
434  myAccel = accel;
435  }
436 
437 
441  virtual void setMaxDecel(double decel) {
442  myDecel = decel;
443  }
444 
445 
449  virtual void setEmergencyDecel(double decel) {
450  myEmergencyDecel = decel;
451  }
452 
453 
457  virtual void setApparentDecel(double decel) {
458  myApparentDecel = decel;
459  }
460 
461 
465  virtual void setImperfection(double imperfection) {
466  UNUSED_PARAMETER(imperfection);
467  }
468 
469 
473  virtual void setHeadwayTime(double headwayTime) {
474  myHeadwayTime = headwayTime;
475  }
477 
486  double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion = false) const;
487 
488 
495  double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion = false, double headway = -1) const;
496 
497 
502  double maximumSafeStopSpeedEuler(double gap) const;
503 
504 
516  double maximumSafeStopSpeedBallistic(double gap, double currentSpeed, bool onInsertion = false, double headway = -1) const;
517 
518 
519 protected:
522 
524  double myAccel;
525 
527  double myDecel;
532 
535 
536 };
537 
538 
539 #endif /* MSCFModel_h */
540 
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:566
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const =0
Duplicates the car-following model.
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:521
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:331
double myApparentDecel
The vehicle&#39;s deceleration as expected by surrounding traffic [m/s^2].
Definition: MSCFModel.h:531
virtual double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const =0
Computes the vehicle&#39;s follow speed (no dawdling)
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
virtual double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel.cpp:153
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:185
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:305
The car-following model abstraction.
Definition: MSCFModel.h:60
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:604
virtual double getHeadwayTime() const
Get the driver&#39;s desired headway [s].
Definition: MSCFModel.h:247
double myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:524
T MAX2(T a, T b)
Definition: StdDefs.h:74
double getMinimalArrivalSpeed(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
Definition: MSCFModel.cpp:374
virtual int getModelID() const =0
Returns the model&#39;s ID; the XML-Tag number is used.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:40
virtual void setApparentDecel(double decel)
Sets a new value for the apparent deceleration [m/s^2].
Definition: MSCFModel.h:457
The car-following model and parameter.
Definition: MSVehicleType.h:73
double getEmergencyDecel() const
Get the vehicle type&#39;s maximal phisically possible deceleration [m/s^2].
Definition: MSCFModel.h:220
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:320
static double distAfterTime(double t, double speed, double decel)
calculates the distance travelled after braking for time t
Definition: MSCFModel.cpp:298
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:247
#define max(a, b)
Definition: polyfonts.c:65
static double brakeGapEuler(const double speed, const double decel, const double headwayTime)
Definition: MSCFModel.cpp:81
virtual double getImperfection() const
Get the driver&#39;s imperfection.
Definition: MSCFModel.h:239
double getMaxDecel() const
Get the vehicle type&#39;s maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:212
virtual void setHeadwayTime(double headwayTime)
Sets a new value for desired headway [s].
Definition: MSCFModel.h:473
T MIN2(T a, T b)
Definition: StdDefs.h:68
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:219
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:645
double maximumSafeStopSpeedEuler(double gap) const
Returns the maximum next velocity for stopping within gap when using the semi-implicit Euler update...
Definition: MSCFModel.cpp:614
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:226
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:527
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:400
virtual ~MSCFModel()
Destructor.
Definition: MSCFModel.cpp:59
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:494
double getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:204
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:441
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting...
Definition: MSCFModel.h:195
virtual void setMaxAccel(double accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:433
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:200
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:206
virtual void setImperfection(double imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:465
double myEmergencyDecel
The vehicle&#39;s maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:529
double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const
Definition: MSCFModel.cpp:595
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) ...
MSCFModel(const MSVehicleType *vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double headwayTime)
Constructor.
Definition: MSCFModel.cpp:48
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:237
virtual void setEmergencyDecel(double decel)
Sets a new value for maximal physically possible deceleration [m/s^2].
Definition: MSCFModel.h:449
long long int SUMOTime
Definition: TraCIDefs.h:52
double getApparentDecel() const
Get the vehicle type&#39;s apparent deceleration [m/s^2] (the one regarded by its followers.
Definition: MSCFModel.h:228
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:534
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:712
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
double estimateArrivalTime(double dist, double speed, double maxSpeed, double accel) const
Computes the time needed to travel a distance dist given an initial speed and constant acceleration...
Definition: MSCFModel.cpp:333
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:290
double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update...
Definition: MSCFModel.cpp:381