SUMO - Simulation of Urban MObility

MSCFModel_Krauss.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Krauss car-following model, with acceleration decrease and faster start
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 
00020 
00021 // ===========================================================================
00022 // included modules
00023 // ===========================================================================
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029 
00030 #include <microsim/MSVehicle.h>
00031 #include <microsim/MSLane.h>
00032 #include "MSCFModel_Krauss.h"
00033 #include <microsim/MSAbstractLaneChangeModel.h>
00034 #include <utils/common/RandHelper.h>
00035 
00036 
00037 // ===========================================================================
00038 // method definitions
00039 // ===========================================================================
00040 MSCFModel_Krauss::MSCFModel_Krauss(const MSVehicleType* vtype, SUMOReal accel, SUMOReal decel,
00041                                    SUMOReal dawdle, SUMOReal headwayTime)
00042     : MSCFModel_KraussOrig1(vtype, accel, decel, dawdle, headwayTime) {
00043 }
00044 
00045 
00046 MSCFModel_Krauss::~MSCFModel_Krauss() {}
00047 
00048 
00049 SUMOReal
00050 MSCFModel_Krauss::followSpeed(const MSVehicle* const /*veh*/, SUMOReal speed, SUMOReal gap, SUMOReal predSpeed, SUMOReal predMaxDecel) const {
00051     return MAX2(getSpeedAfterMaxDecel(speed), MIN2(_vsafe(gap, predSpeed, predMaxDecel), maxNextSpeed(speed)));
00052 }
00053 
00054 
00055 SUMOReal
00056 MSCFModel_Krauss::stopSpeed(const MSVehicle* const veh, SUMOReal gap) const {
00057     return MAX2(getSpeedAfterMaxDecel(veh->getSpeed()), MIN2(_vsafe(gap, 0, 0), maxNextSpeed(veh->getSpeed())));
00058 }
00059 
00060 
00061 SUMOReal
00062 MSCFModel_Krauss::dawdle(SUMOReal speed) const {
00063     // generate random number out of [0,1]
00064     SUMOReal random = RandHelper::rand();
00065     // Dawdle.
00066     if (speed < myAccel) {
00067         // we should not prevent vehicles from driving just due to dawdling
00068         //  if someone is starting, he should definitely start
00069         // (but what about slow-to-start?)!!!
00070         speed -= ACCEL2SPEED(myDawdle * speed * random);
00071     } else {
00072         speed -= ACCEL2SPEED(myDawdle * myAccel * random);
00073     }
00074     return MAX2(SUMOReal(0), speed);
00075 }
00076 
00077 
00079 SUMOReal
00080 MSCFModel_Krauss::_vsafe(SUMOReal gap, SUMOReal predSpeed, SUMOReal predMaxDecel) const {
00081     if (predSpeed==0) {
00082         if (gap < 0.01) {
00083             return 0;
00084         }
00085         return (SUMOReal)(-myTauDecel + sqrt(myTauDecel*myTauDecel + 2. * myDecel * gap));
00086     }
00087     if (predMaxDecel == 0) {
00088         return predSpeed;
00089     }
00090     const SUMOReal speedReduction = ACCEL2SPEED(predMaxDecel);
00091     const int predSteps = int(predSpeed / speedReduction);
00092     const SUMOReal leaderContrib = 2. * myDecel * (gap + SPEED2DIST(predSteps * predSpeed - speedReduction * predSteps * (predSteps+1) / 2));
00093     return (SUMOReal)(-myTauDecel + sqrt(myTauDecel*myTauDecel + leaderContrib));
00094 }
00095 
00096 
00097 MSCFModel*
00098 MSCFModel_Krauss::duplicate(const MSVehicleType* vtype) const {
00099     return new MSCFModel_Krauss(vtype, myAccel, myDecel, myDawdle, myHeadwayTime);
00100 }
00101 
00102 
00103 //void MSCFModel::saveState(std::ostream &os) {}
00104 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines