SUMO - Simulation of Urban MObility
MSCFModel_KraussOrig1.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // The original Krauss (1998) car-following model and parameter
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <microsim/MSVehicle.h>
36 #include <microsim/MSLane.h>
37 #include "MSCFModel_KraussOrig1.h"
40 #include <microsim/MSGlobals.h>
41 
42 //#define DEBUG_EXECUTE_MOVE
43 #define DEBUG_COND (veh->getID()=="disabled")
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 MSCFModel_KraussOrig1::MSCFModel_KraussOrig1(const MSVehicleType* vtype, double accel, double decel,
49  double emergencyDecel, double apparentDecel,
50  double dawdle, double headwayTime) :
51  MSCFModel(vtype, accel, decel, emergencyDecel, apparentDecel, headwayTime), myDawdle(dawdle),
52  myTauDecel(decel * headwayTime) {}
53 
54 
56 
57 
58 double
59 MSCFModel_KraussOrig1::moveHelper(MSVehicle* const veh, double vPos) const {
60  const double oldV = veh->getSpeed(); // save old v for optional acceleration computation
61  const double vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
62  // we need the acceleration for emission computation;
63  // in this case, we neglect dawdling, nonetheless, using
64  // vSafe does not incorporate speed reduction due to interaction
65  // on lane changing
66  const double vMin = minNextSpeed(oldV, veh);
67  // do not exceed max decel even if it is unsafe
68  double vMax = MAX2(vMin,
69  MIN3(veh->getLane()->getVehicleMaxSpeed(veh), maxNextSpeed(oldV, veh), vSafe));
70 #ifdef _DEBUG
71  //if (vMin > vMax) {
72  // WRITE_WARNING("Maximum speed of vehicle '" + veh->getID() + "' is lower than the minimum speed (min: " + toString(vMin) + ", max: " + toString(vMax) + ").");
73  //}
74 #endif
75 
76  const double vDawdle = MAX2(vMin, dawdle(vMax));
77 
78  double vNext = veh->getLaneChangeModel().patchSpeed(vMin, vDawdle, vMax, *this);
79 
80 #ifdef DEBUG_EXECUTE_MOVE
81  if DEBUG_COND {
82  std::cout << "\nMOVE_HELPER\n"
83  << "veh '" << veh->getID() << "' vMin=" << vMin
84  << " vMax=" << vMax << " vDawdle=" << vDawdle
85  << " vSafe" << vSafe << " vNext=" << vNext
86  << "\n";
87  }
88 #endif
89 
90  // (Leo) At this point vNext may also be negative indicating a stop within next step.
91  // This would have resulted from a call to maximumSafeStopSpeed(), which does not
92  // consider deceleration bounds. Therefore, we cap vNext here.
94  vNext = MAX2(vNext, veh->getSpeed() - ACCEL2SPEED(getMaxDecel()));
95  }
96 
97  return vNext;
98 }
99 
100 
101 double
102 MSCFModel_KraussOrig1::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double predMaxDecel) const {
104  return MIN2(vsafe(gap, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)); // XXX: and why not cap with minNextSpeed!? (Leo)
105  } else {
106  return MAX2(MIN2(maximumSafeFollowSpeed(gap, speed, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)), minNextSpeed(speed));
107  }
108 }
109 
110 
111 double
112 MSCFModel_KraussOrig1::insertionFollowSpeed(const MSVehicle* const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const {
114  return followSpeed(veh, speed, gap2pred, predSpeed, predMaxDecel);
115  } else {
116  // ballistic update
117  return maximumSafeFollowSpeed(gap2pred, 0., predSpeed, predMaxDecel, true);
118  }
119 }
120 
121 
122 double
123 MSCFModel_KraussOrig1::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
125  return MIN2(vsafe(gap, 0., 0.), maxNextSpeed(speed, veh));
126  } else {
127  // XXX: using this here is probably in the spirit of Krauss, but we should consider,
128  // if the original vsafe should be kept instead (Leo), refs. #2575
129  return MIN2(maximumSafeStopSpeedBallistic(gap, speed), maxNextSpeed(speed, veh));
130  }
131 }
132 
133 
134 double
135 MSCFModel_KraussOrig1::dawdle(double speed) const {
137  // in case of the ballistic update, negative speeds indicate
138  // a desired stop before the completion of the next timestep.
139  // We do not allow dawdling to overwrite this indication
140  if (speed < 0) {
141  return speed;
142  }
143  }
144  return MAX2(0., speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand()));
145 }
146 
147 
149 double MSCFModel_KraussOrig1::vsafe(double gap, double predSpeed, double /* predMaxDecel */) const {
150  if (predSpeed == 0 && gap < 0.01) {
151  return 0;
152  } else if (predSpeed == 0 && gap <= ACCEL2SPEED(myDecel)) {
153  // workaround for #2310
154  return MIN2(ACCEL2SPEED(myDecel), DIST2SPEED(gap));
155  }
156  double vsafe = (double)(-1. * myTauDecel
157  + sqrt(
159  + (predSpeed * predSpeed)
160  + (2. * myDecel * gap)
161  ));
162  assert(vsafe >= 0);
163  return vsafe;
164 }
165 
166 
167 MSCFModel*
170 }
171 
172 
173 /****************************************************************************/
#define DIST2SPEED(x)
Definition: SUMOTime.h:57
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:462
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:590
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:473
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:488
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:198
The car-following model abstraction.
Definition: MSCFModel.h:60
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:193
double myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:466
T MAX2(T a, T b)
Definition: StdDefs.h:70
The car-following model and parameter.
Definition: MSVehicleType.h:74
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:2921
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.
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle&#39;s safe speed (no dawdling)
static double rand()
Returns a random real number in [0, 1)
Definition: RandHelper.h:62
double myDawdle
The vehicle&#39;s dawdle-parameter. 0 for no dawdling, 1 for max.
T MIN2(T a, T b)
Definition: StdDefs.h:64
MSCFModel_KraussOrig1(const MSVehicleType *vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double dawdle, double headwayTime)
Constructor.
double getMaxDecel() const
Get the vehicle type&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:201
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:469
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:1145
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:523
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:471
#define DEBUG_COND
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:63
T MIN3(T a, T b, T c)
Definition: StdDefs.h:77
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:476
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:442
const std::string & getID() const
Returns the name of the vehicle.
virtual double dawdle(double speed) const
Applies driver imperfection (dawdling / sigma)