SUMO - Simulation of Urban MObility

MSCFModel.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The car-following model abstraction
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 "MSCFModel.h"
00031 #include "MSVehicleType.h"
00032 #include "MSVehicle.h"
00033 #include "MSLane.h"
00034 #include "MSAbstractLaneChangeModel.h"
00035 
00036 
00037 // ===========================================================================
00038 // method definitions
00039 // ===========================================================================
00040 MSCFModel::MSCFModel(const MSVehicleType* vtype, const SUMOReal accel,
00041                      const SUMOReal decel, const SUMOReal headwayTime)
00042     : myType(vtype), myAccel(accel), myDecel(decel), myHeadwayTime(headwayTime) {
00043 }
00044 
00045 
00046 MSCFModel::~MSCFModel() {}
00047 
00048 
00049 SUMOReal
00050 MSCFModel::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     assert(vMin<=vMax);
00061     return veh->getLaneChangeModel().patchSpeed(vMin, vMax, vMax, *this);
00062 }
00063 
00064 
00065 SUMOReal
00066 MSCFModel::interactionGap(const MSVehicle* const veh, SUMOReal vL) const {
00067     // Resolve the vsafe equation to gap. Assume predecessor has
00068     // speed != 0 and that vsafe will be the current speed plus acceleration,
00069     // i.e that with this gap there will be no interaction.
00070     const SUMOReal vNext = MIN2(maxNextSpeed(veh->getSpeed()), veh->getLane()->getMaxSpeed());
00071     const SUMOReal gap = (vNext - vL) *
00072                          ((veh->getSpeed() + vL) / (2.*myDecel) + myHeadwayTime) +
00073                          vL * myHeadwayTime;
00074 
00075     // Don't allow timeHeadWay < deltaT situations.
00076     return MAX2(gap, SPEED2DIST(vNext));
00077 }
00078 
00079 
00080 void
00081 MSCFModel::leftVehicleVsafe(const MSVehicle* const ego, const MSVehicle* const neigh, SUMOReal& vSafe) const {
00082     if (neigh!=0&&neigh->getSpeed()>60./3.6) {
00083         SUMOReal mgap = MAX2((SUMOReal) 0, neigh->getPositionOnLane()-neigh->getVehicleType().getLengthWithGap()-ego->getPositionOnLane());
00084         SUMOReal nVSafe = followSpeed(ego, ego->getSpeed(), mgap, neigh->getSpeed(), neigh->getCarFollowModel().getMaxDecel());
00085         if (mgap-neigh->getSpeed()>=0) {
00086             vSafe = MIN2(vSafe, nVSafe);
00087         }
00088     }
00089 }
00090 
00091 
00092 SUMOReal
00093 MSCFModel::maxNextSpeed(SUMOReal speed) const {
00094     return MIN2(speed + (SUMOReal) ACCEL2SPEED(getMaxAccel()), myType->getMaxSpeed());
00095 }
00096 
00097 
00098 SUMOReal
00099 MSCFModel::brakeGap(SUMOReal speed) const {
00100     /* one possiblity to speed this up is to precalculate speedReduction * steps * (steps+1) / 2
00101        for small values of steps (up to 10 maybe) and store them in an array */
00102     const SUMOReal speedReduction = ACCEL2SPEED(getMaxDecel());
00103     const int steps = int(speed / speedReduction);
00104     return SPEED2DIST(steps * speed - speedReduction * steps *(steps+1) / 2) + speed * myHeadwayTime;
00105 }
00106 
00107 
00108 void MSCFModel::saveState(std::ostream& /*os*/) {}
00109 
00110 
00111 /****************************************************************************/
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines