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-2015 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  };
64 
68  MSCFModel(const MSVehicleType* vtype, SUMOReal accel, SUMOReal decel, SUMOReal headwayTime);
69 
70 
72  virtual ~MSCFModel();
73 
74 
77 
83  virtual SUMOReal moveHelper(MSVehicle* const veh, SUMOReal vPos) const;
84 
85 
98  virtual SUMOReal freeSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal seen,
99  SUMOReal maxSpeed, const bool onInsertion = false) const;
100 
101 
111  virtual SUMOReal followSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const = 0;
112 
113 
126  virtual SUMOReal insertionFollowSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const;
127 
128 
137  virtual SUMOReal stopSpeed(const MSVehicle* const veh, const SUMOReal speed, SUMOReal gap2pred) const = 0;
138 
139 
148  virtual SUMOReal interactionGap(const MSVehicle* const veh, SUMOReal vL) const;
149 
150 
154  virtual int getModelID() const = 0;
155 
156 
161  virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
162 
163 
168  return 0;
169  }
171 
172 
176  inline SUMOReal getMaxAccel() const {
177  return myAccel;
178  }
179 
180 
184  inline SUMOReal getMaxDecel() const {
185  return myDecel;
186  }
187 
188 
191 
195  virtual SUMOReal getImperfection() const {
196  return -1;
197  }
198 
199 
203  virtual SUMOReal getHeadwayTime() const {
204  return myHeadwayTime;
205  }
207 
208 
209 
212 
225  virtual SUMOReal maxNextSpeed(SUMOReal speed, const MSVehicle* const veh) const;
226 
227 
232  inline SUMOReal brakeGap(const SUMOReal speed) const {
233  return brakeGap(speed, myDecel, myHeadwayTime);
234  }
235 
236 
237  inline static SUMOReal brakeGap(const SUMOReal speed, const SUMOReal decel, const SUMOReal headwayTime) {
238  /* one possiblity to speed this up is to precalculate speedReduction * steps * (steps+1) / 2
239  for small values of steps (up to 10 maybe) and store them in an array */
240  const SUMOReal speedReduction = ACCEL2SPEED(decel);
241  const int steps = int(speed / speedReduction);
242  return SPEED2DIST(steps * speed - speedReduction * steps * (steps + 1) / 2) + speed * headwayTime;
243  }
244 
245 
246  inline static SUMOReal freeSpeed(const SUMOReal decel, const SUMOReal seen, const SUMOReal maxSpeed, const bool onInsertion) {
247  // adapt speed to succeeding lane, no reaction time is involved
248  // when breaking for y steps the following distance g is covered
249  // (drive with v in the final step)
250  // g = (y^2 + y) * 0.5 * b + y * v
251  // y = ((((sqrt((b + 2.0*v)*(b + 2.0*v) + 8.0*b*g)) - b)*0.5 - v)/b)
252  const SUMOReal v = SPEED2DIST(maxSpeed);
253  if (seen < v) {
254  return maxSpeed;
255  }
256  const SUMOReal b = ACCEL2DIST(decel);
257  const SUMOReal y = MAX2(0.0, ((sqrt((b + 2.0 * v) * (b + 2.0 * v) + 8.0 * b * seen) - b) * 0.5 - v) / b);
258  const SUMOReal yFull = floor(y);
259  const SUMOReal exactGap = (yFull * yFull + yFull) * 0.5 * b + yFull * v + (y > yFull ? v : 0.0);
260  const SUMOReal fullSpeedGain = (yFull + (onInsertion ? 1. : 0.)) * ACCEL2SPEED(decel);
261  return DIST2SPEED(MAX2((SUMOReal)0.0, seen - exactGap) / (yFull + 1)) + fullSpeedGain + maxSpeed;
262  }
263 
264 
270  inline SUMOReal getSecureGap(const SUMOReal speed, const SUMOReal leaderSpeed, const SUMOReal leaderMaxDecel) const {
271  // The solution approach leaderBrakeGap >= followerBrakeGap is not
272  // secure when the follower can brake harder than the leader because the paths may still cross.
273  // As a workaround we lower the value of followerDecel which errs on the side of caution
274  const SUMOReal followDecel = MIN2(myDecel, leaderMaxDecel);
275  return MAX2((SUMOReal) 0, brakeGap(speed, followDecel, myHeadwayTime) - brakeGap(leaderSpeed, leaderMaxDecel, 0));
276  }
277 
278 
284  return MAX2((SUMOReal) 0, v - (SUMOReal) ACCEL2SPEED(myDecel));
285  }
287 
288 
291 
295  virtual void setMaxAccel(SUMOReal accel) {
296  myAccel = accel;
297  }
298 
299 
303  virtual void setMaxDecel(SUMOReal decel) {
304  myDecel = decel;
305  }
306 
307 
311  virtual void setImperfection(SUMOReal imperfection) {
312  UNUSED_PARAMETER(imperfection);
313  }
314 
315 
319  virtual void setHeadwayTime(SUMOReal headwayTime) {
320  myHeadwayTime = headwayTime;
321  }
323 
324 protected:
331  SUMOReal maximumSafeFollowSpeed(SUMOReal gap, SUMOReal predSpeed, SUMOReal predMaxDecel) const;
332 
333 
339 
340 protected:
343 
346 
349 
352 };
353 
354 
355 #endif /* MSCFModel_h */
356 
#define DIST2SPEED(x)
Definition: SUMOTime.h:57
SUMOReal getSpeedAfterMaxDecel(SUMOReal v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:283
virtual SUMOReal getImperfection() const
Get the driver&#39;s imperfection.
Definition: MSCFModel.h:195
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:342
#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:303
#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:98
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:86
The car-following model abstraction.
Definition: MSCFModel.h:59
SUMOReal myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:345
T MAX2(T a, T b)
Definition: StdDefs.h:79
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:270
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:351
virtual void setMaxAccel(SUMOReal accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:295
#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:246
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:237
SUMOReal maximumSafeStopSpeed(SUMOReal gap) const
Returns the maximum velocity for stopping within gap This depends stronlgy on the position update mod...
Definition: MSCFModel.cpp:105
SUMOReal brakeGap(const SUMOReal speed) const
Returns the distance the vehicle needs to halt including driver&#39;s reaction time.
Definition: MSCFModel.h:232
#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:71
T MIN2(T a, T b)
Definition: StdDefs.h:73
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:184
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:92
virtual SUMOReal getHeadwayTime() const
Get the driver&#39;s reaction time [s].
Definition: MSCFModel.h:203
virtual SUMOReal moveHelper(MSVehicle *const veh, SUMOReal vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel.cpp:56
SUMOReal maximumSafeFollowSpeed(SUMOReal gap, SUMOReal predSpeed, SUMOReal predMaxDecel) const
Returns the maximum safe velocity for following the given leader.
Definition: MSCFModel.cpp:134
SUMOReal getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:176
virtual ~MSCFModel()
Destructor.
Definition: MSCFModel.cpp:52
virtual void setImperfection(SUMOReal imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:311
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting...
Definition: MSCFModel.h:167
#define SUMOReal
Definition: config.h:214
virtual void setHeadwayTime(SUMOReal headwayTime)
Sets a new value for driver reaction time [s].
Definition: MSCFModel.h:319
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
SUMOReal myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:348