SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSCFModel_IDM.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // The Intelligent Driver Model (IDM) car-following model
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include "MSCFModel_IDM.h"
34 #include <microsim/MSVehicle.h>
35 #include <microsim/MSLane.h>
37 #include <utils/common/SUMOTime.h>
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
44  SUMOReal accel, SUMOReal decel,
45  SUMOReal headwayTime, SUMOReal delta,
46  SUMOReal internalStepping)
47  : MSCFModel(vtype, accel, decel, headwayTime), myDelta(delta),
48  myAdaptationFactor(1.), myAdaptationTime(0.), myExpFactor(0),
49  myIterations(MAX2(1, int(TS / internalStepping + .5))),
50  myTwoSqrtAccelDecel(SUMOReal(2 * sqrt(accel* decel))) {
51 }
52 
53 
55  SUMOReal accel, SUMOReal decel,
56  SUMOReal headwayTime,
57  SUMOReal adaptationFactor, SUMOReal adaptationTime,
58  SUMOReal internalStepping)
59  : MSCFModel(vtype, accel, decel, headwayTime), myDelta(4.),
60  myAdaptationFactor(adaptationFactor), myAdaptationTime(adaptationTime),
61  myExpFactor(exp(-TS / adaptationTime)),
62  myIterations(MAX2(1, int(TS / internalStepping + .5))),
63  myTwoSqrtAccelDecel(SUMOReal(2 * sqrt(accel* decel))) {
64 }
65 
66 
68 
69 
71 MSCFModel_IDM::moveHelper(MSVehicle* const veh, SUMOReal vPos) const {
72  const SUMOReal vNext = MSCFModel::moveHelper(veh, vPos);
73  if (myExpFactor > 0.) {
75  vars->levelOfService *= myExpFactor;
76  vars->levelOfService += vNext / desiredSpeed(veh) * myAdaptationTime * (1. - myExpFactor);
77  }
78  return vNext;
79 }
80 
81 
83 MSCFModel_IDM::followSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal /*predMaxDecel*/) const {
84  return _v(veh, gap2pred, speed, predSpeed, desiredSpeed(veh));
85 }
86 
87 
89 MSCFModel_IDM::stopSpeed(const MSVehicle* const veh, const SUMOReal speed, SUMOReal gap2pred) const {
90  if (gap2pred < 0.01) {
91  return 0;
92  }
93  return _v(veh, gap2pred, speed, 0, desiredSpeed(veh));
94 }
95 
96 
99 MSCFModel_IDM::interactionGap(const MSVehicle* const veh, SUMOReal vL) const {
100  // Resolve the IDM equation to gap. Assume predecessor has
101  // speed != 0 and that vsafe will be the current speed plus acceleration,
102  // i.e that with this gap there will be no interaction.
103  SUMOReal acc = myAccel * (1. - pow(veh->getSpeed() / desiredSpeed(veh), myDelta));
104  SUMOReal vNext = veh->getSpeed() + acc;
105  SUMOReal gap = (vNext - vL) * (veh->getSpeed() + vL) / (2 * myDecel) + vL;
106 
107  // Don't allow timeHeadWay < deltaT situations.
108  return MAX2(gap, SPEED2DIST(vNext));
109 }
110 
111 
112 SUMOReal
113 MSCFModel_IDM::_v(const MSVehicle* const veh, SUMOReal gap2pred, SUMOReal egoSpeed, SUMOReal predSpeed, SUMOReal desSpeed) const {
114  SUMOReal headwayTime = myHeadwayTime;
115  if (myExpFactor > 0.) {
117  headwayTime *= myAdaptationFactor + vars->levelOfService * (1. - myAdaptationFactor);
118  }
119  for (int i = 0; i < myIterations; i++) {
120  const SUMOReal delta_v = egoSpeed - predSpeed;
121  const SUMOReal s = myType->getMinGap() + MAX2(SUMOReal(0), egoSpeed * headwayTime + egoSpeed * delta_v / myTwoSqrtAccelDecel);
122  const SUMOReal acc = myAccel * (1. - pow(egoSpeed / desSpeed, myDelta) - (s * s) / (gap2pred * gap2pred));
123  egoSpeed += ACCEL2SPEED(acc) / myIterations;
124  gap2pred -= MAX2(SUMOReal(0), SPEED2DIST(egoSpeed - predSpeed) / myIterations);
125  }
126  return MAX2(SUMOReal(0), egoSpeed);
127 }
128 
129 
130 MSCFModel*
133 }
SUMOReal stopSpeed(const MSVehicle *const veh, const SUMOReal speed, SUMOReal gap2pred) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling) ...
~MSCFModel_IDM()
Destructor.
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
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
SUMOReal moveHelper(MSVehicle *const veh, SUMOReal vPos) const
Applies interaction with stops and lane changing model influences.
The car-following model abstraction.
Definition: MSCFModel.h:58
SUMOReal myAccel
The vehicle's maximum acceleration [m/s^2].
Definition: MSCFModel.h:292
SUMOReal followSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const
Computes the vehicle's safe speed (no dawdling)
const SUMOReal myDelta
The IDM delta exponent.
T MAX2(T a, T b)
Definition: StdDefs.h:71
SUMOReal levelOfService
state variable for remembering speed deviation history (lambda)
SUMOReal myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:298
#define TS
Definition: SUMOTime.h:52
The car-following model and parameter.
Definition: MSVehicleType.h:74
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
SUMOReal _v(const MSVehicle *const veh, SUMOReal gap2pred, SUMOReal mySpeed, SUMOReal predSpeed, SUMOReal desSpeed) const
MSCFModel_IDM(const MSVehicleType *vtype, SUMOReal accel, SUMOReal decel, SUMOReal headwayTime, SUMOReal delta, SUMOReal internalStepping)
Constructor.
SUMOReal getMinGap() const
Get the free space in front of vehicles of this class.
const SUMOReal myTwoSqrtAccelDecel
A computational shortcut.
SUMOReal interactionGap(const MSVehicle *const , SUMOReal vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
const SUMOReal myExpFactor
A computational shortcut for IDMM.
MSCFModel::VehicleVariables * getCarFollowVariables() const
Returns the vehicle's car following model variables.
Definition: MSVehicle.h:540
virtual SUMOReal moveHelper(MSVehicle *const veh, SUMOReal vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel.cpp:56
SUMOReal desiredSpeed(const MSVehicle *const veh) const
const int myIterations
The number of iterations in speed calculations.
SUMOReal getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:291
#define SUMOReal
Definition: config.h:215
const SUMOReal myAdaptationFactor
The IDMM adaptation factor beta.
const SUMOReal myAdaptationTime
The IDMM adaptation time tau.
SUMOReal myDecel
The vehicle's maximum deceleration [m/s^2].
Definition: MSCFModel.h:295