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-2013 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 }