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.sourceforge.net/
12 // Copyright (C) 2001-2012 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  myTwoSqrtAccelDecel(SUMOReal(2 * sqrt(accel* decel))), myIterations(MAX2(1, int(TS / internalStepping + .5))) {
50 }
51 
52 
54  SUMOReal accel, SUMOReal decel, SUMOReal headwayTime,
55  SUMOReal adaptationFactor, SUMOReal adaptationTime,
56  SUMOReal internalStepping)
57  : MSCFModel(vtype, accel, decel, headwayTime), myDelta(4.),
58  myAdaptationFactor(adaptationFactor), myAdaptationTime(adaptationTime), myExpFactor(exp(-TS / adaptationTime)),
59  myTwoSqrtAccelDecel(SUMOReal(2 * sqrt(accel* decel))), myIterations(MAX2(1, int(TS / internalStepping + .5))) {
60 }
61 
62 
64 
65 
67 MSCFModel_IDM::moveHelper(MSVehicle* const veh, SUMOReal vPos) const {
68  const SUMOReal vNext = MSCFModel::moveHelper(veh, vPos);
69  if (myExpFactor > 0.) {
71  vars->levelOfService *= myExpFactor;
72  vars->levelOfService += vNext / desiredSpeed(veh) * myAdaptationTime * (1. - myExpFactor);
73  }
74  return vNext;
75 }
76 
77 
79 MSCFModel_IDM::followSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal /*predMaxDecel*/) const {
80  return _v(veh, gap2pred, speed, predSpeed, desiredSpeed(veh));
81 }
82 
83 
85 MSCFModel_IDM::stopSpeed(const MSVehicle* const veh, SUMOReal gap2pred) const {
86  if (gap2pred < 0.01) {
87  return 0;
88  }
89  return _v(veh, gap2pred, veh->getSpeed(), 0, desiredSpeed(veh));
90 }
91 
92 
95 MSCFModel_IDM::interactionGap(const MSVehicle* const veh, SUMOReal vL) const {
96  // Resolve the IDM equation to gap. Assume predecessor has
97  // speed != 0 and that vsafe will be the current speed plus acceleration,
98  // i.e that with this gap there will be no interaction.
99  SUMOReal acc = myAccel * (1. - pow(veh->getSpeed() / desiredSpeed(veh), myDelta));
100  SUMOReal vNext = veh->getSpeed() + acc;
101  SUMOReal gap = (vNext - vL) * (veh->getSpeed() + vL) / (2 * myDecel) + vL;
102 
103  // Don't allow timeHeadWay < deltaT situations.
104  return MAX2(gap, SPEED2DIST(vNext));
105 }
106 
107 
108 SUMOReal
109 MSCFModel_IDM::_v(const MSVehicle* const veh, SUMOReal gap2pred, SUMOReal egoSpeed, SUMOReal predSpeed, SUMOReal desSpeed) const {
110  SUMOReal headwayTime = myHeadwayTime;
111  if (myExpFactor > 0.) {
113  headwayTime *= myAdaptationFactor + vars->levelOfService * (1. - myAdaptationFactor);
114  }
115  for (int i = 0; i < myIterations; i++) {
116  const SUMOReal delta_v = egoSpeed - predSpeed;
117  const SUMOReal s = myType->getMinGap() + MAX2(SUMOReal(0), egoSpeed * headwayTime + egoSpeed * delta_v / myTwoSqrtAccelDecel);
118  const SUMOReal acc = myAccel * (1. - pow(egoSpeed / desSpeed, myDelta) - (s * s) / (gap2pred * gap2pred));
119  egoSpeed += ACCEL2SPEED(acc) / myIterations;
120  gap2pred -= MAX2(SUMOReal(0), SPEED2DIST(egoSpeed - predSpeed) / myIterations);
121  }
122  return MAX2(SUMOReal(0), egoSpeed);
123 }
124 
125 
126 MSCFModel*
129 }