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