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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // The car-following model abstraction
21 /****************************************************************************/
22 #ifndef MSCFModel_h
23 #define MSCFModel_h
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <cmath>
35 #include <string>
36 #include <utils/common/StdDefs.h>
38 
39 #define INVALID_SPEED 299792458 + 1 // nothing can go faster than the speed of light!
40 
41 // ===========================================================================
42 // class declarations
43 // ===========================================================================
44 class MSVehicleType;
45 class MSVehicle;
46 class MSLane;
47 
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
59 class MSCFModel {
60 
61 public:
62 
64  public:
65  virtual ~VehicleVariables();
66  };
67 
71  MSCFModel(const MSVehicleType* vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double headwayTime);
72 
73 
75  virtual ~MSCFModel();
76 
77 
80 
86  virtual double moveHelper(MSVehicle* const veh, double vPos) const;
87 
88 
101  virtual double freeSpeed(const MSVehicle* const veh, double speed, double seen,
102  double maxSpeed, const bool onInsertion = false) const;
103 
104 
114  virtual double followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const = 0;
115 
116 
129  virtual double insertionFollowSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const;
130 
131 
141  virtual double stopSpeed(const MSVehicle* const veh, const double speed, double gap) const = 0;
142 
143 
153  virtual double insertionStopSpeed(const MSVehicle* const veh, double speed, double gap) const;
154 
165  virtual double followSpeedTransient(double duration, const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const;
166 
175  virtual double interactionGap(const MSVehicle* const veh, double vL) const;
176 
177 
181  virtual int getModelID() const = 0;
182 
183 
188  virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
189 
190 
195  return 0;
196  }
198 
199 
203  inline double getMaxAccel() const {
204  return myAccel;
205  }
206 
207 
211  inline double getMaxDecel() const {
212  return myDecel;
213  }
214 
215 
219  inline double getEmergencyDecel() const {
220  return myEmergencyDecel;
221  }
222 
223 
227  inline double getApparentDecel() const {
228  return myApparentDecel;
229  }
230 
231 
234 
238  virtual double getImperfection() const {
239  return -1;
240  }
241 
242 
246  virtual double getHeadwayTime() const {
247  return myHeadwayTime;
248  }
250 
251 
252 
253 
256 
269  virtual double maxNextSpeed(double speed, const MSVehicle* const veh) const;
270 
271 
281  virtual double minNextSpeed(double speed, const MSVehicle* const veh = 0) const;
282 
283 
289  inline double brakeGap(const double speed) const {
290  return brakeGap(speed, myDecel, myHeadwayTime);
291  }
292 
293  static double brakeGap(const double speed, const double decel, const double headwayTime);
294 
295  static double brakeGapEuler(const double speed, const double decel, const double headwayTime);
296 
297  static double freeSpeed(const double currentSpeed, const double decel, const double dist, const double maxSpeed, const bool onInsertion, const double actionStepLength);
298 
304  inline double getSecureGap(const double speed, const double leaderSpeed, const double leaderMaxDecel) const {
305  // The solution approach leaderBrakeGap >= followerBrakeGap is not
306  // secure when the follower can brake harder than the leader because the paths may still cross.
307  // As a workaround we use a value of leaderDecel which errs on the side of caution
308  const double maxDecel = MAX2(myDecel, leaderMaxDecel);
309  // XXX: returning 0 can be wrong if the leader is slower than the follower! Why not return negative values? (Leo)
310  double secureGap = MAX2((double) 0, brakeGap(speed, myDecel, myHeadwayTime) - brakeGap(leaderSpeed, maxDecel, 0));
311  return secureGap;
312  }
313 
314  virtual
318  inline double getSpeedAfterMaxDecel(double v) const {
319  return MAX2((double) 0, v - (double) ACCEL2SPEED(myDecel));
320  }
322 
328  SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const;
329 
330 
339  static double estimateArrivalTime(double dist, double speed, double maxSpeed, double accel);
340 
354  static double estimateArrivalTime(double dist, double initialSpeed, double arrivalSpeed, double maxSpeed, double accel, double decel);
355 
362  static double avoidArrivalAccel(double dist, double time, double speed);
363 
364 
369  double getMinimalArrivalSpeed(double dist, double currentSpeed) const;
370 
375  double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const;
376 
377 
391  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());
392 
405  static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed);
406 
407 
408 
420  static double speedAfterTime(const double t, const double oldSpeed, const double dist);
421 
422 
424  static double distAfterTime(double t, double speed, double accel);
425 
426 
427 
428  /* @brief estimate speed while accelerating for the given distance
429  * @param[in] dist The distance during which accelerating takes place
430  * @param[in] v The initial speed
431  * @param[in] accel The acceleration
432  * XXX affected by ticket #860 (the formula is invalid for the Euler position update rule)
433  * XXX (Leo) Migrated estimateSpeedAfterDistance() to MSCFModel from MSVehicle as Jakob suggested (removed inline property, because myType is fw-declared)
434  */
435  double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const;
436 
439 
443  virtual void setMaxAccel(double accel) {
444  myAccel = accel;
445  }
446 
447 
451  virtual void setMaxDecel(double decel) {
452  myDecel = decel;
453  }
454 
455 
459  virtual void setEmergencyDecel(double decel) {
460  myEmergencyDecel = decel;
461  }
462 
463 
467  virtual void setApparentDecel(double decel) {
468  myApparentDecel = decel;
469  }
470 
471 
475  virtual void setImperfection(double imperfection) {
476  UNUSED_PARAMETER(imperfection);
477  }
478 
479 
483  virtual void setHeadwayTime(double headwayTime) {
484  myHeadwayTime = headwayTime;
485  }
487 
496  double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion = false) const;
497 
498 
505  double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion = false, double headway = -1) const;
506 
507 
512  double maximumSafeStopSpeedEuler(double gap) const;
513 
514 
526  double maximumSafeStopSpeedBallistic(double gap, double currentSpeed, bool onInsertion = false, double headway = -1) const;
527 
528 
529 protected:
532 
534  double myAccel;
535 
537  double myDecel;
542 
545 
546 };
547 
548 
549 #endif /* MSCFModel_h */
550 
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:624
double getApparentDecel() const
Get the vehicle type&#39;s apparent deceleration [m/s^2] (the one regarded by its followers.
Definition: MSCFModel.h:227
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:770
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:289
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:223
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:531
double myApparentDecel
The vehicle&#39;s deceleration as expected by surrounding traffic [m/s^2].
Definition: MSCFModel.h:541
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:60
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:210
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)
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:238
The car-following model abstraction.
Definition: MSCFModel.h:59
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting...
Definition: MSCFModel.h:194
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:204
double myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:534
T MAX2(T a, T b)
Definition: StdDefs.h:73
virtual double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel.cpp:155
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:245
static double avoidArrivalAccel(double dist, double time, double speed)
Computes the acceleration needed to arrive not before the given time.
Definition: MSCFModel.cpp:415
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
virtual void setApparentDecel(double decel)
Sets a new value for the apparent deceleration [m/s^2].
Definition: MSCFModel.h:467
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:234
The car-following model and parameter.
Definition: MSVehicleType.h:72
double getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:203
static double distAfterTime(double t, double speed, double accel)
calculates the distance travelled after accelerating for time t
Definition: MSCFModel.cpp:306
virtual int getModelID() const =0
Returns the model&#39;s ID; the XML-Tag number is used.
static double brakeGapEuler(const double speed, const double decel, const double headwayTime)
Definition: MSCFModel.cpp:80
double getEmergencyDecel() const
Get the vehicle type&#39;s maximal phisically possible deceleration [m/s^2].
Definition: MSCFModel.h:219
virtual void setHeadwayTime(double headwayTime)
Sets a new value for desired headway [s].
Definition: MSCFModel.h:483
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:189
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:318
double getMaxDecel() const
Get the vehicle type&#39;s maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:211
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:662
double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update...
Definition: MSCFModel.cpp:439
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:537
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:458
virtual ~MSCFModel()
Destructor.
Definition: MSCFModel.cpp:58
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:552
double maximumSafeStopSpeedEuler(double gap) const
Returns the maximum next velocity for stopping within gap when using the semi-implicit Euler update...
Definition: MSCFModel.cpp:672
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:451
virtual void setMaxAccel(double accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:443
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:703
virtual double getHeadwayTime() const
Get the driver&#39;s desired headway [s].
Definition: MSCFModel.h:246
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:344
virtual void setImperfection(double imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:475
double myEmergencyDecel
The vehicle&#39;s maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:539
double getMinimalArrivalSpeed(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
Definition: MSCFModel.cpp:432
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:331
MSCFModel(const MSVehicleType *vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double headwayTime)
Constructor.
Definition: MSCFModel.cpp:47
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:255
double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const
Definition: MSCFModel.cpp:653
virtual void setEmergencyDecel(double decel)
Sets a new value for maximal physically possible deceleration [m/s^2].
Definition: MSCFModel.h:459
long long int SUMOTime
Definition: TraCIDefs.h:51
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:304
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:544
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
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) ...