SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
13 // Copyright (C) 2001-2013 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 <string>
36 #include <utils/common/StdDefs.h>
38 
39 
40 // ===========================================================================
41 // class declarations
42 // ===========================================================================
43 class MSVehicleType;
44 class MSVehicle;
45 class MSLane;
46 
47 
48 // ===========================================================================
49 // class definitions
50 // ===========================================================================
58 class MSCFModel {
59 public:
60 
62  };
63 
67  MSCFModel(const MSVehicleType* vtype, SUMOReal accel, SUMOReal decel, SUMOReal headwayTime);
68 
69 
71  virtual ~MSCFModel();
72 
73 
76 
82  virtual SUMOReal moveHelper(MSVehicle* const veh, SUMOReal vPos) const;
83 
84 
95  virtual SUMOReal freeSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal seen, SUMOReal maxSpeed) const;
96 
97 
107  virtual SUMOReal followSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const = 0;
108 
109 
118  virtual SUMOReal stopSpeed(const MSVehicle* const veh, const SUMOReal speed, SUMOReal gap2pred) const = 0;
119 
120 
129  virtual SUMOReal interactionGap(const MSVehicle* const veh, SUMOReal vL) const;
130 
131 
135  virtual int getModelID() const = 0;
136 
137 
142  virtual MSCFModel* duplicate(const MSVehicleType* vtype) const = 0;
143 
144 
149  return 0;
150  }
152 
153 
157  inline SUMOReal getMaxAccel() const {
158  return myAccel;
159  }
160 
161 
165  inline SUMOReal getMaxDecel() const {
166  return myDecel;
167  }
168 
169 
172 
176  virtual SUMOReal getImperfection() const {
177  return -1;
178  }
179 
180 
184  virtual SUMOReal getHeadwayTime() const {
185  return myHeadwayTime;
186  }
188 
189 
190 
193 
206  virtual SUMOReal maxNextSpeed(SUMOReal speed, const MSVehicle* const veh) const;
207 
208 
213  inline SUMOReal brakeGap(const SUMOReal speed) const {
214  /* one possiblity to speed this up is to precalculate speedReduction * steps * (steps+1) / 2
215  for small values of steps (up to 10 maybe) and store them in an array */
216  const SUMOReal speedReduction = ACCEL2SPEED(getMaxDecel());
217  const int steps = int(speed / speedReduction);
218  return SPEED2DIST(steps * speed - speedReduction * steps * (steps + 1) / 2) + speed * myHeadwayTime;
219  }
220 
221 
227  inline SUMOReal getSecureGap(const SUMOReal speed, const SUMOReal leaderSpeed, const SUMOReal leaderMaxDecel) const {
228  const int leaderSteps = int(leaderSpeed / ACCEL2SPEED(leaderMaxDecel));
229  const SUMOReal leaderBreak = SPEED2DIST(leaderSteps * leaderSpeed - ACCEL2SPEED(leaderMaxDecel) * leaderSteps * (leaderSteps + 1) / 2);
230  return MAX2((SUMOReal) 0, brakeGap(speed) - leaderBreak);
231  }
232 
233 
239  return MAX2((SUMOReal) 0, v - (SUMOReal) ACCEL2SPEED(myDecel));
240  }
242 
243 
246 
250  virtual void setMaxAccel(SUMOReal accel) {
251  myAccel = accel;
252  }
253 
254 
258  virtual void setMaxDecel(SUMOReal decel) {
259  myDecel = decel;
260  }
261 
262 
266  virtual void setImperfection(SUMOReal imperfection) {
267  UNUSED_PARAMETER(imperfection);
268  }
269 
270 
274  virtual void setHeadwayTime(SUMOReal headwayTime) {
275  myHeadwayTime = headwayTime;
276  }
278 
279 
280 protected:
283 
286 
289 
292 };
293 
294 
295 #endif /* MSCFModel_h */
296 
SUMOReal getSpeedAfterMaxDecel(SUMOReal v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:238
virtual SUMOReal getImperfection() const
Get the driver&#39;s imperfection.
Definition: MSCFModel.h:176
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:282
#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:258
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
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 safe 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:58
SUMOReal myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:285
T MAX2(T a, T b)
Definition: StdDefs.h:63
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:227
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:291
virtual void setMaxAccel(SUMOReal accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:250
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:36
The car-following model and parameter.
Definition: MSVehicleType.h:74
SUMOReal brakeGap(const SUMOReal speed) const
Returns the distance the vehicle needs to halt including driver&#39;s reaction time.
Definition: MSCFModel.h:213
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
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:165
virtual SUMOReal getHeadwayTime() const
Get the driver&#39;s reaction time [s].
Definition: MSCFModel.h:184
virtual SUMOReal moveHelper(MSVehicle *const veh, SUMOReal vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel.cpp:56
SUMOReal getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:157
virtual ~MSCFModel()
Destructor.
Definition: MSCFModel.cpp:52
virtual void setImperfection(SUMOReal imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:266
virtual SUMOReal freeSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal seen, SUMOReal maxSpeed) const
Computes the vehicle&#39;s safe speed without a leader.
Definition: MSCFModel.cpp:92
virtual VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting...
Definition: MSCFModel.h:148
#define SUMOReal
Definition: config.h:221
virtual void setHeadwayTime(SUMOReal headwayTime)
Sets a new value for driver reaction time [s].
Definition: MSCFModel.h:274
Representation of a lane in the micro simulation.
Definition: MSLane.h:73
SUMOReal myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:288