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-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 // The original Krauss (1998) car-following model and parameter
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 "MSCFModel_KraussOrig1.h"
39 #include <microsim/MSGlobals.h>
40 
41 //#define DEBUG_MOVE_HELPER
42 #define DEBUG_COND (veh->getID()=="disabled")
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 MSCFModel_KraussOrig1::MSCFModel_KraussOrig1(const MSVehicleType* vtype, double accel, double decel,
48  double emergencyDecel, double apparentDecel,
49  double dawdle, double headwayTime) :
50  MSCFModel(vtype, accel, decel, emergencyDecel, apparentDecel, headwayTime), myDawdle(dawdle),
51  myTauDecel(decel * headwayTime) {}
52 
53 
55 
56 
57 double
58 MSCFModel_KraussOrig1::moveHelper(MSVehicle* const veh, double vPos) const {
59  const double oldV = veh->getSpeed(); // save old v for optional acceleration computation
60  const double vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
61  const double vMin = minNextSpeed(oldV, veh);
62  // do not exceed max decel even if it is unsafe
63  double vMax = MAX2(vMin,
64  MIN3(veh->getLane()->getVehicleMaxSpeed(veh), maxNextSpeed(oldV, veh), vSafe));
65 #ifdef _DEBUG
66  //if (vMin > vMax) {
67  // WRITE_WARNING("Maximum speed of vehicle '" + veh->getID() + "' is lower than the minimum speed (min: " + toString(vMin) + ", max: " + toString(vMax) + ").");
68  //}
69 #endif
70 
71  const double vDawdle = MAX2(vMin, dawdle(vMax));
72 
73  double vNext = veh->getLaneChangeModel().patchSpeed(vMin, vDawdle, vMax, *this);
74 
75 #ifdef DEBUG_MOVE_HELPER
76  if DEBUG_COND {
77  std::cout << "\nMOVE_HELPER\n"
78  << "veh '" << veh->getID() << "' vMin=" << vMin
79  << " vMax=" << vMax << " vDawdle=" << vDawdle
80  << " vSafe" << vSafe << " vNext=" << vNext << " vPos=" << vPos << " veh->getSpeed()=" << oldV
81  << "\n";
82  }
83 #endif
84 
85  // (Leo) At this point vNext may also be negative indicating a stop within next step.
86  // This would have resulted from a call to maximumSafeStopSpeed(), which does not
87  // consider deceleration bounds. Therefore, we cap vNext here.
89 // vNext = MAX2(vNext, veh->getSpeed() - ACCEL2SPEED(getMaxDecel()));
90  vNext = MAX2(vNext, minNextSpeed(veh->getSpeed(), veh));
91  }
92 
93  return vNext;
94 }
95 
96 
97 double
98 MSCFModel_KraussOrig1::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double predMaxDecel) const {
100  return MIN2(vsafe(gap, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)); // XXX: and why not cap with minNextSpeed!? (Leo)
101  } else {
102  return MAX2(MIN2(maximumSafeFollowSpeed(gap, speed, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)), minNextSpeed(speed));
103  }
104 }
105 
106 
107 double
108 MSCFModel_KraussOrig1::insertionFollowSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const {
110  return followSpeed(veh, speed, gap2pred, predSpeed, predMaxDecel);
111  } else {
112  // ballistic update
113  return maximumSafeFollowSpeed(gap2pred, 0., predSpeed, predMaxDecel, true);
114  }
115 }
116 
117 
118 double
119 MSCFModel_KraussOrig1::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
121  return MIN2(vsafe(gap, 0., 0.), maxNextSpeed(speed, veh));
122  } else {
123  // XXX: using this here is probably in the spirit of Krauss, but we should consider,
124  // if the original vsafe should be kept instead (Leo), refs. #2575
125  return MIN2(maximumSafeStopSpeedBallistic(gap, speed), maxNextSpeed(speed, veh));
126  }
127 }
128 
129 
130 double
131 MSCFModel_KraussOrig1::dawdle(double speed) 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  return MAX2(0., speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand()));
141 }
142 
143 
145 double MSCFModel_KraussOrig1::vsafe(double gap, double predSpeed, double /* predMaxDecel */) const {
146  if (predSpeed == 0 && gap < 0.01) {
147  return 0;
148  } else if (predSpeed == 0 && gap <= ACCEL2SPEED(myDecel)) {
149  // workaround for #2310
150  return MIN2(ACCEL2SPEED(myDecel), DIST2SPEED(gap));
151  }
152  double vsafe = (double)(-1. * myTauDecel
153  + sqrt(
155  + (predSpeed * predSpeed)
156  + (2. * myDecel * gap)
157  ));
158  assert(vsafe >= 0);
159  return vsafe;
160 }
161 
162 
163 MSCFModel*
166 }
167 
168 
169 /****************************************************************************/
#define DIST2SPEED(x)
Definition: SUMOTime.h:56
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 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
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
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
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 followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle&#39;s safe speed (no dawdling)
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
MSCFModel_KraussOrig1(const MSVehicleType *vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double dawdle, double headwayTime)
Constructor.
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:537
virtual double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
double insertionFollowSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle&#39;s safe speed (no dawdling) This method is used during the insertion stage...
virtual double vsafe(double gap, double predSpeed, double predMaxDecel) const
Returns the "safe" velocity.
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1376
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:703
virtual 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) ...
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
T MIN3(T a, T b, T c)
Definition: StdDefs.h:80
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
double myTauDecel
The precomputed value for myDecel*myTau.
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.
virtual double dawdle(double speed) const
Applies driver imperfection (dawdling / sigma)