SUMO - Simulation of Urban MObility
MSCFModel_IDM.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // The Intelligent Driver Model (IDM) car-following model
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include "MSCFModel_IDM.h"
27 #include <microsim/MSVehicle.h>
28 
29 
30 // ===========================================================================
31 // method definitions
32 // ===========================================================================
33 MSCFModel_IDM::MSCFModel_IDM(const MSVehicleType* vtype, bool idmm) :
34  MSCFModel(vtype),
35  myIDMM(idmm),
36  myDelta(idmm ? 4.0 : vtype->getParameter().getCFParam(SUMO_ATTR_CF_IDM_DELTA, 4.)),
37  myAdaptationFactor(idmm ? vtype->getParameter().getCFParam(SUMO_ATTR_CF_IDMM_ADAPT_FACTOR, 1.8) : 1.0),
38  myAdaptationTime(idmm ? vtype->getParameter().getCFParam(SUMO_ATTR_CF_IDMM_ADAPT_TIME, 600.0) : 0.0),
39  myIterations(MAX2(1, int(TS / vtype->getParameter().getCFParam(SUMO_ATTR_CF_IDM_STEPPING, .25) + .5))),
40  myTwoSqrtAccelDecel(double(2 * sqrt(myAccel * myDecel))) {
41 }
42 
44 
45 
46 double
47 MSCFModel_IDM::finalizeSpeed(MSVehicle* const veh, double vPos) const {
48  const double vNext = MSCFModel::finalizeSpeed(veh, vPos);
49  if (myAdaptationFactor != 1.) {
51  vars->levelOfService += (vNext / veh->getLane()->getVehicleMaxSpeed(veh) - vars->levelOfService) / myAdaptationTime * TS;
52  }
53  return vNext;
54 }
55 
56 
57 double
58 MSCFModel_IDM::followSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double /*predMaxDecel*/, const MSVehicle* const /*pred*/) const {
59  return _v(veh, gap2pred, speed, predSpeed, veh->getLane()->getVehicleMaxSpeed(veh));
60 }
61 
62 
63 double
64 MSCFModel_IDM::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
65  if (gap < 0.01) {
66  return 0;
67  }
68  double result = _v(veh, gap, speed, 0, veh->getLane()->getVehicleMaxSpeed(veh), false);
69  if (gap > 0 && speed < NUMERICAL_EPS) {
70  // ensure that stops can be reached:
71  result = maximumSafeStopSpeed(gap, speed, false, 0);
72  }
73  return result;
74 }
75 
76 
78 double
79 MSCFModel_IDM::interactionGap(const MSVehicle* const veh, double vL) const {
80  // Resolve the IDM equation to gap. Assume predecessor has
81  // speed != 0 and that vsafe will be the current speed plus acceleration,
82  // i.e that with this gap there will be no interaction.
83  const double acc = myAccel * (1. - pow(veh->getSpeed() / veh->getLane()->getVehicleMaxSpeed(veh), myDelta));
84  const double vNext = veh->getSpeed() + acc;
85  const double gap = (vNext - vL) * (veh->getSpeed() + vL) / (2 * myDecel) + vL;
86 
87  // Don't allow timeHeadWay < deltaT situations.
88  return MAX2(gap, SPEED2DIST(vNext));
89 }
90 
91 
92 double
93 MSCFModel_IDM::_v(const MSVehicle* const veh, const double gap2pred, const double egoSpeed,
94  const double predSpeed, const double desSpeed, const bool respectMinGap) const {
95 // this is more or less based on http://www.vwi.tu-dresden.de/~treiber/MicroApplet/IDM.html
96 // and http://arxiv.org/abs/cond-mat/0304337
97 // we assume however constant speed for the leader
98  double headwayTime = myHeadwayTime;
99  if (myAdaptationFactor != 1.) {
101  headwayTime *= myAdaptationFactor + vars->levelOfService * (1. - myAdaptationFactor);
102  }
103  double newSpeed = egoSpeed;
104  double gap = gap2pred;
105  for (int i = 0; i < myIterations; i++) {
106  const double delta_v = newSpeed - predSpeed;
107  double s = MAX2(0., newSpeed * headwayTime + newSpeed * delta_v / myTwoSqrtAccelDecel);
108  if (respectMinGap) {
109  s += myType->getMinGap();
110  }
111  const double acc = myAccel * (1. - pow(newSpeed / desSpeed, myDelta) - (s * s) / (gap * gap));
112  newSpeed += ACCEL2SPEED(acc) / myIterations;
113  //TODO use more realistic position update which takes accelerated motion into account
114  gap -= MAX2(0., SPEED2DIST(newSpeed - predSpeed) / myIterations);
115  }
116 // return MAX2(getSpeedAfterMaxDecel(egoSpeed), newSpeed);
117  return MAX2(0., newSpeed);
118 }
119 
120 
121 MSCFModel*
123  return new MSCFModel_IDM(vtype, myIDMM);
124 }
double getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane&#39;s maximum speed, given a vehicle&#39;s speed limit adaptation.
Definition: MSLane.h:485
~MSCFModel_IDM()
Destructor.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
double interactionGap(const MSVehicle *const, double vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
MSCFModel::VehicleVariables * getCarFollowVariables() const
Returns the vehicle&#39;s car following model variables.
Definition: MSVehicle.h:905
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:581
#define SPEED2DIST(x)
Definition: SUMOTime.h:48
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:54
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:561
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
const bool myIDMM
whether the model is IDMM or IDM
const double myDelta
The IDM delta exponent.
The car-following model abstraction.
Definition: MSCFModel.h:57
const double myAdaptationFactor
The IDMM adaptation factor beta.
double myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:584
T MAX2(T a, T b)
Definition: StdDefs.h:68
double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
MSCFModel_IDM(const MSVehicleType *vtype, bool idmm)
Constructor.
#define TS
Definition: SUMOTime.h:45
virtual double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences. Called at most once per simulation...
Definition: MSCFModel.cpp:163
The car-following model and parameter.
Definition: MSVehicleType.h:66
double stopSpeed(const MSVehicle *const veh, const double speed, double gap) const
Computes the vehicle&#39;s safe speed for approaching a non-moving obstacle (no dawdling) ...
const double myAdaptationTime
The IDMM adaptation time tau.
double levelOfService
state variable for remembering speed deviation history (lambda)
double _v(const MSVehicle *const veh, const double gap2pred, const double mySpeed, const double predSpeed, const double desSpeed, const bool respectMinGap=true) const
double getMinGap() const
Get the free space in front of vehicles of this class.
const double myTwoSqrtAccelDecel
A computational shortcut.
double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap.
Definition: MSCFModel.cpp:703
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:587
const int myIterations
The number of iterations in speed calculations.
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0) const
Computes the vehicle&#39;s safe speed (no dawdling)
#define NUMERICAL_EPS
Definition: config.h:148
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:594
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:479