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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
22 // Krauss car-following model, with acceleration decrease and faster start
23 /****************************************************************************/
24 #include <config.h>
25 
26 #include <microsim/MSVehicle.h>
27 #include <microsim/MSLane.h>
28 #include <microsim/MSGlobals.h>
29 #include "MSCFModel_Krauss.h"
32 
33 
34 
35 // ===========================================================================
36 // DEBUG constants
37 // ===========================================================================
38 //#define DEBUG_COND (true)
39 #define DEBUG_COND (veh->isSelected())
40 #define DEBUG_DRIVER_ERRORS
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
47  MSCFModel_KraussOrig1(vtype) {
48 }
49 
50 
52 
53 
54 double
55 MSCFModel_Krauss::patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
56  const double sigma = (veh->passingMinor()
58  : myDawdle);
59  const double vDawdle = MAX2(vMin, dawdle2(vMax, sigma, veh->getRNG()));
60  return vDawdle;
61 }
62 
63 
64 double
65 MSCFModel_Krauss::stopSpeed(const MSVehicle* const veh, const double speed, double gap, double decel) const {
66  // NOTE: This allows return of smaller values than minNextSpeed().
67  // Only relevant for the ballistic update: We give the argument headway=veh->getActionStepLengthSecs(), to assure that
68  // the stopping position is approached with a uniform deceleration also for tau!=veh->getActionStepLengthSecs().
69  applyHeadwayPerceptionError(veh, speed, gap);
70  return MIN2(maximumSafeStopSpeed(gap, decel, speed, false, veh->getActionStepLengthSecs()), maxNextSpeed(speed, veh));
71 }
72 
73 
74 double
75 MSCFModel_Krauss::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double predMaxDecel, const MSVehicle* const pred) const {
76  //gDebugFlag1 = DEBUG_COND;
77  applyHeadwayAndSpeedDifferencePerceptionErrors(veh, speed, gap, predSpeed, predMaxDecel, pred);
78  //gDebugFlag1 = DEBUG_COND; // enable for DEBUG_EMERGENCYDECEL
79  const double vsafe = maximumSafeFollowSpeed(gap, speed, predSpeed, predMaxDecel);
80  //gDebugFlag1 = false;
81  const double vmin = minNextSpeedEmergency(speed);
82  const double vmax = maxNextSpeed(speed, veh);
84  return MIN2(vsafe, vmax);
85  } else {
86  // ballistic
87  // XXX: the euler variant can break as strong as it wishes immediately! The ballistic cannot, refs. #2575.
88  return MAX2(MIN2(vsafe, vmax), vmin);
89  }
90 }
91 
92 double
93 MSCFModel_Krauss::dawdle2(double speed, double sigma, SumoRNG* rng) const {
95  // in case of the ballistic update, negative speeds indicate
96  // a desired stop before the completion of the next timestep.
97  // We do not allow dawdling to overwrite this indication
98  if (speed < 0) {
99  return speed;
100  }
101  }
102  // generate random number out of [0,1)
103  const double random = RandHelper::rand(rng);
104  // Dawdle.
105  if (speed < myAccel) {
106  // we should not prevent vehicles from driving just due to dawdling
107  // if someone is starting, he should definitely start
108  // (but what about slow-to-start?)!!!
109  speed -= ACCEL2SPEED(sigma * speed * random);
110  } else {
111  speed -= ACCEL2SPEED(sigma * myAccel * random);
112  }
113  return MAX2(0., speed);
114 }
115 
116 
117 MSCFModel*
119  return new MSCFModel_Krauss(vtype);
120 }
121 
122 
123 /****************************************************************************/
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:49
@ SUMO_ATTR_JM_SIGMA_MINOR
T MIN2(T a, T b)
Definition: StdDefs.h:74
T MAX2(T a, T b)
Definition: StdDefs.h:80
SumoRNG * getRNG() const
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
double patchSpeedBeforeLC(const MSVehicle *veh, double vMin, double vMax) const
apply custom speed adaptations within the given speed bounds
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0) const
Computes the vehicle's safe speed (no dawdling) this uses the maximumSafeFollowSpeed.
double dawdle2(double speed, double sigma, SumoRNG *rng) const
Applies driver imperfection (dawdling / sigma)
double stopSpeed(const MSVehicle *const veh, const double speed, double gap2pred, double decel) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling) this uses the m...
~MSCFModel_Krauss()
Destructor.
MSCFModel_Krauss(const MSVehicleType *vtype)
Constructor.
The original Krauss (1998) car-following model and parameter.
virtual double vsafe(double gap, double predSpeed, double predMaxDecel) const
Returns the "safe" velocity.
double myDawdle
The vehicle's dawdle-parameter. 0 for no dawdling, 1 for max.
The car-following model abstraction.
Definition: MSCFModel.h:55
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:237
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:254
double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap.
Definition: MSCFModel.cpp:716
void applyHeadwayPerceptionError(const MSVehicle *const veh, double speed, double &gap) const
Overwrites gap by the perceived value obtained from the vehicle's driver state.
Definition: MSCFModel.cpp:1023
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's driver state,...
Definition: MSCFModel.cpp:987
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:861
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition: MSCFModel.h:644
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:53
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:75
double getActionStepLengthSecs() const
Returns the vehicle's action step length in secs, i.e. the interval between two action points.
Definition: MSVehicle.h:504
bool passingMinor() const
decide whether the vehicle is passing a minor link or has comitted to do so
Definition: MSVehicle.cpp:6511
The car-following model and parameter.
Definition: MSVehicleType.h:62
const SUMOVTypeParameter & getParameter() const
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Definition: RandHelper.h:119
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.