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 2001-2010 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 tau) throw()
00042         : MSCFModel(vtype, decel), myAccel(accel), myDawdle(dawdle), myTau(tau) {
00043 
00044     myTauDecel = decel * myTau;
00045 }
00046 
00047 
00048 MSCFModel_Krauss::~MSCFModel_Krauss() throw() {}
00049 
00050 
00051 SUMOReal
00052 MSCFModel_Krauss::moveHelper(MSVehicle * const veh, const MSLane * const lane, SUMOReal vPos) const throw() {
00053     SUMOReal oldV = veh->getSpeed(); // save old v for optional acceleration computation
00054     SUMOReal vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
00055     // we need the acceleration for emission computation;
00056     //  in this case, we neglect dawdling, nonetheless, using
00057     //  vSafe does not incorporate speed reduction due to interaction
00058     //  on lane changing
00059     veh->setPreDawdleAcceleration(SPEED2ACCEL(vSafe-oldV));
00060     //
00061     SUMOReal vNext = dawdle(MIN3(lane->getMaxSpeed(), maxNextSpeed(oldV), vSafe));
00062     vNext =
00063         veh->getLaneChangeModel().patchSpeed(
00064             MAX2((SUMOReal) 0, oldV-(SUMOReal)ACCEL2SPEED(myDecel)), 
00065             vNext,
00066             MIN3(vSafe, veh->getLane().getMaxSpeed(), maxNextSpeed(oldV)),//vaccel(myState.mySpeed, myLane->maxSpeed())),
00067             vSafe);
00068     return MIN4(vNext, vSafe, veh->getLane().getMaxSpeed(), maxNextSpeed(oldV));
00069 }
00070 
00071 
00072 SUMOReal
00073 MSCFModel_Krauss::ffeV(const MSVehicle * const veh, SUMOReal speed, SUMOReal gap, SUMOReal predSpeed) const throw() {
00074     return MIN2(_vsafe(gap, predSpeed), maxNextSpeed(speed));
00075 }
00076 
00077 
00078 SUMOReal
00079 MSCFModel_Krauss::ffeV(const MSVehicle * const veh, SUMOReal gap, SUMOReal predSpeed) const throw() {
00080     return MIN2(_vsafe(gap, predSpeed), maxNextSpeed(veh->getSpeed()));
00081 }
00082 
00083 
00084 SUMOReal
00085 MSCFModel_Krauss::ffeV(const MSVehicle * const veh, const MSVehicle *pred) const throw() {
00086     return MIN2(_vsafe(veh->gap2pred(*pred), pred->getSpeed()), maxNextSpeed(veh->getSpeed()));
00087 }
00088 
00089 
00090 SUMOReal
00091 MSCFModel_Krauss::ffeS(const MSVehicle * const veh, SUMOReal gap) const throw() {
00092     return MIN2(_vsafe(gap, 0), maxNextSpeed(veh->getSpeed()));
00093 }
00094 
00095 
00096 SUMOReal
00097 MSCFModel_Krauss::interactionGap(const MSVehicle * const veh, SUMOReal vL) const throw() {
00098     // Resolve the vsafe equation to gap. Assume predecessor has
00099     // speed != 0 and that vsafe will be the current speed plus acceleration,
00100     // i.e that with this gap there will be no interaction.
00101     SUMOReal vNext = MIN2(maxNextSpeed(veh->getSpeed()), veh->getLane().getMaxSpeed());
00102     SUMOReal gap = (vNext - vL) *
00103                    ((veh->getSpeed() + vL) * myInverseTwoDecel + myTau) +
00104                    vL * myTau;
00105 
00106     // Don't allow timeHeadWay < deltaT situations.
00107     return MAX2(gap, SPEED2DIST(vNext));
00108 }
00109 
00110 
00111 bool
00112 MSCFModel_Krauss::hasSafeGap(SUMOReal speed, SUMOReal gap, SUMOReal predSpeed, SUMOReal laneMaxSpeed) const throw() {
00113     if (gap<0) {
00114         return false;
00115     }
00116     SUMOReal vSafe = MIN2(_vsafe(gap, predSpeed), maxNextSpeed(speed));
00117     SUMOReal vNext = MIN3(maxNextSpeed(speed), laneMaxSpeed, vSafe);
00118     return (vNext>=getSpeedAfterMaxDecel(speed) && gap>= SPEED2DIST(speed));
00119 }
00120 
00121 
00122 SUMOReal
00123 MSCFModel_Krauss::dawdle(SUMOReal speed) const throw() {
00124     // generate random number out of [0,1]
00125     SUMOReal random = RandHelper::rand();
00126     // Dawdle.
00127     if (speed < myAccel) {
00128         // we should not prevent vehicles from driving just due to dawdling
00129         //  if someone is starting, he should definitely start
00130         // (but what about slow-to-start?)!!!
00131         speed -= ACCEL2SPEED(myDawdle * speed * random);
00132     } else {
00133         speed -= ACCEL2SPEED(myDawdle * getMaxAccel(speed) * random);
00134     }
00135     return MAX2(SUMOReal(0), speed);
00136 }
00137 
00138 
00140 SUMOReal MSCFModel_Krauss::_vsafe(SUMOReal gap, SUMOReal predSpeed) const throw() {
00141     if (predSpeed==0&&gap<0.01) {
00142         return 0;
00143     }
00144     SUMOReal vsafe = (SUMOReal)(-1. * myTauDecel + sqrt(myTauDecel*myTauDecel + (predSpeed*predSpeed) + (2. * myDecel * gap)));
00145     assert(vsafe >= 0);
00146     return vsafe;
00147 }
00148 
00149 
00150 
00151 //void MSCFModel::saveState(std::ostream &os) {}
00152 

Generated on Wed May 5 00:06:31 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6