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.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 // The original Krauss (1998) car-following model and parameter
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 "MSCFModel_KraussOrig1.h"
32 #include <microsim/MSGlobals.h>
33 
34 // ===========================================================================
35 // DEBUG constants
36 // ===========================================================================
37 //#define DEBUG_COND (veh->getID()=="disabled")
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
43  MSCFModel(vtype),
44  myDawdle(vtype->getParameter().getCFParam(SUMO_ATTR_SIGMA, SUMOVTypeParameter::getDefaultImperfection(vtype->getParameter().vehicleClass))),
45  myTauDecel(myDecel * myHeadwayTime) {
46 }
47 
48 
50 
51 double
52 MSCFModel_KraussOrig1::patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
53  UNUSED_PARAMETER(veh);
54  const double vDawdle = MAX2(vMin, dawdle(vMax, veh->getRNG()));
55  return vDawdle;
56 }
57 
58 
59 double
60 MSCFModel_KraussOrig1::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double predMaxDecel, const MSVehicle* const /*pred*/) const {
62  return MIN2(vsafe(gap, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)); // XXX: and why not cap with minNextSpeed!? (Leo)
63  } else {
64  return MAX2(MIN2(maximumSafeFollowSpeed(gap, speed, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)), minNextSpeed(speed));
65  }
66 }
67 
68 
69 double
70 MSCFModel_KraussOrig1::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
72  return MIN2(vsafe(gap, 0., 0.), maxNextSpeed(speed, veh));
73  } else {
74  // XXX: using this here is probably in the spirit of Krauss, but we should consider,
75  // if the original vsafe should be kept instead (Leo), refs. #2575
76  return MIN2(maximumSafeStopSpeedBallistic(gap, speed), maxNextSpeed(speed, veh));
77  }
78 }
79 
80 
81 double
82 MSCFModel_KraussOrig1::dawdle(double speed, std::mt19937* rng) const {
84  // in case of the ballistic update, negative speeds indicate
85  // a desired stop before the completion of the next timestep.
86  // We do not allow dawdling to overwrite this indication
87  if (speed < 0) {
88  return speed;
89  }
90  }
91  return MAX2(0., speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand(rng)));
92 }
93 
94 
96 double MSCFModel_KraussOrig1::vsafe(double gap, double predSpeed, double /* predMaxDecel */) const {
97  if (predSpeed == 0 && gap < 0.01) {
98  return 0;
99  } else if (predSpeed == 0 && gap <= ACCEL2SPEED(myDecel)) {
100  // workaround for #2310
101  return MIN2(ACCEL2SPEED(myDecel), DIST2SPEED(gap));
102  }
103  double vsafe = (double)(-1. * myTauDecel
104  + sqrt(
106  + (predSpeed * predSpeed)
107  + (2. * myDecel * gap)
108  ));
109  assert(vsafe >= 0);
110  return vsafe;
111 }
112 
113 
114 MSCFModel*
116  return new MSCFModel_KraussOrig1(vtype);
117 }
118 
119 
120 /****************************************************************************/
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:65
MSCFModel_KraussOrig1::duplicate
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
Definition: MSCFModel_KraussOrig1.cpp:115
UNUSED_PARAMETER
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:31
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
DIST2SPEED
#define DIST2SPEED(x)
Definition: SUMOTime.h:48
MSCFModel::maxNextSpeed
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:238
MSCFModel_KraussOrig1::MSCFModel_KraussOrig1
MSCFModel_KraussOrig1(const MSVehicleType *vtype)
Constructor.
Definition: MSCFModel_KraussOrig1.cpp:42
MSCFModel::maximumSafeStopSpeedBallistic
double maximumSafeStopSpeedBallistic(double gap, 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:789
ACCEL2SPEED
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:52
MSCFModel_KraussOrig1.h
MSVehicle.h
MSCFModel_KraussOrig1::dawdle
virtual double dawdle(double speed, std::mt19937 *rng) const
Applies driver imperfection (dawdling / sigma)
Definition: MSCFModel_KraussOrig1.cpp:82
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
MSCFModel_KraussOrig1::patchSpeedBeforeLC
double patchSpeedBeforeLC(const MSVehicle *veh, double vMin, double vMax) const
apply custom speed adaptations within the given speed bounds
Definition: MSCFModel_KraussOrig1.cpp:52
MSCFModel_KraussOrig1::myTauDecel
double myTauDecel
The precomputed value for myDecel*myTau.
Definition: MSCFModel_KraussOrig1.h:151
SUMOVTypeParameter
Structure representing possible vehicle parameter.
Definition: SUMOVTypeParameter.h:86
MSCFModel_KraussOrig1::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)
Definition: MSCFModel_KraussOrig1.cpp:60
MSCFModel_KraussOrig1::~MSCFModel_KraussOrig1
~MSCFModel_KraussOrig1()
Destructor.
Definition: MSCFModel_KraussOrig1.cpp:49
MSCFModel_KraussOrig1::myDawdle
double myDawdle
The vehicle's dawdle-parameter. 0 for no dawdling, 1 for max.
Definition: MSCFModel_KraussOrig1.h:148
MSGlobals.h
MSCFModel_KraussOrig1::stopSpeed
virtual 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)
Definition: MSCFModel_KraussOrig1.cpp:70
MSCFModel::minNextSpeed
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:244
SUMO_ATTR_SIGMA
@ SUMO_ATTR_SIGMA
Definition: SUMOXMLDefinitions.h:548
MSCFModel::myDecel
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition: MSCFModel.h:620
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
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
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