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-2014 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  return brakeGap(speed, myDecel, myHeadwayTime);
215  }
216 
217 
218  inline static SUMOReal brakeGap(const SUMOReal speed, const SUMOReal decel, const SUMOReal headwayTime) {
219  /* one possiblity to speed this up is to precalculate speedReduction * steps * (steps+1) / 2
220  for small values of steps (up to 10 maybe) and store them in an array */
221  const SUMOReal speedReduction = ACCEL2SPEED(decel);
222  const int steps = int(speed / speedReduction);
223  return SPEED2DIST(steps * speed - speedReduction * steps * (steps + 1) / 2) + speed * headwayTime;
224  }
225 
226 
232  inline SUMOReal getSecureGap(const SUMOReal speed, const SUMOReal leaderSpeed, const SUMOReal leaderMaxDecel) const {
233  // The solution approach leaderBrakeGap >= followerBrakeGap is not
234  // secure when the follower can brake harder than the leader because the paths may still cross.
235  // As a workaround we lower the value of followerDecel which errs on the side of caution
236  const SUMOReal followDecel = MIN2(myDecel, leaderMaxDecel);
237  return MAX2((SUMOReal) 0, brakeGap(speed, followDecel, myHeadwayTime) - brakeGap(leaderSpeed, leaderMaxDecel, 0));
238  }
239 
240 
246  return MAX2((SUMOReal) 0, v - (SUMOReal) ACCEL2SPEED(myDecel));
247  }
249 
250 
253 
257  virtual void setMaxAccel(SUMOReal accel) {
258  myAccel = accel;
259  }
260 
261 
265  virtual void setMaxDecel(SUMOReal decel) {
266  myDecel = decel;
267  }
268 
269 
273  virtual void setImperfection(SUMOReal imperfection) {
274  UNUSED_PARAMETER(imperfection);
275  }
276 
277 
281  virtual void setHeadwayTime(SUMOReal headwayTime) {
282  myHeadwayTime = headwayTime;
283  }
285 
286 
287 protected:
290 
293 
296 
299 };
300 
301 
302 #endif /* MSCFModel_h */
303 
SUMOReal getSpeedAfterMaxDecel(SUMOReal v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:245
virtual SUMOReal getImperfection() const
Get the driver'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:289
#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:265
#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'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's maximum acceleration [m/s^2].
Definition: MSCFModel.h:292
T MAX2(T a, T b)
Definition: StdDefs.h:72
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:232
MSCFModel(const MSVehicleType *vtype, SUMOReal accel, SUMOReal decel, SUMOReal headwayTime)
Constructor.
Definition: MSCFModel.cpp:46
SUMOReal myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:298
virtual void setMaxAccel(SUMOReal accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:257
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:39
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:218
SUMOReal brakeGap(const SUMOReal speed) const
Returns the distance the vehicle needs to halt including driver's reaction time.
Definition: MSCFModel.h:213
virtual int getModelID() const =0
Returns the model'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:66
virtual SUMOReal stopSpeed(const MSVehicle *const veh, const SUMOReal speed, SUMOReal gap2pred) const =0
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling) ...
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
Definition: MSCFModel.h:165
virtual SUMOReal getHeadwayTime() const
Get the driver'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'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:273
virtual SUMOReal freeSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal seen, SUMOReal maxSpeed) const
Computes the vehicle'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:215
virtual void setHeadwayTime(SUMOReal headwayTime)
Sets a new value for driver reaction time [s].
Definition: MSCFModel.h:281
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
SUMOReal myDecel
The vehicle's maximum deceleration [m/s^2].
Definition: MSCFModel.h:295