SUMO - Simulation of Urban MObility

MSCFModel_KraussOrig1.cpp

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