SUMO - Simulation of Urban MObility
MSCFModel_KraussOrig1.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00011 // The original Krauss (1998) car-following model and parameter
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_KraussOrig1.h"
00038 #include <microsim/MSAbstractLaneChangeModel.h>
00039 #include <utils/common/RandHelper.h>
00040 
00041 
00042 // ===========================================================================
00043 // method definitions
00044 // ===========================================================================
00045 MSCFModel_KraussOrig1::MSCFModel_KraussOrig1(const MSVehicleType* vtype,  SUMOReal accel, SUMOReal decel,
00046         SUMOReal dawdle, SUMOReal headwayTime)
00047     : MSCFModel(vtype, accel, decel, headwayTime), myDawdle(dawdle), myTauDecel(decel* headwayTime) {
00048 }
00049 
00050 
00051 MSCFModel_KraussOrig1::~MSCFModel_KraussOrig1() {}
00052 
00053 
00054 SUMOReal
00055 MSCFModel_KraussOrig1::moveHelper(MSVehicle* const veh, SUMOReal vPos) const {
00056     const SUMOReal oldV = veh->getSpeed(); // save old v for optional acceleration computation
00057     const SUMOReal vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
00058     // we need the acceleration for emission computation;
00059     //  in this case, we neglect dawdling, nonetheless, using
00060     //  vSafe does not incorporate speed reduction due to interaction
00061     //  on lane changing
00062     veh->setPreDawdleAcceleration(SPEED2ACCEL(vSafe - oldV));
00063     const SUMOReal vMin = MAX2((SUMOReal) 0, oldV - ACCEL2SPEED(myDecel));
00064     const SUMOReal vMax = MIN3(veh->getLane()->getMaxSpeed(), maxNextSpeed(oldV), vSafe);
00065 #ifdef _DEBUG
00066     if (vMin > vMax) {
00067         WRITE_WARNING("Vehicle's '" + veh->getID() + "' maximum speed is lower than the minimum speed (min: " + toString(vMin) + ", max: " + toString(vMax) + ").");
00068     }
00069 #endif
00070     return veh->getLaneChangeModel().patchSpeed(vMin, MAX2(vMin, dawdle(vMax)), vMax, *this);
00071 }
00072 
00073 
00074 SUMOReal
00075 MSCFModel_KraussOrig1::followSpeed(const MSVehicle* const /*veh*/, SUMOReal speed, SUMOReal gap, SUMOReal predSpeed, SUMOReal /*predMaxDecel*/) const {
00076     return MIN2(_vsafe(gap, predSpeed), maxNextSpeed(speed));
00077 }
00078 
00079 
00080 SUMOReal
00081 MSCFModel_KraussOrig1::stopSpeed(const MSVehicle* const veh, SUMOReal gap) const {
00082     return MIN2(_vsafe(gap, 0), maxNextSpeed(veh->getSpeed()));
00083 }
00084 
00085 
00086 SUMOReal
00087 MSCFModel_KraussOrig1::dawdle(SUMOReal speed) const {
00088     return MAX2(SUMOReal(0), speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand()));
00089 }
00090 
00091 
00093 SUMOReal MSCFModel_KraussOrig1::_vsafe(SUMOReal gap, SUMOReal predSpeed) const {
00094     if (predSpeed == 0 && gap < 0.01) {
00095         return 0;
00096     }
00097     SUMOReal vsafe = (SUMOReal)(-1. * myTauDecel
00098                                 + sqrt(
00099                                     myTauDecel * myTauDecel
00100                                     + (predSpeed * predSpeed)
00101                                     + (2. * myDecel * gap)
00102                                 ));
00103     assert(vsafe >= 0);
00104     return vsafe;
00105 }
00106 
00107 
00108 MSCFModel*
00109 MSCFModel_KraussOrig1::duplicate(const MSVehicleType* vtype) const {
00110     return new MSCFModel_KraussOrig1(vtype, myAccel, myDecel, myDawdle, myHeadwayTime);
00111 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines