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 
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 public:
61 
63  public:
64  virtual ~VehicleVariables();
65  };
66 
70  MSCFModel(const MSVehicleType* vtype, SUMOReal accel, SUMOReal decel, SUMOReal headwayTime);
71 
72 
74  virtual ~MSCFModel();
75 
76 
79 
85  virtual SUMOReal moveHelper(MSVehicle* const veh, SUMOReal vPos) const;
86 
87 
100  virtual SUMOReal freeSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal seen,
101  SUMOReal maxSpeed, const bool onInsertion = false) const;
102 
103 
113  virtual SUMOReal followSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const = 0;
114 
115 
128  virtual SUMOReal insertionFollowSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const;
129 
130 
139  virtual SUMOReal stopSpeed(const MSVehicle* const veh, const SUMOReal speed, SUMOReal gap2pred) const = 0;
140 
141 
150  virtual SUMOReal interactionGap(const MSVehicle* const veh, SUMOReal vL) const;
151 
152 
156  virtual int getModelID() const = 0;
157 
158 
163  virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
164 
165 
170  return 0;
171  }
173 
174 
178  inline SUMOReal getMaxAccel() const {
179  return myAccel;
180  }
181 
182 
186  inline SUMOReal getMaxDecel() const {
187  return myDecel;
188  }
189 
190 
193 
197  virtual SUMOReal getImperfection() const {
198  return -1;
199  }
200 
201 
205  virtual SUMOReal getHeadwayTime() const {
206  return myHeadwayTime;
207  }
209 
210 
211 
214 
227  virtual SUMOReal maxNextSpeed(SUMOReal speed, const MSVehicle* const veh) const;
228 
229 
234  inline SUMOReal brakeGap(const SUMOReal speed) const {
235  return brakeGap(speed, myDecel, myHeadwayTime);
236  }
237 
238 
239  inline static SUMOReal brakeGap(const SUMOReal speed, const SUMOReal decel, const SUMOReal headwayTime) {
240  /* one possiblity to speed this up is to precalculate speedReduction * steps * (steps+1) / 2
241  for small values of steps (up to 10 maybe) and store them in an array */
242  const SUMOReal speedReduction = ACCEL2SPEED(decel);
243  const int steps = int(speed / speedReduction);
244  return SPEED2DIST(steps * speed - speedReduction * steps * (steps + 1) / 2) + speed * headwayTime;
245  }
246 
247 
248  inline static SUMOReal freeSpeed(const SUMOReal decel, const SUMOReal seen, const SUMOReal maxSpeed, const bool onInsertion) {
249  // adapt speed to succeeding lane, no reaction time is involved
250  // when breaking for y steps the following distance g is covered
251  // (drive with v in the final step)
252  // g = (y^2 + y) * 0.5 * b + y * v
253  // y = ((((sqrt((b + 2.0*v)*(b + 2.0*v) + 8.0*b*g)) - b)*0.5 - v)/b)
254  const SUMOReal v = SPEED2DIST(maxSpeed);
255  if (seen < v) {
256  return maxSpeed;
257  }
258  const SUMOReal b = ACCEL2DIST(decel);
259  const SUMOReal y = MAX2(0.0, ((sqrt((b + 2.0 * v) * (b + 2.0 * v) + 8.0 * b * seen) - b) * 0.5 - v) / b);
260  const SUMOReal yFull = floor(y);
261  const SUMOReal exactGap = (yFull * yFull + yFull) * 0.5 * b + yFull * v + (y > yFull ? v : 0.0);
262  const SUMOReal fullSpeedGain = (yFull + (onInsertion ? 1. : 0.)) * ACCEL2SPEED(decel);
263  return DIST2SPEED(MAX2((SUMOReal)0.0, seen - exactGap) / (yFull + 1)) + fullSpeedGain + maxSpeed;
264  }
265 
266 
272  inline SUMOReal getSecureGap(const SUMOReal speed, const SUMOReal leaderSpeed, const SUMOReal leaderMaxDecel) const {
273  // The solution approach leaderBrakeGap >= followerBrakeGap is not
274  // secure when the follower can brake harder than the leader because the paths may still cross.
275  // As a workaround we lower the value of followerDecel which errs on the side of caution
276  const SUMOReal followDecel = MIN2(myDecel, leaderMaxDecel);
277  return MAX2((SUMOReal) 0, brakeGap(speed, followDecel, myHeadwayTime) - brakeGap(leaderSpeed, leaderMaxDecel, 0));
278  }
279 
280 
286  return MAX2((SUMOReal) 0, v - (SUMOReal) ACCEL2SPEED(myDecel));
287  }
289 
290 
293 
297  virtual void setMaxAccel(SUMOReal accel) {
298  myAccel = accel;
299  }
300 
301 
305  virtual void setMaxDecel(SUMOReal decel) {
306  myDecel = decel;
307  }
308 
309 
313  virtual void setImperfection(SUMOReal imperfection) {
314  UNUSED_PARAMETER(imperfection);
315  }
316 
317 
321  virtual void setHeadwayTime(SUMOReal headwayTime) {
322  myHeadwayTime = headwayTime;
323  }
325 
326 protected:
333  SUMOReal maximumSafeFollowSpeed(SUMOReal gap, SUMOReal predSpeed, SUMOReal predMaxDecel) const;
334 
335 
341 
342 protected:
345 
348 
351 
354 };
355 
356 
357 #endif /* MSCFModel_h */
358 
#define DIST2SPEED(x)
Definition: SUMOTime.h:57
SUMOReal getSpeedAfterMaxDecel(SUMOReal v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:285
virtual SUMOReal getImperfection() const
Get the driver&#39;s imperfection.
Definition: MSCFModel.h:197
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:81
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:344
#define SPEED2DIST(x)
Definition: SUMOTime.h:55
virtual void setMaxDecel(SUMOReal decel)
Sets a new value for maximum deceleration [m/s^2].
Definition: MSCFModel.h:305
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
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:101
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)
virtual SUMOReal maxNextSpeed(SUMOReal speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:89
The car-following model abstraction.
Definition: MSCFModel.h:59
SUMOReal myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:347
T MAX2(T a, T b)
Definition: StdDefs.h:75
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.
Definition: MSCFModel.h:272
MSCFModel(const MSVehicleType *vtype, SUMOReal accel, SUMOReal decel, SUMOReal headwayTime)
Constructor.
Definition: MSCFModel.cpp:46
SUMOReal myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:353
virtual void setMaxAccel(SUMOReal accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:297
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
static SUMOReal freeSpeed(const SUMOReal decel, const SUMOReal seen, const SUMOReal maxSpeed, const bool onInsertion)
Definition: MSCFModel.h:248
The car-following model and parameter.
Definition: MSVehicleType.h:74
static SUMOReal brakeGap(const SUMOReal speed, const SUMOReal decel, const SUMOReal headwayTime)
Definition: MSCFModel.h:239
SUMOReal maximumSafeStopSpeed(SUMOReal gap) const
Returns the maximum velocity for stopping within gap This depends stronlgy on the position update mod...
Definition: MSCFModel.cpp:108
SUMOReal brakeGap(const SUMOReal speed) const
Returns the distance the vehicle needs to halt including driver&#39;s reaction time.
Definition: MSCFModel.h:234
#define ACCEL2DIST(x)
Definition: SUMOTime.h:59
virtual int getModelID() const =0
Returns the model&#39;s ID; the XML-Tag number is used.
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:74
T MIN2(T a, T b)
Definition: StdDefs.h:69
virtual SUMOReal stopSpeed(const MSVehicle *const veh, const SUMOReal speed, SUMOReal gap2pred) const =0
Computes the vehicle&#39;s safe speed for approaching a non-moving obstacle (no dawdling) ...
SUMOReal getMaxDecel() const
Get the vehicle type&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:186
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:95
virtual SUMOReal getHeadwayTime() const
Get the driver&#39;s reaction time [s].
Definition: MSCFModel.h:205
virtual SUMOReal moveHelper(MSVehicle *const veh, SUMOReal vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel.cpp:59
SUMOReal maximumSafeFollowSpeed(SUMOReal gap, SUMOReal predSpeed, SUMOReal predMaxDecel) const
Returns the maximum safe velocity for following the given leader.
Definition: MSCFModel.cpp:138
SUMOReal getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:178
virtual ~MSCFModel()
Destructor.
Definition: MSCFModel.cpp:52
virtual void setImperfection(SUMOReal imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:313
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting...
Definition: MSCFModel.h:169
#define SUMOReal
Definition: config.h:213
virtual void setHeadwayTime(SUMOReal headwayTime)
Sets a new value for driver reaction time [s].
Definition: MSCFModel.h:321
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:350