SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2016 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 // ===========================================================================
49  SUMOReal dawdle, SUMOReal headwayTime)
50  : MSCFModel(vtype, accel, decel, headwayTime), myDawdle(dawdle), myTauDecel(decel * headwayTime) {}
51 
52 
54 
55 
58  const SUMOReal oldV = veh->getSpeed(); // save old v for optional acceleration computation
59  const SUMOReal vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
60  // we need the acceleration for emission computation;
61  // in this case, we neglect dawdling, nonetheless, using
62  // vSafe does not incorporate speed reduction due to interaction
63  // on lane changing
64  const SUMOReal vMin = minNextSpeed(oldV, veh);
65  // do not exceed max decel even if it is unsafe
66  SUMOReal vMax = MAX2(vMin,
67  MIN3(veh->getLane()->getVehicleMaxSpeed(veh), maxNextSpeed(oldV, veh), vSafe));
68 #ifdef _DEBUG
69  //if (vMin > vMax) {
70  // WRITE_WARNING("Maximum speed of vehicle '" + veh->getID() + "' is lower than the minimum speed (min: " + toString(vMin) + ", max: " + toString(vMax) + ").");
71  //}
72 #endif
73 
74  const SUMOReal vDawdle = MAX2(vMin, dawdle(vMax));
75 
76  SUMOReal vNext = veh->getLaneChangeModel().patchSpeed(vMin, vDawdle, vMax, *this);
77 
78 #ifdef DEBUG_EXECUTE_MOVE
79  if DEBUG_COND {
80  std::cout << "\nMOVE_HELPER\n"
81  << "veh '" << veh->getID() << "' vMin=" << vMin
82  << " vMax=" << vMax << " vDawdle=" << vDawdle
83  << " vSafe" << vSafe << " vNext=" << vNext
84  << "\n";
85  }
86 #endif
87 
88  // (Leo) At this point vNext may also be negative indicating a stop within next step.
89  // This would have resulted from a call to maximumSafeStopSpeed(), which does not
90  // consider deceleration bounds. Therefore, we cap vNext here.
92  vNext = MAX2(vNext, veh->getSpeed() - ACCEL2SPEED(getMaxDecel()));
93  }
94 
95  return vNext;
96 }
97 
98 
100 MSCFModel_KraussOrig1::followSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap, SUMOReal predSpeed, SUMOReal predMaxDecel) const {
102  return MIN2(vsafe(gap, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)); // XXX: and why not cap with minNextSpeed!? (Leo)
103  } else {
104  return MAX2(MIN2(maximumSafeFollowSpeed(gap, speed, predSpeed, predMaxDecel), maxNextSpeed(speed, veh)), minNextSpeed(speed));
105  }
106 }
107 
108 
109 SUMOReal
110 MSCFModel_KraussOrig1::insertionFollowSpeed(const MSVehicle* const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const {
112  return followSpeed(veh, speed, gap2pred, predSpeed, predMaxDecel);
113  } else {
114  // ballistic update
115  return maximumSafeFollowSpeed(gap2pred, 0., predSpeed, predMaxDecel, true);
116  }
117 }
118 
119 
120 SUMOReal
121 MSCFModel_KraussOrig1::stopSpeed(const MSVehicle* const veh, const SUMOReal speed, SUMOReal gap) const {
123  return MIN2(vsafe(gap, 0., 0.), maxNextSpeed(speed, veh));
124  } else {
125  // XXX: using this here is probably in the spirit of Krauss, but we should consider,
126  // if the original vsafe should be kept instead (Leo), refs. #2575
127  return MIN2(maximumSafeStopSpeedBallistic(gap, speed), maxNextSpeed(speed, veh));
128  }
129 }
130 
131 
132 SUMOReal
135  // in case of the ballistic update, negative speeds indicate
136  // a desired stop before the completion of the next timestep.
137  // We do not allow dawdling to overwrite this indication
138  if (speed < 0) {
139  return speed;
140  }
141  }
142  return MAX2(SUMOReal(0), speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand()));
143 }
144 
145 
147 SUMOReal MSCFModel_KraussOrig1::vsafe(SUMOReal gap, SUMOReal predSpeed, SUMOReal /* predMaxDecel */) const {
148  if (predSpeed == 0 && gap < 0.01) {
149  return 0;
150  } else if (predSpeed == 0 && gap <= ACCEL2SPEED(myDecel)) {
151  // workaround for #2310
152  return MIN2(ACCEL2SPEED(myDecel), DIST2SPEED(gap));
153  }
155  + sqrt(
157  + (predSpeed * predSpeed)
158  + (2. * myDecel * gap)
159  ));
160  assert(vsafe >= 0);
161  return vsafe;
162 }
163 
164 
165 MSCFModel*
168 }
169 
170 
171 /****************************************************************************/
#define DIST2SPEED(x)
Definition: SUMOTime.h:57
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
virtual SUMOReal maxNextSpeed(SUMOReal speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:190
The car-following model abstraction.
Definition: MSCFModel.h:60
virtual SUMOReal vsafe(SUMOReal gap, SUMOReal predSpeed, SUMOReal predMaxDecel) const
Returns the "safe" velocity.
SUMOReal insertionFollowSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const
Computes the vehicle's safe speed (no dawdling) This method is used during the insertion stage...
SUMOReal myAccel
The vehicle's maximum acceleration [m/s^2].
Definition: MSCFModel.h:466
static SUMOReal rand()
Returns a random real number in [0, 1)
Definition: RandHelper.h:62
T MAX2(T a, T b)
Definition: StdDefs.h:75
SUMOReal myHeadwayTime
The driver's desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:472
SUMOReal processNextStop(SUMOReal currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1027
SUMOReal myTauDecel
The precomputed value for myDecel*myTau.
SUMOReal minNextSpeed(SUMOReal 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:195
SUMOReal moveHelper(MSVehicle *const veh, SUMOReal vPos) const
Applies interaction with stops and lane changing model influences.
The car-following model and parameter.
Definition: MSVehicleType.h:74
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:2702
SUMOReal followSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const
Computes the vehicle's safe speed (no dawdling)
SUMOReal myDawdle
The vehicle's dawdle-parameter. 0 for no dawdling, 1 for max.
virtual SUMOReal dawdle(SUMOReal speed) const
Applies driver imperfection (dawdling / sigma)
T MIN2(T a, T b)
Definition: StdDefs.h:69
MSCFModel_KraussOrig1(const MSVehicleType *vtype, SUMOReal accel, SUMOReal decel, SUMOReal dawdle, SUMOReal headwayTime)
Constructor.
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
Definition: MSCFModel.h:201
SUMOReal maximumSafeFollowSpeed(SUMOReal gap, SUMOReal egoSpeed, SUMOReal predSpeed, SUMOReal predMaxDecel, bool onInsertion=false) const
Returns the maximum safe velocity for following the given leader.
Definition: MSCFModel.cpp:585
virtual SUMOReal stopSpeed(const MSVehicle *const veh, const SUMOReal speed, SUMOReal gap2pred) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling) ...
SUMOReal maximumSafeStopSpeedBallistic(SUMOReal gap, SUMOReal currentSpeed, bool onInsertion=false, SUMOReal headway=-1) const
Returns the maximum next velocity for stopping within gap when using the ballistic positional update...
Definition: MSCFModel.cpp:518
virtual SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max, const MSCFModel &cfModel)=0
Called to adapt the speed in order to allow a lane change.
SUMOReal getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:441
#define DEBUG_COND
#define SUMOReal
Definition: config.h:214
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:63
T MIN3(T a, T b, T c)
Definition: StdDefs.h:82
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
Definition: MSLane.h:458
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:487
SUMOReal myDecel
The vehicle's maximum deceleration [m/s^2].
Definition: MSCFModel.h:469
const std::string & getID() const
Returns the name of the vehicle.