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