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 /****************************************************************************/
18 // Krauss car-following model, with acceleration decrease and faster start
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <microsim/MSVehicle.h>
28 #include <microsim/MSLane.h>
29 #include <microsim/MSGlobals.h>
30 #include "MSCFModel_Krauss.h"
33 
34 
35 
36 // ===========================================================================
37 // DEBUG constants
38 // ===========================================================================
39 //#define DEBUG_COND (true)
40 #define DEBUG_COND (veh->isSelected())
41 #define DEBUG_DRIVER_ERRORS
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
48  MSCFModel_KraussOrig1(vtype) {
49 }
50 
51 
53 
54 
55 double
56 MSCFModel_Krauss::patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
57  const double sigma = (veh->passingMinor()
59  : myDawdle);
60  const double vDawdle = MAX2(vMin, dawdle2(vMax, sigma, veh->getRNG()));
61  return vDawdle;
62 }
63 
64 
65 double
66 MSCFModel_Krauss::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
67  // NOTE: This allows return of smaller values than minNextSpeed().
68  // Only relevant for the ballistic update: We give the argument headway=veh->getActionStepLengthSecs(), to assure that
69  // the stopping position is approached with a uniform deceleration also for tau!=veh->getActionStepLengthSecs().
70  applyHeadwayPerceptionError(veh, speed, gap);
71  return MIN2(maximumSafeStopSpeed(gap, speed, false, veh->getActionStepLengthSecs()), maxNextSpeed(speed, veh));
72 }
73 
74 
75 double
76 MSCFModel_Krauss::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double predMaxDecel, const MSVehicle* const pred) const {
77  //gDebugFlag1 = DEBUG_COND;
78  applyHeadwayAndSpeedDifferencePerceptionErrors(veh, speed, gap, predSpeed, predMaxDecel, pred);
79  //gDebugFlag1 = DEBUG_COND; // enable for DEBUG_EMERGENCYDECEL
80  const double vsafe = maximumSafeFollowSpeed(gap, speed, predSpeed, predMaxDecel);
81  //gDebugFlag1 = false;
82  const double vmin = minNextSpeedEmergency(speed);
83  const double vmax = maxNextSpeed(speed, veh);
85  return MIN2(vsafe, vmax);
86  } else {
87  // ballistic
88  // XXX: the euler variant can break as strong as it wishes immediately! The ballistic cannot, refs. #2575.
89  return MAX2(MIN2(vsafe, vmax), vmin);
90  }
91 }
92 
93 double
94 MSCFModel_Krauss::dawdle2(double speed, double sigma, std::mt19937* rng) const {
96  // in case of the ballistic update, negative speeds indicate
97  // a desired stop before the completion of the next timestep.
98  // We do not allow dawdling to overwrite this indication
99  if (speed < 0) {
100  return speed;
101  }
102  }
103  // generate random number out of [0,1)
104  const double random = RandHelper::rand(rng);
105  // Dawdle.
106  if (speed < myAccel) {
107  // we should not prevent vehicles from driving just due to dawdling
108  // if someone is starting, he should definitely start
109  // (but what about slow-to-start?)!!!
110  speed -= ACCEL2SPEED(sigma * speed * random);
111  } else {
112  speed -= ACCEL2SPEED(sigma * myAccel * random);
113  }
114  return MAX2(0., speed);
115 }
116 
117 
118 MSCFModel*
120  return new MSCFModel_Krauss(vtype);
121 }
122 
123 
124 /****************************************************************************/
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:65
MSCFModel_Krauss::patchSpeedBeforeLC
double patchSpeedBeforeLC(const MSVehicle *veh, double vMin, double vMax) const
apply custom speed adaptations within the given speed bounds
Definition: MSCFModel_Krauss.cpp:56
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:73
MSCFModel::maximumSafeFollowSpeed
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:856
MSCFModel::maxNextSpeed
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:238
ACCEL2SPEED
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:52
MSCFModel::applyHeadwayAndSpeedDifferencePerceptionErrors
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:982
MSCFModel_Krauss::duplicate
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
Definition: MSCFModel_Krauss.cpp:119
MSVehicle.h
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
RandHelper::rand
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:53
MSVehicle::getActionStepLengthSecs
double getActionStepLengthSecs() const
Returns the vehicle's action step length in secs, i.e. the interval between two action points.
Definition: MSVehicle.h:512
MSCFModel::maximumSafeStopSpeed
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:711
MSCFModel_KraussOrig1::myDawdle
double myDawdle
The vehicle's dawdle-parameter. 0 for no dawdling, 1 for max.
Definition: MSCFModel_KraussOrig1.h:148
MSCFModel_Krauss::followSpeed
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.
Definition: MSCFModel_Krauss.cpp:76
MSCFModel_Krauss::~MSCFModel_Krauss
~MSCFModel_Krauss()
Destructor.
Definition: MSCFModel_Krauss.cpp:52
MSCFModel::minNextSpeedEmergency
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:255
MSCFModel_Krauss::stopSpeed
double stopSpeed(const MSVehicle *const veh, const double speed, double gap2pred) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling) this uses the m...
Definition: MSCFModel_Krauss.cpp:66
MSCFModel_KraussOrig1
The original Krauss (1998) car-following model and parameter.
Definition: MSCFModel_KraussOrig1.h:38
MSGlobals.h
SUMO_ATTR_JM_SIGMA_MINOR
Definition: SUMOXMLDefinitions.h:620
MSBaseVehicle::getVehicleType
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
Definition: MSBaseVehicle.h:123
MSCFModel_Krauss::MSCFModel_Krauss
MSCFModel_Krauss(const MSVehicleType *vtype)
Constructor.
Definition: MSCFModel_Krauss.cpp:47
MSCFModel_Krauss.h
MSVehicle::passingMinor
bool passingMinor() const
decide whether the vehicle is passing a minor link or has comitted to do so
Definition: MSVehicle.cpp:6011
MSVehicleType::getParameter
const SUMOVTypeParameter & getParameter() const
Definition: MSVehicleType.h:560
MSCFModel
The car-following model abstraction.
Definition: MSCFModel.h:56
config.h
MSCFModel_KraussOrig1::vsafe
virtual double vsafe(double gap, double predSpeed, double predMaxDecel) const
Returns the "safe" velocity.
Definition: MSCFModel_KraussOrig1.cpp:96
MSCFModel_Krauss::dawdle2
double dawdle2(double speed, double sigma, std::mt19937 *rng) const
Applies driver imperfection (dawdling / sigma)
Definition: MSCFModel_Krauss.cpp:94
RandHelper.h
MSCFModel::myAccel
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition: MSCFModel.h:617
MSLane.h
MSGlobals::gSemiImplicitEulerUpdate
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:55
MSCFModel::applyHeadwayPerceptionError
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:1018
SUMOVTypeParameter::getJMParam
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.
Definition: SUMOVTypeParameter.cpp:504
MSAbstractLaneChangeModel.h
MSBaseVehicle::getRNG
std::mt19937 * getRNG() const
Definition: MSBaseVehicle.cpp:758
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79