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 <math.h>
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 
156 
165  virtual double interactionGap(const MSVehicle* const veh, double vL) const;
166 
167 
171  virtual int getModelID() const = 0;
172 
173 
178  virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
179 
180 
185  return 0;
186  }
188 
189 
193  inline double getMaxAccel() const {
194  return myAccel;
195  }
196 
197 
201  inline double getMaxDecel() const {
202  return myDecel;
203  }
204 
205 
208 
212  virtual double getImperfection() const {
213  return -1;
214  }
215 
216 
220  virtual double getHeadwayTime() const {
221  return myHeadwayTime;
222  }
224 
225 
226 
227 
230 
243  virtual double maxNextSpeed(double speed, const MSVehicle* const veh) const;
244 
245 
255  virtual double minNextSpeed(double speed, const MSVehicle* const veh = 0) const;
256 
257 
263  inline double brakeGap(const double speed) const {
264  return brakeGap(speed, myDecel, myHeadwayTime);
265  }
266 
267  static double brakeGap(const double speed, const double decel, const double headwayTime);
268 
269  static double freeSpeed(const double currentSpeed, const double decel, const double dist, const double maxSpeed, const bool onInsertion);
270 
276  inline double getSecureGap(const double speed, const double leaderSpeed, const double leaderMaxDecel) const {
277  // The solution approach leaderBrakeGap >= followerBrakeGap is not
278  // secure when the follower can brake harder than the leader because the paths may still cross.
279  // As a workaround we lower the value of followerDecel which errs on the side of caution
280  //
281  // xxx (Leo, refs #2548) This is somewhat different from the approach in maximumSafeFollowSpeed, where
282  // the leaderMaxDecel is increased instead. This is no perfect estimate either,
283  // but without taking into account the reaction time it is less conservative than decreasing followDecel.
284  // Consider replacement by 'const leaderMaxDecel = MAX2(myDecel, leaderMaxDecel);' below and 'followDecel = myDecel;'
285  // With maximumSafeSpeed = maximumSafeFollowSpeed(*secureGap*, speed, leaderSpeed, leaderMaxDecel) we should have:
286  // assert(maximumSafeSpeed <= speed + NUMERICAL_EPS && maximumSafeSpeed >= speed - NUMERICAL_EPS);
287 
288  // XXX: this should fix #2548 (postponed after merge of branch {ticket860}):
289  // const double maxDecel = MAX2(myDecel, leaderMaxDecel);
290  // double secureGap = MAX2((double) 0, brakeGap(speed, myDecel, myHeadwayTime) - brakeGap(leaderSpeed, maxDecel, 0));
291 
292  const double followDecel = MIN2(myDecel, leaderMaxDecel);
293  // XXX: returning 0 can be wrong if the leader is slower than the follower! Why not return negative values? (Leo)
294  double secureGap = MAX2((double) 0, brakeGap(speed, followDecel, myHeadwayTime) - brakeGap(leaderSpeed, leaderMaxDecel, 0));
295  return secureGap;
296  }
297 
298  virtual
302  inline double getSpeedAfterMaxDecel(double v) const {
303  return MAX2((double) 0, v - (double) ACCEL2SPEED(myDecel));
304  }
306 
312  SUMOTime getMinimalArrivalTime(double dist, double currentSpeed, double arrivalSpeed) const;
313 
314 
319  double getMinimalArrivalSpeed(double dist, double currentSpeed) const;
320 
325  double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const;
326 
327 
341  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());
342 
355  static double passingTime(const double lastPos, const double passedPos, const double currentPos, const double lastSpeed, const double currentSpeed);
356 
357 
358 
370  static double speedAfterTime(const double t, const double oldSpeed, const double dist);
371 
372 
373 
374 
375 
376  /* @brief estimate speed while accelerating for the given distance
377  * @param[in] dist The distance during which accelerating takes place
378  * @param[in] v The initial speed
379  * @param[in] accel The acceleration
380  * XXX affected by ticket #860 (the formula is invalid for the Euler position update rule)
381  * XXX (Leo) Migrated estimateSpeedAfterDistance() to MSCFModel from MSVehicle as Jakob suggested (removed inline property, because myType is fw-declared)
382  */
383  double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const;
384 
387 
391  virtual void setMaxAccel(double accel) {
392  myAccel = accel;
393  }
394 
395 
399  virtual void setMaxDecel(double decel) {
400  myDecel = decel;
401  }
402 
403 
407  virtual void setImperfection(double imperfection) {
408  UNUSED_PARAMETER(imperfection);
409  }
410 
411 
415  virtual void setHeadwayTime(double headwayTime) {
416  myHeadwayTime = headwayTime;
417  }
419 
428  double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion = false) const;
429 
430 
437  double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion = false, double headway = -1) const;
438 
439 
444  double maximumSafeStopSpeedEuler(double gap) const;
445 
446 
458  double maximumSafeStopSpeedBallistic(double gap, double currentSpeed, bool onInsertion = false, double headway = -1) const;
459 
460 
461 protected:
464 
466  double myAccel;
467 
469  double myDecel;
474 
477 
478 };
479 
480 
481 #endif /* MSCFModel_h */
482 
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:444
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:590
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver&#39;s reaction time, assuming that during...
Definition: MSCFModel.h:263
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:211
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:463
double myApparentDecel
The vehicle&#39;s deceleration as expected by surrounding traffic [m/s^2].
Definition: MSCFModel.h:473
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
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:198
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:212
The car-following model abstraction.
Definition: MSCFModel.h:60
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting...
Definition: MSCFModel.h:184
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:193
double myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:466
T MAX2(T a, T b)
Definition: StdDefs.h:70
virtual double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel.cpp:147
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:229
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:38
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:218
The car-following model and parameter.
Definition: MSVehicleType.h:74
double getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:193
#define max(a, b)
Definition: polyfonts.c:65
virtual int getModelID() const =0
Returns the model&#39;s ID; the XML-Tag number is used.
virtual void setHeadwayTime(double headwayTime)
Sets a new value for driver reaction time [s].
Definition: MSCFModel.h:415
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:178
T MIN2(T a, T b)
Definition: StdDefs.h:64
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:302
double getMaxDecel() const
Get the vehicle type&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:201
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:482
double getMinimalArrivalSpeedEuler(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update...
Definition: MSCFModel.cpp:259
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:469
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:278
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:372
double maximumSafeStopSpeedEuler(double gap) const
Returns the maximum next velocity for stopping within gap when using the semi-implicit Euler update...
Definition: MSCFModel.cpp:492
virtual void setMaxDecel(double decel)
Sets a new value for maximum deceleration [m/s^2].
Definition: MSCFModel.h:399
virtual void setMaxAccel(double accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:391
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:523
virtual double getHeadwayTime() const
Get the driver&#39;s reaction time [s].
Definition: MSCFModel.h:220
virtual void setImperfection(double imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:407
double myEmergencyDecel
The vehicle&#39;s maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:471
double getMinimalArrivalSpeed(double dist, double currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
Definition: MSCFModel.cpp:252
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:239
MSCFModel(const MSVehicleType *vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double headwayTime)
Constructor.
Definition: MSCFModel.cpp:48
double estimateSpeedAfterDistance(const double dist, const double v, const double accel) const
Definition: MSCFModel.cpp:473
long long int SUMOTime
Definition: TraCIDefs.h:52
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:276
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:476
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
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) ...