SUMO - Simulation of Urban MObility
MSCFModel_Daniel1.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // The original Krauss (1998) car-following model and parameter
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2012-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <microsim/MSVehicle.h>
34 #include <microsim/MSLane.h>
35 #include "MSCFModel_Daniel1.h"
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
44  double decel, double emergencyDecel, double apparentDecel,
45  double dawdle, double headwayTime,
46  double tmp1, double tmp2, double tmp3, double tmp4, double tmp5) :
47  MSCFModel(vtype, accel, decel, emergencyDecel, apparentDecel, headwayTime),
48  myDawdle(dawdle), myTauDecel(decel * headwayTime),
49  myTmp1(tmp1), myTmp2(tmp2), myTmp3(tmp3), myTmp4(tmp4), myTmp5(tmp5) {
50 }
51 
52 
54 
55 
56 double
57 MSCFModel_Daniel1::moveHelper(MSVehicle* const veh, double vPos) const {
58  const double oldV = veh->getSpeed(); // save old v for optional acceleration computation
59  const double 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 double vMin = getSpeedAfterMaxDecel(oldV);
65  const double vMax = MIN3(veh->getLane()->getVehicleMaxSpeed(veh), maxNextSpeed(oldV, veh), vSafe);
66 #ifdef _DEBUG
67  if (vMin > vMax) {
68  WRITE_WARNING("Maximum speed of vehicle '" + veh->getID() + "' is lower than the minimum speed (min: " + toString(vMin) + ", max: " + toString(vMax) + ").");
69  }
70 #endif
71  return veh->getLaneChangeModel().patchSpeed(vMin, MAX2(vMin, dawdle(vMax)), vMax, *this);
72 }
73 
74 
75 double
76 MSCFModel_Daniel1::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double /*predMaxDecel*/) const {
77  return MIN2(_vsafe(gap, predSpeed), maxNextSpeed(speed, veh));
78 }
79 
80 
81 double
82 MSCFModel_Daniel1::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
83  return MIN2(_vsafe(gap, 0), maxNextSpeed(speed, veh));
84 }
85 
86 
87 double
88 MSCFModel_Daniel1::dawdle(double speed) const {
89  return MAX2(0., speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand()));
90 }
91 
92 
94 double MSCFModel_Daniel1::_vsafe(double gap, double predSpeed) const {
95  if (predSpeed == 0 && gap < 0.01) {
96  return 0;
97  }
98  double vsafe = (double)(-1. * myTauDecel
99  + sqrt(
101  + (predSpeed * predSpeed)
102  + (2. * myDecel * gap)
103  ));
104  assert(vsafe >= 0);
105  return vsafe;
106 }
107 
108 
109 MSCFModel*
113 }
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 myTmp1
temporary (testing) parameter
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
double myTauDecel
The precomputed value for myDecel*myTau.
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel.h:331
double myApparentDecel
The vehicle&#39;s deceleration as expected by surrounding traffic [m/s^2].
Definition: MSCFModel.h:531
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
The car-following model abstraction.
Definition: MSCFModel.h:60
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:65
double myAccel
The vehicle&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:524
T MAX2(T a, T b)
Definition: StdDefs.h:74
virtual double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle&#39;s safe speed (no dawdling)
double myDawdle
The vehicle&#39;s dawdle-parameter. 0 for no dawdling, 1 for max.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
The car-following model and parameter.
Definition: MSVehicleType.h:73
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:3144
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.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
T MIN2(T a, T b)
Definition: StdDefs.h:68
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:527
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1284
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel.cpp:200
virtual double _vsafe(double gap, double predSpeed) const
Returns the "safe" velocity.
double myEmergencyDecel
The vehicle&#39;s maximum emergency deceleration [m/s^2].
Definition: MSCFModel.h:529
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
T MIN3(T a, T b, T c)
Definition: StdDefs.h:81
double myHeadwayTime
The driver&#39;s desired time headway (aka reaction time tau) [s].
Definition: MSCFModel.h:534
virtual double dawdle(double speed) const
Applies driver imperfection (dawdling / sigma)
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:499
MSCFModel_Daniel1(const MSVehicleType *vtype, double accel, double decel, double emergencyDecel, double apparentDecel, double dawdle, double headwayTime, double tmp1, double tmp2, double tmp3, double tmp4, double tmp5)
Constructor.
~MSCFModel_Daniel1()
Destructor.
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
const std::string & getID() const
Returns the name of the vehicle.
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:443