Eclipse SUMO - Simulation of Urban MObility
MSCFModel_Krauss.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-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 /****************************************************************************/
19 // Krauss car-following model, with acceleration decrease and faster start
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <microsim/MSVehicle.h>
29 #include <microsim/MSLane.h>
30 #include <microsim/MSGlobals.h>
31 #include "MSCFModel_Krauss.h"
34 
35 
36 
37 // ===========================================================================
38 // DEBUG constants
39 // ===========================================================================
40 //#define DEBUG_COND (true)
41 #define DEBUG_COND (veh->isSelected())
42 #define DEBUG_DRIVER_ERRORS
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
49  MSCFModel_KraussOrig1(vtype) {
50 }
51 
52 
54 
55 
56 double
57 MSCFModel_Krauss::patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
58  const double sigma = (veh->passingMinor()
60  : myDawdle);
61  const double vDawdle = MAX2(vMin, dawdle2(vMax, sigma, veh->getRNG()));
62  return vDawdle;
63 }
64 
65 
66 double
67 MSCFModel_Krauss::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
68  // NOTE: This allows return of smaller values than minNextSpeed().
69  // Only relevant for the ballistic update: We give the argument headway=veh->getActionStepLengthSecs(), to assure that
70  // the stopping position is approached with a uniform deceleration also for tau!=veh->getActionStepLengthSecs().
71  if (veh->hasDriverState()) {
72  // @todo: Provide objectID (e.g. pointer address for the relevant object at the given distance(gap))
73  // This is for item related management of known object and perception updates when the distance
74  // changes significantly. (Should not be too important for stationary objects though.)
75  applyHeadwayPerceptionError(veh, speed, gap);
76  }
77  return MIN2(maximumSafeStopSpeed(gap, speed, false, veh->getActionStepLengthSecs()), maxNextSpeed(speed, veh));
78 }
79 
80 
81 double
82 MSCFModel_Krauss::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double predMaxDecel, const MSVehicle* const pred) const {
83  //gDebugFlag1 = DEBUG_COND;
84  if (veh->hasDriverState()) {
85  applyHeadwayAndSpeedDifferencePerceptionErrors(veh, speed, gap, predSpeed, predMaxDecel, pred);
86  }
87  //gDebugFlag1 = DEBUG_COND; // enable for DEBUG_EMERGENCYDECEL
88  const double vsafe = maximumSafeFollowSpeed(gap, speed, predSpeed, predMaxDecel);
89  //gDebugFlag1 = false;
90  const double vmin = minNextSpeedEmergency(speed);
91  const double vmax = maxNextSpeed(speed, veh);
93  return MIN2(vsafe, vmax);
94  } else {
95  // ballistic
96  // XXX: the euler variant can break as strong as it wishes immediately! The ballistic cannot, refs. #2575.
97  return MAX2(MIN2(vsafe, vmax), vmin);
98  }
99 }
100 
101 double
102 MSCFModel_Krauss::dawdle2(double speed, double sigma, std::mt19937* rng) const {
104  // in case of the ballistic update, negative speeds indicate
105  // a desired stop before the completion of the next timestep.
106  // We do not allow dawdling to overwrite this indication
107  if (speed < 0) {
108  return speed;
109  }
110  }
111  // generate random number out of [0,1)
112  const double random = RandHelper::rand(rng);
113  // Dawdle.
114  if (speed < myAccel) {
115  // we should not prevent vehicles from driving just due to dawdling
116  // if someone is starting, he should definitely start
117  // (but what about slow-to-start?)!!!
118  speed -= ACCEL2SPEED(sigma * speed * random);
119  } else {
120  speed -= ACCEL2SPEED(sigma * myAccel * random);
121  }
122  return MAX2(0., speed);
123 }
124 
125 
126 MSCFModel*
128  return new MSCFModel_Krauss(vtype);
129 }
130 
131 
132 /****************************************************************************/
double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion=false) const
Returns the maximum safe velocity for following the given leader.
Definition: MSCFModel.cpp:857
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
double getJMParam(const SumoXMLAttr attr, const double defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:53
std::mt19937 * getRNG() const
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
The original Krauss (1998) car-following model and parameter.
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
~MSCFModel_Krauss()
Destructor.
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) this uses the m...
The car-following model and parameter.
Definition: MSVehicleType.h:66
bool hasDriverState() const
Whether this vehicle is equipped with a MSDriverState.
Definition: MSVehicle.h:1001
double getActionStepLengthSecs() const
Returns the vehicle&#39;s action step length in secs, i.e. the interval between two action points...
Definition: MSVehicle.h:513
MSCFModel_Krauss(const MSVehicleType *vtype)
Constructor.
virtual double minNextSpeedEmergency(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed after emergency braking, given the current speed (depends on the numerical ...
Definition: MSCFModel.cpp:256
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
double myDawdle
The vehicle&#39;s dawdle-parameter. 0 for no dawdling, 1 for max.
T MIN2(T a, T b)
Definition: StdDefs.h:74
double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap.
Definition: MSCFModel.cpp:712
const SUMOVTypeParameter & getParameter() const
void applyHeadwayAndSpeedDifferencePerceptionErrors(const MSVehicle *const veh, double speed, double &gap, double &predSpeed, double predMaxDecel, const MSVehicle *const pred) const
Overwrites gap2pred and predSpeed by the perceived values obtained from the vehicle&#39;s driver state...
Definition: MSCFModel.cpp:983
virtual double vsafe(double gap, double predSpeed, double predMaxDecel) const
Returns the "safe" velocity.
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
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) this uses the maximumSafeFollowSpeed.
double patchSpeedBeforeLC(const MSVehicle *veh, double vMin, double vMax) const
apply custom speed adaptations within the given speed bounds
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:56
bool passingMinor() const
decide whether the vehicle is passing a minor link or has comitted to do so
Definition: MSVehicle.cpp:5928
void applyHeadwayPerceptionError(const MSVehicle *const veh, double speed, double &gap) const
Overwrites gap by the perceived value obtained from the vehicle&#39;s driver state.
Definition: MSCFModel.cpp:1017
double dawdle2(double speed, double sigma, std::mt19937 *rng) const
Applies driver imperfection (dawdling / sigma)