SUMO - Simulation of Urban MObility
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.dlr.de/
12 // Copyright (C) 2001-2016 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.),
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  myIterations(MAX2(1, int(TS / internalStepping + .5))),
62  myTwoSqrtAccelDecel(SUMOReal(2 * sqrt(accel * decel))) {
63 }
64 
65 
67 
68 
70 MSCFModel_IDM::moveHelper(MSVehicle* const veh, SUMOReal vPos) const {
71  const SUMOReal vNext = MSCFModel::moveHelper(veh, vPos);
72  if (myAdaptationFactor != 1.) {
74  vars->levelOfService += (vNext / veh->getLane()->getVehicleMaxSpeed(veh) - vars->levelOfService) / myAdaptationTime * TS;
75  }
76  return vNext;
77 }
78 
79 
81 MSCFModel_IDM::followSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal /*predMaxDecel*/) const {
82  return _v(veh, gap2pred, speed, predSpeed, veh->getLane()->getVehicleMaxSpeed(veh));
83 }
84 
85 
87 MSCFModel_IDM::stopSpeed(const MSVehicle* const veh, const SUMOReal speed, SUMOReal gap2pred) const {
88  if (gap2pred < 0.01) {
89  return 0;
90  }
91  return _v(veh, gap2pred, speed, 0, veh->getLane()->getVehicleMaxSpeed(veh), false);
92 }
93 
94 
97 MSCFModel_IDM::interactionGap(const MSVehicle* const veh, SUMOReal vL) const {
98  // Resolve the IDM equation to gap. Assume predecessor has
99  // speed != 0 and that vsafe will be the current speed plus acceleration,
100  // i.e that with this gap there will be no interaction.
101  const SUMOReal acc = myAccel * (1. - pow(veh->getSpeed() / veh->getLane()->getVehicleMaxSpeed(veh), myDelta));
102  const SUMOReal vNext = veh->getSpeed() + acc;
103  const SUMOReal gap = (vNext - vL) * (veh->getSpeed() + vL) / (2 * myDecel) + vL;
104 
105  // Don't allow timeHeadWay < deltaT situations.
106  return MAX2(gap, SPEED2DIST(vNext));
107 }
108 
109 
110 SUMOReal
111 MSCFModel_IDM::_v(const MSVehicle* const veh, const SUMOReal gap2pred, const SUMOReal egoSpeed,
112  const SUMOReal predSpeed, const SUMOReal desSpeed, const bool respectMinGap) const {
113 // this is more or less based on http://www.vwi.tu-dresden.de/~treiber/MicroApplet/IDM.html
114 // and http://arxiv.org/abs/cond-mat/0304337
115 // we assume however constant speed for the leader
116  SUMOReal headwayTime = myHeadwayTime;
117  if (myAdaptationFactor != 1.) {
119  headwayTime *= myAdaptationFactor + vars->levelOfService * (1. - myAdaptationFactor);
120  }
121  SUMOReal newSpeed = egoSpeed;
122  SUMOReal gap = gap2pred;
123  for (int i = 0; i < myIterations; i++) {
124  const SUMOReal delta_v = newSpeed - predSpeed;
125  SUMOReal s = MAX2(SUMOReal(0), newSpeed * headwayTime + newSpeed * delta_v / myTwoSqrtAccelDecel);
126  if (respectMinGap) {
127  s += myType->getMinGap();
128  }
129  const SUMOReal acc = myAccel * (1. - pow(newSpeed / desSpeed, myDelta) - (s * s) / (gap * gap));
130  newSpeed += ACCEL2SPEED(acc) / myIterations;
131  //TODO use more realistic position update which takes accelerated motion into account
132  gap -= MAX2(SUMOReal(0), SPEED2DIST(newSpeed - predSpeed) / myIterations);
133  }
134 // return MAX2(getSpeedAfterMaxDecel(egoSpeed), newSpeed);
135  return MAX2(SUMOReal(0), newSpeed);
136 }
137 
138 
139 MSCFModel*
142 }
~MSCFModel_IDM()
Destructor.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
MSCFModel::VehicleVariables * getCarFollowVariables() const
Returns the vehicle&#39;s car following model variables.
Definition: MSVehicle.h:767
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:463
#define SPEED2DIST(x)
Definition: SUMOTime.h:55
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:487
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
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:60
virtual SUMOReal moveHelper(MSVehicle *const veh, SUMOReal vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel.cpp:144
SUMOReal myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:466
const SUMOReal myDelta
The IDM delta exponent.
T MAX2(T a, T b)
Definition: StdDefs.h:75
SUMOReal levelOfService
state variable for remembering speed deviation history (lambda)
SUMOReal myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:472
#define TS
Definition: SUMOTime.h:52
SUMOReal followSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const
Computes the vehicle&#39;s safe speed (no dawdling)
The car-following model and parameter.
Definition: MSVehicleType.h:74
MSCFModel_IDM(const MSVehicleType *vtype, SUMOReal accel, SUMOReal decel, SUMOReal headwayTime, SUMOReal delta, SUMOReal internalStepping)
Constructor.
const SUMOReal myTwoSqrtAccelDecel
A computational shortcut.
SUMOReal stopSpeed(const MSVehicle *const veh, const SUMOReal speed, SUMOReal gap2pred) const
Computes the vehicle&#39;s safe speed for approaching a non-moving obstacle (no dawdling) ...
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane&#39;s maximum speed, given a vehicle&#39;s speed limit adaptation.
Definition: MSLane.h:458
const int myIterations
The number of iterations in speed calculations.
SUMOReal interactionGap(const MSVehicle *const, SUMOReal vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
SUMOReal _v(const MSVehicle *const veh, const SUMOReal gap2pred, const SUMOReal mySpeed, const SUMOReal predSpeed, const SUMOReal desSpeed, const bool respectMinGap=true) const
SUMOReal getMinGap() const
Get the free space in front of vehicles of this class.
#define SUMOReal
Definition: config.h:213
const SUMOReal myAdaptationFactor
The IDMM adaptation factor beta.
const SUMOReal myAdaptationTime
The IDMM adaptation time tau.
SUMOReal getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:441
SUMOReal myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:469