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