SUMO - Simulation of Urban MObility
MSCFModel.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // The car-following model abstraction
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
14 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <math.h>
36 #include <microsim/MSVehicleType.h>
37 #include <microsim/MSVehicle.h>
38 #include <microsim/MSLane.h>
40 #include "MSCFModel.h"
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 MSCFModel::MSCFModel(const MSVehicleType* vtype, const SUMOReal accel,
47  const SUMOReal decel, const SUMOReal headwayTime)
48  : myType(vtype), myAccel(accel), myDecel(decel), myHeadwayTime(headwayTime) {
49 }
50 
51 
53 
54 
56 MSCFModel::moveHelper(MSVehicle* const veh, SUMOReal vPos) const {
57  const SUMOReal oldV = veh->getSpeed(); // save old v for optional acceleration computation
58  const SUMOReal vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
59  // we need the acceleration for emission computation;
60  // in this case, we neglect dawdling, nonetheless, using
61  // vSafe does not incorporate speed reduction due to interaction
62  // on lane changing
63  const SUMOReal vMin = getSpeedAfterMaxDecel(oldV);
64  const SUMOReal vMax = MIN3(veh->getLane()->getVehicleMaxSpeed(veh), maxNextSpeed(oldV, veh), vSafe);
65  assert(vMin <= vMax);
66  return veh->getLaneChangeModel().patchSpeed(vMin, vMax, vMax, *this);
67 }
68 
69 
71 MSCFModel::interactionGap(const MSVehicle* const veh, SUMOReal vL) const {
72  // Resolve the vsafe equation to gap. Assume predecessor has
73  // speed != 0 and that vsafe will be the current speed plus acceleration,
74  // i.e that with this gap there will be no interaction.
75  const SUMOReal vNext = MIN2(maxNextSpeed(veh->getSpeed(), veh), veh->getLane()->getVehicleMaxSpeed(veh));
76  const SUMOReal gap = (vNext - vL) *
77  ((veh->getSpeed() + vL) / (2.*myDecel) + myHeadwayTime) +
78  vL * myHeadwayTime;
79 
80  // Don't allow timeHeadWay < deltaT situations.
81  return MAX2(gap, SPEED2DIST(vNext));
82 }
83 
84 
86 MSCFModel::maxNextSpeed(SUMOReal speed, const MSVehicle* const /*veh*/) const {
87  return MIN2(speed + (SUMOReal) ACCEL2SPEED(getMaxAccel()), myType->getMaxSpeed());
88 }
89 
90 
92 MSCFModel::freeSpeed(const MSVehicle* const /* veh */, SUMOReal /* speed */, SUMOReal seen, SUMOReal maxSpeed) const {
93  // adapt speed to succeeding lane, no reaction time is involved
94  // when breaking for y steps the following distance g is covered
95  // (drive with v in the final step)
96  // g = (y^2 + y) * 0.5 * b + y * v
97  // y = ((((sqrt((b + 2.0*v)*(b + 2.0*v) + 8.0*b*g)) - b)*0.5 - v)/b)
98  const SUMOReal b = ACCEL2SPEED(myDecel);
99  const SUMOReal v = SPEED2DIST(maxSpeed);
100  const SUMOReal y = MAX2(0.0, ((sqrt((b + 2.0 * v) * (b + 2.0 * v) + 8.0 * b * seen) - b) * 0.5 - v) / b);
101  const SUMOReal yFull = floor(y);
102  const SUMOReal exactGap = (yFull * yFull + yFull) * 0.5 * b + yFull * v + (y > yFull ? v : 0.0);
103  return MAX2((SUMOReal)0.0, seen - exactGap) / (yFull + 1) + yFull * b + maxSpeed;
104 }
105 
106 /****************************************************************************/
SUMOReal getSpeedAfterMaxDecel(SUMOReal v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:245
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
SUMOReal getMaxSpeed() const
Get vehicle's maximum speed [m/s].
const MSVehicleType * myType
The type to which this model definition belongs to.
Definition: MSCFModel.h:289
#define SPEED2DIST(x)
Definition: SUMOTime.h:55
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
virtual SUMOReal maxNextSpeed(SUMOReal speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:86
T MAX2(T a, T b)
Definition: StdDefs.h:72
MSCFModel(const MSVehicleType *vtype, SUMOReal accel, SUMOReal decel, SUMOReal headwayTime)
Constructor.
Definition: MSCFModel.cpp:46
SUMOReal myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:298
SUMOReal processNextStop(SUMOReal currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:773
The car-following model and parameter.
Definition: MSVehicleType.h:74
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:1750
virtual SUMOReal interactionGap(const MSVehicle *const veh, SUMOReal vL) const
Returns the maximum gap at which an interaction between both vehicles occurs.
Definition: MSCFModel.cpp:71
T MIN2(T a, T b)
Definition: StdDefs.h:66
virtual SUMOReal moveHelper(MSVehicle *const veh, SUMOReal vPos) const
Applies interaction with stops and lane changing model influences.
Definition: MSCFModel.cpp:56
SUMOReal getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
Definition: MSCFModel.h:157
virtual ~MSCFModel()
Destructor.
Definition: MSCFModel.cpp:52
virtual SUMOReal freeSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal seen, SUMOReal maxSpeed) const
Computes the vehicle's safe speed without a leader.
Definition: MSCFModel.cpp:92
virtual SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max, const MSCFModel &cfModel)=0
Called to adapt the speed in order to allow a lane change.
SUMOReal getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:291
#define SUMOReal
Definition: config.h:215
T MIN3(T a, T b, T c)
Definition: StdDefs.h:79
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
Definition: MSLane.h:354
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:328
SUMOReal myDecel
The vehicle's maximum deceleration [m/s^2].
Definition: MSCFModel.h:295