Eclipse SUMO - Simulation of Urban MObility
MSCFModel_KraussOrig1.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 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 // The original Krauss (1998) car-following model and parameter
23 /****************************************************************************/
24 #include <config.h>
25 
26 #include <microsim/MSVehicle.h>
27 #include <microsim/MSLane.h>
28 #include "MSCFModel_KraussOrig1.h"
31 #include <microsim/MSGlobals.h>
32 
33 // ===========================================================================
34 // DEBUG constants
35 // ===========================================================================
36 //#define DEBUG_COND (veh->getID()=="disabled")
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
42  MSCFModel(vtype),
43  myDawdle(vtype->getParameter().getCFParam(SUMO_ATTR_SIGMA, SUMOVTypeParameter::getDefaultImperfection(vtype->getParameter().vehicleClass))),
44  myTauDecel(myDecel * myHeadwayTime) {
45 }
46 
47 
49 
50 double
51 MSCFModel_KraussOrig1::patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
52  UNUSED_PARAMETER(veh);
53  const double vDawdle = MAX2(vMin, dawdle(vMax, veh->getRNG()));
54  return vDawdle;
55 }
56 
57 
58 double
59 MSCFModel_KraussOrig1::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double predMaxDecel, const MSVehicle* const /*pred*/, const CalcReason /*usage*/) const {
61  return MIN2(vsafe(gap, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)); // XXX: and why not cap with minNextSpeed!? (Leo)
62  } else {
63  return MAX2(MIN2(maximumSafeFollowSpeed(gap, speed, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)), minNextSpeed(speed));
64  }
65 }
66 
67 
68 double
69 MSCFModel_KraussOrig1::stopSpeed(const MSVehicle* const veh, const double speed, double gap, double decel, const CalcReason /*usage*/) const {
71  return MIN2(vsafe(gap, 0., 0.), maxNextSpeed(speed, veh));
72  } else {
73  // XXX: using this here is probably in the spirit of Krauss, but we should consider,
74  // if the original vsafe should be kept instead (Leo), refs. #2575
75  return MIN2(maximumSafeStopSpeedBallistic(gap, decel, speed), maxNextSpeed(speed, veh));
76  }
77 }
78 
79 
80 double
81 MSCFModel_KraussOrig1::dawdle(double speed, SumoRNG* rng) const {
83  // in case of the ballistic update, negative speeds indicate
84  // a desired stop before the completion of the next timestep.
85  // We do not allow dawdling to overwrite this indication
86  if (speed < 0) {
87  return speed;
88  }
89  }
90  return MAX2(0., speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand(rng)));
91 }
92 
93 
95 double MSCFModel_KraussOrig1::vsafe(double gap, double predSpeed, double /* predMaxDecel */) const {
96  if (predSpeed == 0 && gap < 0.01) {
97  return 0;
98  } else if (predSpeed == 0 && gap <= ACCEL2SPEED(myDecel)) {
99  // workaround for #2310
100  return MIN2(ACCEL2SPEED(myDecel), DIST2SPEED(gap));
101  }
102  double vsafe = (double)(-1. * myTauDecel
103  + sqrt(
105  + (predSpeed * predSpeed)
106  + (2. * myDecel * gap)
107  ));
108  assert(vsafe >= 0);
109  return vsafe;
110 }
111 
112 
113 MSCFModel*
115  return new MSCFModel_KraussOrig1(vtype);
116 }
117 
118 
119 /****************************************************************************/
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:51
#define DIST2SPEED(x)
Definition: SUMOTime.h:47
@ SUMO_ATTR_SIGMA
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:30
T MIN2(T a, T b)
Definition: StdDefs.h:76
T MAX2(T a, T b)
Definition: StdDefs.h:82
SumoRNG * getRNG() const
virtual double vsafe(double gap, double predSpeed, double predMaxDecel) const
Returns the "safe" velocity.
virtual double dawdle(double speed, SumoRNG *rng) const
Applies driver imperfection (dawdling / sigma)
double myDawdle
The vehicle's dawdle-parameter. 0 for no dawdling, 1 for max.
double myTauDecel
The precomputed value for myDecel*myTau.
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed (no dawdling)
virtual double stopSpeed(const MSVehicle *const veh, const double speed, double gap2pred, double decel, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
MSCFModel_KraussOrig1(const MSVehicleType *vtype)
Constructor.
virtual 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
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:292
virtual double minNextSpeed(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed given the current speed (depends on the numerical update scheme and its ste...
Definition: MSCFModel.cpp:298
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:922
CalcReason
What the return value of stop/follow/free-Speed is used for.
Definition: MSCFModel.h:77
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition: MSCFModel.h:701
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition: MSCFModel.h:698
double maximumSafeStopSpeedBallistic(double gap, double decel, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap when using the ballistic positional update.
Definition: MSCFModel.cpp:855
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:53
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
The car-following model and parameter.
Definition: MSVehicleType.h:63
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Definition: RandHelper.cpp:94
Structure representing possible vehicle parameter.