SUMO - Simulation of Urban MObility
MSCFModel_IDM.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // The Intelligent Driver Model (IDM) car-following model
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 /****************************************************************************/
00014 //
00015 //   This file is part of SUMO.
00016 //   SUMO is free software: you can redistribute it and/or modify
00017 //   it under the terms of the GNU General Public License as published by
00018 //   the Free Software Foundation, either version 3 of the License, or
00019 //   (at your option) any later version.
00020 //
00021 /****************************************************************************/
00022 
00023 
00024 // ===========================================================================
00025 // included modules
00026 // ===========================================================================
00027 #ifdef _MSC_VER
00028 #include <windows_config.h>
00029 #else
00030 #include <config.h>
00031 #endif
00032 
00033 #include "MSCFModel_IDM.h"
00034 #include <microsim/MSVehicle.h>
00035 #include <microsim/MSLane.h>
00036 #include <utils/common/RandHelper.h>
00037 #include <utils/common/SUMOTime.h>
00038 
00039 
00040 // ===========================================================================
00041 // method definitions
00042 // ===========================================================================
00043 MSCFModel_IDM::MSCFModel_IDM(const MSVehicleType* vtype,
00044                              SUMOReal accel, SUMOReal decel,
00045                              SUMOReal headwayTime, SUMOReal delta,
00046                              SUMOReal internalStepping)
00047     : MSCFModel(vtype, accel, decel, headwayTime), myDelta(delta),
00048       myAdaptationFactor(1.), myAdaptationTime(0.), myExpFactor(0),
00049       myTwoSqrtAccelDecel(SUMOReal(2 * sqrt(accel* decel))), myIterations(MAX2(1, int(TS / internalStepping + .5))) {
00050 }
00051 
00052 
00053 MSCFModel_IDM::MSCFModel_IDM(const MSVehicleType* vtype,
00054                              SUMOReal accel, SUMOReal decel, SUMOReal headwayTime,
00055                              SUMOReal adaptationFactor, SUMOReal adaptationTime,
00056                              SUMOReal internalStepping)
00057     : MSCFModel(vtype, accel, decel, headwayTime), myDelta(4.),
00058       myAdaptationFactor(adaptationFactor), myAdaptationTime(adaptationTime), myExpFactor(exp(-TS / adaptationTime)),
00059       myTwoSqrtAccelDecel(SUMOReal(2 * sqrt(accel* decel))), myIterations(MAX2(1, int(TS / internalStepping + .5))) {
00060 }
00061 
00062 
00063 MSCFModel_IDM::~MSCFModel_IDM() {}
00064 
00065 
00066 SUMOReal
00067 MSCFModel_IDM::moveHelper(MSVehicle* const veh, SUMOReal vPos) const {
00068     const SUMOReal vNext = MSCFModel::moveHelper(veh, vPos);
00069     if (myExpFactor > 0.) {
00070         VehicleVariables* vars = (VehicleVariables*)veh->getCarFollowVariables();
00071         vars->levelOfService *= myExpFactor;
00072         vars->levelOfService += vNext / desiredSpeed(veh) * myAdaptationTime * (1. - myExpFactor);
00073     }
00074     return vNext;
00075 }
00076 
00077 
00078 SUMOReal
00079 MSCFModel_IDM::followSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal /*predMaxDecel*/) const {
00080     return _v(veh, gap2pred, speed, predSpeed, desiredSpeed(veh));
00081 }
00082 
00083 
00084 SUMOReal
00085 MSCFModel_IDM::stopSpeed(const MSVehicle* const veh, SUMOReal gap2pred) const {
00086     if (gap2pred < 0.01) {
00087         return 0;
00088     }
00089     return _v(veh, gap2pred, veh->getSpeed(), 0, desiredSpeed(veh));
00090 }
00091 
00092 
00094 SUMOReal
00095 MSCFModel_IDM::interactionGap(const MSVehicle* const veh, SUMOReal vL) const {
00096     // Resolve the IDM equation to gap. Assume predecessor has
00097     // speed != 0 and that vsafe will be the current speed plus acceleration,
00098     // i.e that with this gap there will be no interaction.
00099     SUMOReal acc = myAccel * (1. - pow(veh->getSpeed() / desiredSpeed(veh), myDelta));
00100     SUMOReal vNext = veh->getSpeed() + acc;
00101     SUMOReal gap = (vNext - vL) * (veh->getSpeed() + vL) / (2 * myDecel) + vL;
00102 
00103     // Don't allow timeHeadWay < deltaT situations.
00104     return MAX2(gap, SPEED2DIST(vNext));
00105 }
00106 
00107 
00108 SUMOReal
00109 MSCFModel_IDM::_v(const MSVehicle* const veh, SUMOReal gap2pred, SUMOReal egoSpeed, SUMOReal predSpeed, SUMOReal desSpeed) const {
00110     SUMOReal headwayTime = myHeadwayTime;
00111     if (myExpFactor > 0.) {
00112         const VehicleVariables* vars = (VehicleVariables*)veh->getCarFollowVariables();
00113         headwayTime *= myAdaptationFactor + vars->levelOfService * (1. - myAdaptationFactor);
00114     }
00115     for (int i = 0; i < myIterations; i++) {
00116         const SUMOReal delta_v = egoSpeed - predSpeed;
00117         const SUMOReal s = myType->getMinGap() + MAX2(SUMOReal(0), egoSpeed * headwayTime + egoSpeed * delta_v / myTwoSqrtAccelDecel);
00118         const SUMOReal acc = myAccel * (1. - pow(egoSpeed / desSpeed, myDelta) - (s * s) / (gap2pred * gap2pred));
00119         egoSpeed += ACCEL2SPEED(acc) / myIterations;
00120         gap2pred -= MAX2(SUMOReal(0), SPEED2DIST(egoSpeed - predSpeed) / myIterations);
00121     }
00122     return MAX2(SUMOReal(0), egoSpeed);
00123 }
00124 
00125 
00126 MSCFModel*
00127 MSCFModel_IDM::duplicate(const MSVehicleType* vtype) const {
00128     return new MSCFModel_IDM(vtype, myAccel, myDecel, myHeadwayTime, myDelta, TS / myIterations);
00129 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines