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-2016 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, SUMOReal accel, SUMOReal decel, SUMOReal headwayTime);
73 
74 
76  virtual ~MSCFModel();
77 
78 
81 
87  virtual SUMOReal moveHelper(MSVehicle* const veh, SUMOReal vPos) const;
88 
89 
102  virtual SUMOReal freeSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal seen,
103  SUMOReal maxSpeed, const bool onInsertion = false) const;
104 
105 
115  virtual SUMOReal followSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const = 0;
116 
117 
130  virtual SUMOReal insertionFollowSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const;
131 
132 
142  virtual SUMOReal stopSpeed(const MSVehicle* const veh, const SUMOReal speed, SUMOReal gap) const = 0;
143 
144 
154  virtual SUMOReal insertionStopSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap) const;
155 
156 
165  virtual SUMOReal interactionGap(const MSVehicle* const veh, SUMOReal 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 SUMOReal getMaxAccel() const {
194  return myAccel;
195  }
196 
197 
201  inline SUMOReal getMaxDecel() const {
202  return myDecel;
203  }
204 
205 
208 
212  virtual SUMOReal getImperfection() const {
213  return -1;
214  }
215 
216 
220  virtual SUMOReal getHeadwayTime() const {
221  return myHeadwayTime;
222  }
224 
225 
226 
227 
230 
243  virtual SUMOReal maxNextSpeed(SUMOReal speed, const MSVehicle* const veh) const;
244 
245 
255  SUMOReal minNextSpeed(SUMOReal speed, const MSVehicle* const veh = 0) const;
256 
257 
263  inline SUMOReal brakeGap(const SUMOReal speed) const {
264  return brakeGap(speed, myDecel, myHeadwayTime);
265  }
266 
267  static SUMOReal brakeGap(const SUMOReal speed, const SUMOReal decel, const SUMOReal headwayTime);
268 
269  static SUMOReal freeSpeed(const SUMOReal currentSpeed, const SUMOReal decel, const SUMOReal dist, const SUMOReal maxSpeed, const bool onInsertion);
270 
276  inline SUMOReal getSecureGap(const SUMOReal speed, const SUMOReal leaderSpeed, const SUMOReal 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 SUMOReal maxDecel = MAX2(myDecel, leaderMaxDecel);
290  // SUMOReal secureGap = MAX2((SUMOReal) 0, brakeGap(speed, myDecel, myHeadwayTime) - brakeGap(leaderSpeed, maxDecel, 0));
291 
292  const SUMOReal 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  SUMOReal secureGap = MAX2((SUMOReal) 0, brakeGap(speed, followDecel, myHeadwayTime) - brakeGap(leaderSpeed, leaderMaxDecel, 0));
295  return secureGap;
296  }
297 
303  return MAX2((SUMOReal) 0, v - (SUMOReal) ACCEL2SPEED(myDecel));
304  }
306 
312  SUMOTime getMinimalArrivalTime(SUMOReal dist, SUMOReal currentSpeed, SUMOReal arrivalSpeed) const;
313 
314 
319  SUMOReal getMinimalArrivalSpeed(SUMOReal dist, SUMOReal currentSpeed) const;
320 
325  SUMOReal getMinimalArrivalSpeedEuler(SUMOReal dist, SUMOReal currentSpeed) const;
326 
327 
341  static SUMOReal gapExtrapolation(const SUMOReal duration, const SUMOReal currentGap, SUMOReal v1, SUMOReal v2, SUMOReal a1 = 0, SUMOReal a2 = 0, const SUMOReal maxV1 = std::numeric_limits<SUMOReal>::max(), const SUMOReal maxV2 = std::numeric_limits<SUMOReal>::max());
342 
355  static SUMOReal passingTime(const SUMOReal lastPos, const SUMOReal passedPos, const SUMOReal currentPos, const SUMOReal lastSpeed, const SUMOReal currentSpeed);
356 
357 
358 
370  static SUMOReal speedAfterTime(const SUMOReal t, const SUMOReal oldSpeed, const SUMOReal 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  SUMOReal estimateSpeedAfterDistance(const SUMOReal dist, const SUMOReal v, const SUMOReal accel) const;
384 
387 
391  virtual void setMaxAccel(SUMOReal accel) {
392  myAccel = accel;
393  }
394 
395 
399  virtual void setMaxDecel(SUMOReal decel) {
400  myDecel = decel;
401  }
402 
403 
407  virtual void setImperfection(SUMOReal imperfection) {
408  UNUSED_PARAMETER(imperfection);
409  }
410 
411 
415  virtual void setHeadwayTime(SUMOReal headwayTime) {
416  myHeadwayTime = headwayTime;
417  }
419 
428  SUMOReal maximumSafeFollowSpeed(SUMOReal gap, SUMOReal egoSpeed, SUMOReal predSpeed, SUMOReal predMaxDecel, bool onInsertion = false) const;
429 
430 
437  SUMOReal maximumSafeStopSpeed(SUMOReal gap, SUMOReal currentSpeed, bool onInsertion = false, SUMOReal headway = -1) const;
438 
439 
445 
446 
458  SUMOReal maximumSafeStopSpeedBallistic(SUMOReal gap, SUMOReal currentSpeed, bool onInsertion = false, SUMOReal headway = -1) const;
459 
460 
461 protected:
464 
467 
470 
473 
474 };
475 
476 
477 #endif /* MSCFModel_h */
478 
SUMOReal getSpeedAfterMaxDecel(SUMOReal v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:302
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
long long int SUMOTime
Definition: SUMOTime.h:43
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:463
virtual SUMOReal insertionFollowSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const
Computes the vehicle&#39;s safe speed (no dawdling) This method is used during the insertion stage...
Definition: MSCFModel.cpp:213
SUMOReal maximumSafeStopSpeedBallistic(SUMOReal gap, SUMOReal currentSpeed, bool onInsertion=false, SUMOReal headway=-1) const
Returns the maximum next velocity for stopping within gap when using the ballistic positional update...
Definition: MSCFModel.cpp:518
virtual void setMaxDecel(SUMOReal decel)
Sets a new value for maximum deceleration [m/s^2].
Definition: MSCFModel.h:399
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
virtual SUMOReal getImperfection() const
Get the driver&#39;s imperfection.
Definition: MSCFModel.h:212
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const =0
Duplicates the car-following model.
virtual SUMOReal followSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const =0
Computes the vehicle&#39;s follow speed (no dawdling)
The car-following model abstraction.
Definition: MSCFModel.h:60
virtual SUMOReal moveHelper(MSVehicle *const veh, SUMOReal vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel.cpp:144
SUMOReal myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:466
SUMOReal getMaxDecel() const
Get the vehicle type&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:201
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting...
Definition: MSCFModel.h:184
T MAX2(T a, T b)
Definition: StdDefs.h:75
MSCFModel(const MSVehicleType *vtype, SUMOReal accel, SUMOReal decel, SUMOReal headwayTime)
Constructor.
Definition: MSCFModel.cpp:48
SUMOReal myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:472
virtual void setMaxAccel(SUMOReal accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:391
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
SUMOReal getSecureGap(const SUMOReal speed, const SUMOReal leaderSpeed, const SUMOReal leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum (>=0)
Definition: MSCFModel.h:276
SUMOReal maximumSafeStopSpeedEuler(SUMOReal gap) const
Returns the maximum next velocity for stopping within gap when using the semi-implicit Euler update...
Definition: MSCFModel.cpp:487
SUMOReal minNextSpeed(SUMOReal 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:195
The car-following model and parameter.
Definition: MSVehicleType.h:74
SUMOReal getMinimalArrivalSpeedEuler(SUMOReal dist, SUMOReal currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance for Euler update...
Definition: MSCFModel.cpp:254
static SUMOReal speedAfterTime(const SUMOReal t, const SUMOReal oldSpeed, const SUMOReal dist)
Calculates the speed after a time t [0,TS] given the initial speed and the distance traveled in an i...
Definition: MSCFModel.cpp:439
#define max(a, b)
Definition: polyfonts.c:65
SUMOTime getMinimalArrivalTime(SUMOReal dist, SUMOReal currentSpeed, SUMOReal arrivalSpeed) const
Computes the minimal time needed to cover a distance given the desired speed at arrival.
Definition: MSCFModel.cpp:234
virtual int getModelID() const =0
Returns the model&#39;s ID; the XML-Tag number is used.
virtual SUMOReal getHeadwayTime() const
Get the driver&#39;s reaction time [s].
Definition: MSCFModel.h:220
virtual SUMOReal freeSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal seen, SUMOReal maxSpeed, const bool onInsertion=false) const
Computes the vehicle&#39;s safe speed without a leader.
Definition: MSCFModel.cpp:206
T MIN2(T a, T b)
Definition: StdDefs.h:69
static SUMOReal passingTime(const SUMOReal lastPos, const SUMOReal passedPos, const SUMOReal currentPos, const SUMOReal lastSpeed, const SUMOReal currentSpeed)
Calculates the time at which the position passedPosition has been passed In case of a ballistic updat...
Definition: MSCFModel.cpp:367
SUMOReal getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:193
SUMOReal maximumSafeStopSpeed(SUMOReal gap, SUMOReal currentSpeed, bool onInsertion=false, SUMOReal headway=-1) const
Returns the maximum next velocity for stopping within gap.
Definition: MSCFModel.cpp:477
SUMOReal maximumSafeFollowSpeed(SUMOReal gap, SUMOReal egoSpeed, SUMOReal predSpeed, SUMOReal predMaxDecel, bool onInsertion=false) const
Returns the maximum safe velocity for following the given leader.
Definition: MSCFModel.cpp:585
SUMOReal brakeGap(const SUMOReal speed) const
Returns the distance the vehicle needs to halt including driver&#39;s reaction time, assuming that during...
Definition: MSCFModel.h:263
virtual ~MSCFModel()
Destructor.
Definition: MSCFModel.cpp:54
SUMOReal estimateSpeedAfterDistance(const SUMOReal dist, const SUMOReal v, const SUMOReal accel) const
Definition: MSCFModel.cpp:468
virtual void setImperfection(SUMOReal imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:407
SUMOReal getMinimalArrivalSpeed(SUMOReal dist, SUMOReal currentSpeed) const
Computes the minimal possible arrival speed after covering a given distance.
Definition: MSCFModel.cpp:247
virtual SUMOReal stopSpeed(const MSVehicle *const veh, const SUMOReal speed, SUMOReal gap) const =0
Computes the vehicle&#39;s safe speed for approaching a non-moving obstacle (no dawdling) ...
#define SUMOReal
Definition: config.h:213
static SUMOReal gapExtrapolation(const SUMOReal duration, const SUMOReal currentGap, SUMOReal v1, SUMOReal v2, SUMOReal a1=0, SUMOReal a2=0, const SUMOReal maxV1=std::numeric_limits< SUMOReal >::max(), const SUMOReal maxV2=std::numeric_limits< SUMOReal >::max())
return the resulting gap if, starting with gap currentGap, two vehicles continue with constant accele...
Definition: MSCFModel.cpp:273
virtual SUMOReal maxNextSpeed(SUMOReal speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:190
virtual void setHeadwayTime(SUMOReal headwayTime)
Sets a new value for driver reaction time [s].
Definition: MSCFModel.h:415
virtual SUMOReal interactionGap(const MSVehicle *const veh, SUMOReal vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
Definition: MSCFModel.cpp:175
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
SUMOReal myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:469
virtual SUMOReal insertionStopSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal gap) const
Computes the vehicle&#39;s safe speed for approaching an obstacle at insertion without constraints due to...
Definition: MSCFModel.cpp:224