Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // The original Krauss (1998) car-following model and parameter
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <microsim/MSVehicle.h>
27 #include <microsim/MSLane.h>
28 #include "MSCFModel_Daniel1.h"
31 
32 
33 // ===========================================================================
34 // method definitions
35 // ===========================================================================
37  MSCFModel(vtype),
38  myDawdle(vtype->getParameter().getCFParam(SUMO_ATTR_SIGMA, SUMOVTypeParameter::getDefaultImperfection(vtype->getParameter().vehicleClass))),
39  myTauDecel(myDecel * myHeadwayTime),
40  myTmp1(vtype->getParameter().getCFParam(SUMO_ATTR_TMP1, 1.0)),
41  myTmp2(vtype->getParameter().getCFParam(SUMO_ATTR_TMP2, 1.0)),
42  myTmp3(vtype->getParameter().getCFParam(SUMO_ATTR_TMP3, 1.0)),
43  myTmp4(vtype->getParameter().getCFParam(SUMO_ATTR_TMP4, 1.0)),
44  myTmp5(vtype->getParameter().getCFParam(SUMO_ATTR_TMP5, 1.0)) {
45 }
46 
47 
49 
50 
51 double
52 MSCFModel_Daniel1::finalizeSpeed(MSVehicle* const veh, double vPos) const {
53  const double oldV = veh->getSpeed(); // save old v for optional acceleration computation
54  const double vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
55  // we need the acceleration for emission computation;
56  // in this case, we neglect dawdling, nonetheless, using
57  // vSafe does not incorporate speed reduction due to interaction
58  // on lane changing
59  const double vMin = getSpeedAfterMaxDecel(oldV);
60  const double vMax = MIN3(veh->getLane()->getVehicleMaxSpeed(veh), maxNextSpeed(oldV, veh), vSafe);
61 #ifdef _DEBUG
62  if (vMin > vMax) {
63  WRITE_WARNING("Maximum speed of vehicle '" + veh->getID() + "' is lower than the minimum speed (min: " + toString(vMin) + ", max: " + toString(vMax) + ").");
64  }
65 #endif
66  return veh->getLaneChangeModel().patchSpeed(vMin, MAX2(vMin, dawdle(vMax, veh->getRNG())), vMax, *this);
67 }
68 
69 
70 double
71 MSCFModel_Daniel1::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double /*predMaxDecel*/, const MSVehicle* const /*pred*/) const {
72  return MIN2(_vsafe(gap, predSpeed), maxNextSpeed(speed, veh));
73 }
74 
75 
76 double
77 MSCFModel_Daniel1::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
78  return MIN2(_vsafe(gap, 0), maxNextSpeed(speed, veh));
79 }
80 
81 
82 double
83 MSCFModel_Daniel1::dawdle(double speed, std::mt19937* rng) const {
84  return MAX2(0., speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand(rng)));
85 }
86 
87 
89 double MSCFModel_Daniel1::_vsafe(double gap, double predSpeed) const {
90  if (predSpeed == 0 && gap < 0.01) {
91  return 0;
92  }
93  double vsafe = (double)(-1. * myTauDecel
94  + sqrt(
96  + (predSpeed * predSpeed)
97  + (2. * myDecel * gap)
98  ));
99  assert(vsafe >= 0);
100  return vsafe;
101 }
102 
103 
104 MSCFModel*
106  return new MSCFModel_Daniel1(vtype);
107 }
MSCFModel_Daniel1(const MSVehicleType *vtype)
Constructor.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
double myTauDecel
The precomputed value for myDecel*myTau.
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:53
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:561
std::mt19937 * getRNG() const
Structure representing possible vehicle parameter.
The car-following model abstraction.
Definition: MSCFModel.h:57
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:60
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:239
double myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:616
T MAX2(T a, T b)
Definition: StdDefs.h:80
double myDawdle
The vehicle&#39;s dawdle-parameter. 0 for no dawdling, 1 for max.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
The car-following model and parameter.
Definition: MSVehicleType.h:66
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:4609
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:48
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
T MIN2(T a, T b)
Definition: StdDefs.h:74
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:341
virtual double dawdle(double speed, std::mt19937 *rng) const
Applies driver imperfection (dawdling / sigma)
double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:619
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1819
virtual double _vsafe(double gap, double predSpeed) const
Returns the "safe" velocity.
virtual double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0) const
Computes the vehicle&#39;s safe speed (no dawdling)
T MIN3(T a, T b, T c)
Definition: StdDefs.h:87
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 getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:477
const std::string & getID() const
Returns the name of the vehicle.
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane&#39;s maximum speed, given a vehicle&#39;s speed limit adaptation.
Definition: MSLane.h:519
~MSCFModel_Daniel1()
Destructor.