SUMO - Simulation of Urban MObility
MSCFModel_Daniel1.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // The original Krauss (1998) car-following model and parameter
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <microsim/MSVehicle.h>
33 #include <microsim/MSLane.h>
34 #include "MSCFModel_Daniel1.h"
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
43  double decel, double emergencyDecel, double apparentDecel,
44  double dawdle, double headwayTime,
45  double tmp1, double tmp2, double tmp3, double tmp4, double tmp5) :
46  MSCFModel(vtype, accel, decel, emergencyDecel, apparentDecel, headwayTime),
47  myDawdle(dawdle), myTauDecel(decel * headwayTime),
48  myTmp1(tmp1), myTmp2(tmp2), myTmp3(tmp3), myTmp4(tmp4), myTmp5(tmp5) {
49 }
50 
51 
53 
54 
55 double
56 MSCFModel_Daniel1::moveHelper(MSVehicle* const veh, double vPos) const {
57  const double oldV = veh->getSpeed(); // save old v for optional acceleration computation
58  const double 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 double vMin = getSpeedAfterMaxDecel(oldV);
64  const double vMax = MIN3(veh->getLane()->getVehicleMaxSpeed(veh), maxNextSpeed(oldV, veh), vSafe);
65 #ifdef _DEBUG
66  if (vMin > vMax) {
67  WRITE_WARNING("Maximum speed of vehicle '" + veh->getID() + "' is lower than the minimum speed (min: " + toString(vMin) + ", max: " + toString(vMax) + ").");
68  }
69 #endif
70  return veh->getLaneChangeModel().patchSpeed(vMin, MAX2(vMin, dawdle(vMax)), vMax, *this);
71 }
72 
73 
74 double
75 MSCFModel_Daniel1::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double /*predMaxDecel*/) const {
76  return MIN2(_vsafe(gap, predSpeed), maxNextSpeed(speed, veh));
77 }
78 
79 
80 double
81 MSCFModel_Daniel1::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
82  return MIN2(_vsafe(gap, 0), maxNextSpeed(speed, veh));
83 }
84 
85 
86 double
87 MSCFModel_Daniel1::dawdle(double speed) const {
88  return MAX2(0., speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand()));
89 }
90 
91 
93 double MSCFModel_Daniel1::_vsafe(double gap, double predSpeed) const {
94  if (predSpeed == 0 && gap < 0.01) {
95  return 0;
96  }
97  double vsafe = (double)(-1. * myTauDecel
98  + sqrt(
100  + (predSpeed * predSpeed)
101  + (2. * myDecel * gap)
102  ));
103  assert(vsafe >= 0);
104  return vsafe;
105 }
106 
107 
108 MSCFModel*
112 }
double getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane&#39;s maximum speed, given a vehicle&#39;s speed limit adaptation.
Definition: MSLane.h:475
double myTmp1
temporary (testing) parameter
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
double myTauDecel
The precomputed value for myDecel*myTau.
double myApparentDecel
The vehicle&#39;s deceleration as expected by surrounding traffic [m/s^2].
Definition: MSCFModel.h:541
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:60
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:564
double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
The car-following model abstraction.
Definition: MSCFModel.h:59
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:64
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:204
double myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:534
T MAX2(T a, T b)
Definition: StdDefs.h:73
virtual double dawdle(double speed) const
Applies driver imperfection (dawdling / sigma)
double myDawdle
The vehicle&#39;s dawdle-parameter. 0 for no dawdling, 1 for max.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
The car-following model and parameter.
Definition: MSVehicleType.h:72
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:3674
virtual double patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)=0
Called to adapt the speed in order to allow a lane change. It uses information on LC-related desired ...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
T MIN2(T a, T b)
Definition: StdDefs.h:67
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:318
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:537
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1376
double myEmergencyDecel
The vehicle&#39;s maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:539
virtual double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle&#39;s safe speed (no dawdling)
virtual double _vsafe(double gap, double predSpeed) const
Returns the "safe" velocity.
T MIN3(T a, T b, T c)
Definition: StdDefs.h:80
virtual double stopSpeed(const MSVehicle *const veh, const double speed, double gap2pred) const
Computes the vehicle&#39;s safe speed for approaching a non-moving obstacle (no dawdling) ...
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:544
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:482
const std::string & getID() const
Returns the name of the vehicle.
MSCFModel_Daniel1(const MSVehicleType *vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double dawdle, double headwayTime, double tmp1, double tmp2, double tmp3, double tmp4, double tmp5)
Constructor.
~MSCFModel_Daniel1()
Destructor.