SUMO - Simulation of Urban MObility
MSCFModel_KraussX.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, changing accel and speed by slope
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 
35 #include <microsim/MSVehicle.h>
36 #include <microsim/MSNet.h>
37 #include "MSCFModel_KraussX.h"
38 
39 
40 #define OVERBRAKING_THRESHOLD -3
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 MSCFModel_KraussX::MSCFModel_KraussX(const MSVehicleType* vtype, double accel, double decel,
46  double emergencyDecel, double apparentDecel,
47  double dawdle, double headwayTime,
48  double tmp1, double tmp2):
49  MSCFModel_Krauss(vtype, accel, decel, emergencyDecel, apparentDecel, dawdle, headwayTime),
50  myTmp1(tmp1),
51  myTmp2(tmp2) {
52 }
53 
54 
56 
57 
58 MSCFModel*
61 }
62 
63 
64 double
65 MSCFModel_KraussX::moveHelper(MSVehicle* const veh, double vPos) const {
66  const double oldV = veh->getSpeed(); // save old v for optional acceleration computation
67  const double vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
68  // we need the acceleration for emission computation;
69  // in this case, we neglect dawdling, nonetheless, using
70  // vSafe does not incorporate speed reduction due to interaction
71  // on lane changing
72  double vMin, vNext;
73  const double vMax = MIN3(veh->getMaxSpeedOnLane(), maxNextSpeed(oldV, veh), vSafe);
75  // we do not rely on never braking harder than maxDecel because TraCI or strange cf models may decide to do so
76  vMin = MIN2(getSpeedAfterMaxDecel(oldV), vMax);
77  const double vDawdle = dawdleX(oldV, vMin, vMax);
78  vNext = veh->getLaneChangeModel().patchSpeed(vMin, vDawdle, vMax, *this);
79  //std::cout << SIMTIME << " veh=" << veh->getID()
80  // << " vOld=" << oldV << " vPos=" << vPos << " vSafe=" << vSafe
81  // << " vMax=" << vMax << " vMin=" << vMin << " vDawdle=" << vDawdle << " vNext=" << vNext
82  // << "\n";
83  } else {
84  // for ballistic update, negative vnext must be allowed to
85  // indicate a stop within the coming timestep (i.e., to attain negative values)
86  vMin = MIN2(minNextSpeed(oldV, veh), vMax);
87  const double vDawdle = dawdleX(oldV, vMin, vMax);
88  vNext = veh->getLaneChangeModel().patchSpeed(vMin, vDawdle, vMax, *this);
89  // (Leo) moveHelper() is responsible for assuring that the next
90  // velocity is chosen in accordance with maximal decelerations.
91  // At this point vNext may also be negative indicating a stop within next step.
92  // Moreover, because maximumSafeStopSpeed() does not consider deceleration bounds
93  // vNext can be a large negative value at this point. We cap vNext here.
94  vNext = MAX2(vNext, vMin);
95  }
96  return vNext;
97 }
98 
99 
100 double
101 MSCFModel_KraussX::dawdleX(double vOld, double vMin, double vMax) const {
102  double speed = vMax;
104  // in case of the ballistic update, negative speeds indicate
105  // a desired stop before the completion of the next timestep.
106  // We do not allow dawdling to overwrite this indication
107  if (speed < 0) {
108  return speed;
109  }
110  }
111  // extra slow to start
112  if (vOld < myAccel) {
113  speed -= ACCEL2SPEED(myTmp1 * myAccel);
114  }
115  const double random = RandHelper::rand();
116  speed -= ACCEL2SPEED(myDawdle * myAccel * random);
117  speed = MAX2(vMin, speed);
118  // overbraking
119  if (vOld > vMax) {
120  speed -= ACCEL2SPEED(myTmp2 * myAccel * random);
121  //std::cout << " vMin=" << vMin << " vMax=" << vMax << "speed=" << speed << " d1=" << ACCEL2SPEED(myDawdle * myAccel * random) << " d2=" << ACCEL2SPEED(myTmp2 * myAccel * random) << " unexpectedDecel=" << (speed < vMin) << "\n";
123  speed = MAX2(0.0, speed);
124  }
125  }
126  return speed;
127 }
128 
129 
130 
131 /****************************************************************************/
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
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
double dawdleX(double vOld, double vMin, double vMax) const
Applies driver imperfection (dawdling / sigma)
double getMaxSpeedOnLane() const
Returns the maximal speed for the vehicle on its current lane (including speed factor and deviation...
Definition: MSVehicle.h:574
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 ...
~MSCFModel_KraussX()
Destructor.
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
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:318
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:537
MSCFModel_KraussX(const MSVehicleType *vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double dawdle, double headwayTime, double tmp1, double tmp2)
Constructor.
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1376
double myEmergencyDecel
The vehicle&#39;s maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:539
double myTmp1
extension parameter nr1
double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:62
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
Krauss car-following model, with acceleration decrease and faster start.
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.