Eclipse 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.dev/sumo
3 // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
22 // Krauss car-following model, changing accel and speed by slope
23 /****************************************************************************/
24 #include <config.h>
25 
27 #include <microsim/MSVehicle.h>
28 #include <microsim/MSNet.h>
29 #include "MSCFModel_KraussX.h"
30 
31 
32 #define OVERBRAKING_THRESHOLD -3
33 
34 // ===========================================================================
35 // method definitions
36 // ===========================================================================
38  MSCFModel_Krauss(vtype),
39  myTmp1(vtype->getParameter().getCFParam(SUMO_ATTR_TMP1, 0.0)),
40  myTmp2(vtype->getParameter().getCFParam(SUMO_ATTR_TMP2, 0.0)) {
41 }
42 
43 
45 
46 
47 MSCFModel*
49  return new MSCFModel_KraussX(vtype);
50 }
51 
52 
53 double
54 MSCFModel_KraussX::patchSpeedBeforeLC(const MSVehicle* veh, double vMin, double vMax) const {
55  return dawdleX(veh->getSpeed(), vMin, vMax, veh->getRNG());
56 }
57 
58 
59 double
60 MSCFModel_KraussX::dawdleX(double vOld, double vMin, double vMax, SumoRNG* rng) const {
61  double speed = vMax;
63  // in case of the ballistic update, negative speeds indicate
64  // a desired stop before the completion of the next timestep.
65  // We do not allow dawdling to overwrite this indication
66  if (speed < 0) {
67  return speed;
68  }
69  }
70  // extra slow to start
71  if (vOld < myAccel) {
72  speed -= ACCEL2SPEED(myTmp1 * myAccel);
73  }
74  const double random = RandHelper::rand(rng);
75  speed -= ACCEL2SPEED(myDawdle * myAccel * random);
76  // overbraking
77  if (vOld > vMax) {
78  speed -= ACCEL2SPEED(myTmp2 * myAccel * random);
79  //std::cout << " vMin=" << vMin << " vMax=" << vMax << "speed=" << speed << " d1=" << ACCEL2SPEED(myDawdle * myAccel * random) << " d2=" << ACCEL2SPEED(myTmp2 * myAccel * random) << " unexpectedDecel=" << (speed < vMin) << "\n";
81  speed = MAX2(0.0, speed);
82  }
83  }
84  speed = MAX2(vMin, speed);
85  return speed;
86 }
87 
88 
89 /****************************************************************************/
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:51
@ SUMO_ATTR_TMP2
@ SUMO_ATTR_TMP1
T MAX2(T a, T b)
Definition: StdDefs.h:82
SumoRNG * getRNG() const
Krauss car-following model, with acceleration decrease and faster start.
double myDawdle
The vehicle's dawdle-parameter. 0 for no dawdling, 1 for max.
MSCFModel_KraussX(const MSVehicleType *vtype)
Constructor.
double myTmp1
extension parameter nr1
~MSCFModel_KraussX()
Destructor.
MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
double dawdleX(double vOld, double vMin, double vMax, SumoRNG *rng) const
Applies driver imperfection (dawdling / sigma)
double patchSpeedBeforeLC(const MSVehicle *veh, double vMin, double vMax) const
apply custom speed adaptations within the given speed bounds
The car-following model abstraction.
Definition: MSCFModel.h:55
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition: MSCFModel.h:698
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:53
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:493
The car-following model and parameter.
Definition: MSVehicleType.h:63
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Definition: RandHelper.cpp:94