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