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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // Krauss car-following model, with acceleration decrease and faster start
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <microsim/MSVehicle.h>
35 #include <microsim/MSLane.h>
36 #include <microsim/MSGlobals.h>
37 #include "MSCFModel_Krauss.h"
40 
41 
42 
43 // ===========================================================================
44 // DEBUG constants
45 // ===========================================================================
46 //#define DEBUG_MOVE_HELPER
47 //#define DEBUG_COND (true)
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
53 MSCFModel_Krauss::MSCFModel_Krauss(const MSVehicleType* vtype, double accel, double decel,
54  double emergencyDecel, double apparentDecel,
55  double dawdle, double headwayTime) :
56  MSCFModel_KraussOrig1(vtype, accel, decel, emergencyDecel, apparentDecel, dawdle, headwayTime) {
57 }
58 
59 
61 
62 
63 double
64 MSCFModel_Krauss::moveHelper(MSVehicle* const veh, double vPos) const {
65  const double oldV = veh->getSpeed(); // save old v for optional acceleration computation
66  const double vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
67  const double vMin = minNextSpeed(oldV, veh);
68 
69  // aMax: Maximal admissible acceleration until the next action step, such that the vehicle's maximal
70  // desired speed on the current lane will not be exceeded.
71  double aMax = (veh->getLane()->getVehicleMaxSpeed(veh) - oldV) / veh->getActionStepLengthSecs();
72 
73  // do not exceed max decel even if it is unsafe
74  double vMax = MAX2(vMin, MIN3(oldV + ACCEL2SPEED(aMax), maxNextSpeed(oldV, veh), vSafe));
75 #ifdef _DEBUG
76  //if (vMin > vMax) {
77  // WRITE_WARNING("Maximum speed of vehicle '" + veh->getID() + "' is lower than the minimum speed (min: " + toString(vMin) + ", max: " + toString(vMax) + ").");
78  //}
79 #endif
80 
81  const double sigma = (veh->passingMinor()
83  : myDawdle);
84  const double vDawdle = MAX2(vMin, dawdle2(vMax, sigma));
85 
86  double vNext = veh->getLaneChangeModel().patchSpeed(vMin, vDawdle, vMax, *this);
87 
88  assert(vNext >= vMin);
89  assert(vNext <= vMax);
90 
91 #ifdef DEBUG_MOVE_HELPER
92  if DEBUG_COND {
93  std::cout << "\nMOVE_HELPER\n"
94  << "veh '" << veh->getID() << "' vMin=" << vMin
95  << " vMax=" << vMax << " vDawdle=" << vDawdle
96  << " vSafe" << vSafe << " vNext=" << vNext << " vPos=" << vPos << " veh->getSpeed()=" << oldV
97  << "\n";
98  }
99 #endif
100 
101  return vNext;
102 }
103 
104 
105 
106 double
107 MSCFModel_Krauss::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
108  // NOTE: This allows return of smaller values than minNextSpeed().
109  // Only relevant for the ballistic update: We give the argument headway=veh->getActionStepLengthSecs(), to assure that
110  // the stopping position is approached with a uniform deceleration also for tau!=veh->getActionStepLengthSecs().
111  return MIN2(maximumSafeStopSpeed(gap, speed, false, veh->getActionStepLengthSecs()), maxNextSpeed(speed, veh));
112 }
113 
114 
115 double
116 MSCFModel_Krauss::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double predMaxDecel) const {
117  const double vsafe = maximumSafeFollowSpeed(gap, speed, predSpeed, predMaxDecel);
118  const double vmin = minNextSpeed(speed);
119  const double vmax = maxNextSpeed(speed, veh);
121  return MIN2(vsafe, vmax);
122  } else {
123  // ballistic
124  // XXX: the euler variant can break as strong as it wishes immediately! The ballistic cannot, refs. #2575.
125  return MAX2(MIN2(vsafe, vmax), vmin);
126  }
127 }
128 
129 
130 double
131 MSCFModel_Krauss::dawdle2(double speed, double sigma) const {
133  // in case of the ballistic update, negative speeds indicate
134  // a desired stop before the completion of the next timestep.
135  // We do not allow dawdling to overwrite this indication
136  if (speed < 0) {
137  return speed;
138  }
139  }
140  // generate random number out of [0,1)
141  const double random = RandHelper::rand();
142  // Dawdle.
143  if (speed < myAccel) {
144  // we should not prevent vehicles from driving just due to dawdling
145  // if someone is starting, he should definitely start
146  // (but what about slow-to-start?)!!!
147  speed -= ACCEL2SPEED(sigma * speed * random);
148  } else {
149  speed -= ACCEL2SPEED(sigma * myAccel * random);
150  }
151  return MAX2(0., speed);
152 }
153 
154 
155 MSCFModel*
158 }
159 
160 
161 /****************************************************************************/
double getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane&#39;s maximum speed, given a vehicle&#39;s speed limit adaptation.
Definition: MSLane.h:475
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:770
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
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.
double myApparentDecel
The vehicle&#39;s deceleration as expected by surrounding traffic [m/s^2].
Definition: MSCFModel.h:541
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:60
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:564
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:210
The car-following model abstraction.
Definition: MSCFModel.h:59
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle&#39;s safe speed (no dawdling) this uses the maximumSafeFollowSpeed.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:64
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:204
The original Krauss (1998) car-following model and parameter.
double myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:534
T MAX2(T a, T b)
Definition: StdDefs.h:73
~MSCFModel_Krauss()
Destructor.
double stopSpeed(const MSVehicle *const veh, const double speed, double gap2pred) const
Computes the vehicle&#39;s safe speed for approaching a non-moving obstacle (no dawdling) this uses the m...
The car-following model and parameter.
Definition: MSVehicleType.h:72
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:3674
virtual double patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)=0
Called to adapt the speed in order to allow a lane change. It uses information on LC-related desired ...
double getActionStepLengthSecs() const
Returns the vehicle&#39;s action step length in secs, i.e. the interval between two action points...
Definition: MSVehicle.h:516
virtual double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
double myDawdle
The vehicle&#39;s dawdle-parameter. 0 for no dawdling, 1 for max.
T MIN2(T a, T b)
Definition: StdDefs.h:67
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:662
const SUMOVTypeParameter & getParameter() const
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:537
virtual double vsafe(double gap, double predSpeed, double predMaxDecel) const
Returns the "safe" velocity.
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1376
double dawdle2(double speed, double sigma) const
Applies driver imperfection (dawdling / sigma)
double myEmergencyDecel
The vehicle&#39;s maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:539
#define DEBUG_COND
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:62
bool passingMinor() const
decide whether the vehicle is passing a minor link or has comitted to do so
Definition: MSVehicle.cpp:4916
T MIN3(T a, T b, T c)
Definition: StdDefs.h:80
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:544
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:482
const std::string & getID() const
Returns the name of the vehicle.
MSCFModel_Krauss(const MSVehicleType *vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double dawdle, double headwayTime)
Constructor.