Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSCFModel_SmartSK.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2012-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/****************************************************************************/
21// A smarter SK
22/****************************************************************************/
23#include <config.h>
24
25#include <map>
26#include <microsim/MSVehicle.h>
27#include <microsim/MSLane.h>
28#include "MSCFModel_SmartSK.h"
31
32//#define SmartSK_DEBUG
33
34// ===========================================================================
35// method definitions
36// ===========================================================================
38// check whether setting these variables here with default values is ''good'' SUMO design
39// double tmp1=0.0, double tmp2=5.0, double tmp3=0.0, double tmp4, double tmp5)
40 MSCFModel(vtype),
41 myDawdle(vtype->getParameter().getCFParam(SUMO_ATTR_SIGMA, SUMOVTypeParameter::getDefaultImperfection(vtype->getParameter().vehicleClass))),
42 myTauDecel(myDecel * myHeadwayTime),
43 myTmp1(vtype->getParameter().getCFParam(SUMO_ATTR_TMP1, 1.0)),
44 myTmp2(vtype->getParameter().getCFParam(SUMO_ATTR_TMP2, 1.0)),
45 myTmp3(vtype->getParameter().getCFParam(SUMO_ATTR_TMP3, 1.0)),
46 myTmp4(vtype->getParameter().getCFParam(SUMO_ATTR_TMP4, 1.0)),
47 myTmp5(vtype->getParameter().getCFParam(SUMO_ATTR_TMP5, 1.0)) {
48 // the variable tmp1 is the acceleration delay time, e.g. two seconds (or something like this).
49 // for use in the upate process, a rule like if (v<myTmp1) vsafe = 0; is needed.
50 // To have this, we have to transform myTmp1 (which is a time) into an equivalent speed. This is done by the
51 // using the vsafe formula and computing:
52 // v(t=myTmp1) = -myTauDecel + sqrt(myTauDecel*myTauDecel + accel*(accel + decel)*t*t + accel*decel*t*TS);
53 double t = myTmp1;
54 myS2Sspeed = -myTauDecel + sqrt(myTauDecel * myTauDecel + myAccel * (myAccel + myDecel) * t * t + myAccel * myDecel * t * TS);
55#ifdef SmartSK_DEBUG
56 std::cout << "# s2s-speed: " << myS2Sspeed << std::endl;
57#endif
58 if (myS2Sspeed > 5.0) {
59 myS2Sspeed = 5.0;
60 }
61// double maxDeltaGap = -0.5*ACCEL2DIST(myDecel + myAccel);
62 maxDeltaGap = -0.5 * (myDecel + myAccel) * TS * TS;
63#ifdef SmartSK_DEBUG
64 std::cout << "# maxDeltaGap = " << maxDeltaGap << std::endl;
65#endif
66 myTmp2 = TS / myTmp2;
67 myTmp3 = sqrt(TS) * myTmp3;
68}
69
70
72
73
74double
75MSCFModel_SmartSK::finalizeSpeed(MSVehicle* const veh, double vPos) const {
76 const double vNext = MSCFModel::finalizeSpeed(veh, vPos);
77 updateMyHeadway(veh);
79#ifdef SmartSK_DEBUG
80 if (vars->ggOld.size() > 1) {
81 std::cout << "# more than one entry in ggOld list. Speed is " << vPos << ", corresponding dist is " << vars->ggOld[(int) vPos] << "\n";
82 for (std::map<int, double>::iterator I = vars->ggOld.begin(); I != vars->ggOld.end(); I++) {
83 std::cout << "# " << (*I).first << ' ' << (*I).second << std::endl;
84 }
85 }
86#endif
87 vars->gOld = vars->ggOld[(int) vPos];
88 vars->ggOld.clear();
89 return vNext;
90}
91
92double
93MSCFModel_SmartSK::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double /*predMaxDecel*/, const MSVehicle* const /*pred*/, const CalcReason /*usage*/) const {
95
96// if (((gap - vars->gOld) < maxDeltaGap) && (speed>=5.0) && gap>=5.0) {
97 if ((gap - vars->gOld) < maxDeltaGap) {
98 double tTauTest = gap / speed;
99// allow headway only to decrease only, never to increase. Increase is handled automatically by the headway dynamics in finalizeSpeed()!!!
100 if ((tTauTest < vars->myHeadway) && (tTauTest > TS)) {
101 vars->myHeadway = tTauTest;
102 }
103 }
104
105 double vsafe = _vsafe(veh, gap, predSpeed);
106 if ((speed <= 0.0) && (vsafe < myS2Sspeed)) {
107 vsafe = 0;
108 }
109
110 double vNew = MAX2(getSpeedAfterMaxDecel(speed), MIN2(vsafe, maxNextSpeed(speed, veh)));
111 // there must be a better place to do the following assignment!!!
112 vars->gOld = gap;
113 vars->ggOld[(int)vNew] = gap;
114 return vNew;
115}
116
117double
118MSCFModel_SmartSK::stopSpeed(const MSVehicle* const veh, const double speed, double gap, double /*decel*/, const CalcReason /*usage*/) const {
120
121// if (((gap - vars->gOld) < maxDeltaGap) && (speed>=5.0) && gap>=5.0) {
122 if ((gap - vars->gOld) < maxDeltaGap) {
123 double tTauTest = gap / speed;
124// allow headway only to decrease only, never to increase. Increase is handled automatically by the headway dynamics in finalizeSpeed()!!!
125 if ((tTauTest < vars->myHeadway) && (tTauTest > TS)) {
126 vars->myHeadway = tTauTest;
127 }
128 }
129
130 return MAX2(getSpeedAfterMaxDecel(speed), MIN2(_vsafe(veh, gap, 0), maxNextSpeed(speed, veh)));
131}
132
133double
134MSCFModel_SmartSK::patchSpeedBeforeLC(const MSVehicle* veh, double /*vMin*/, double /*vMax*/) const {
135 return dawdle(veh->getSpeed(), veh->getRNG());
136}
137
138double
139MSCFModel_SmartSK::dawdle(double speed, SumoRNG* rng) const {
140 return MAX2(0., speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand(rng)));
141}
142
143
145double MSCFModel_SmartSK::_vsafe(const MSVehicle* const veh, double gap, double predSpeed) const {
146 if (predSpeed == 0 && gap < 0.01) {
147 return 0;
148 }
150 // this is the most obvious change to the normal SK: the model uses the variable vars->myHeadway instead of the constant
151 // myHeadwayTime as the "desired headway" tau
152 double bTau = myDecel * (vars->myHeadway);
153 double vsafe = (double)(-1. * bTau
154 + sqrt(
155 bTau * bTau
156 + (predSpeed * predSpeed)
157 + (2. * myDecel * gap)
158 ));
159 assert(vsafe >= 0);
160 return vsafe;
161}
162
163
166 return new MSCFModel_SmartSK(vtype);
167}
#define ACCEL2SPEED(x)
Definition SUMOTime.h:51
#define TS
Definition SUMOTime.h:42
@ SUMO_ATTR_TMP4
@ SUMO_ATTR_TMP3
@ SUMO_ATTR_TMP2
@ SUMO_ATTR_SIGMA
@ SUMO_ATTR_TMP1
@ SUMO_ATTR_TMP5
T MIN2(T a, T b)
Definition StdDefs.h:76
T MAX2(T a, T b)
Definition StdDefs.h:82
SumoRNG * getRNG() const
The original Krauss (1998) car-following model and parameter.
double patchSpeedBeforeLC(const MSVehicle *veh, double vMin, double vMax) const
apply dawdling
double myTauDecel
The precomputed value for myDecel*myTau.
double myDawdle
The vehicle's dawdle-parameter. 0 for no dawdling, 1 for max.
virtual double _vsafe(const MSVehicle *const veh, double gap, double predSpeed) const
Returns the "safe" velocity.
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
virtual double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed (no dawdling)
double myS2Sspeed
new variables needed in this model; myS2Sspeed is the speed below which the vehicle does not move whe...
double myTmp1
temporary (testing) parameter
virtual void updateMyHeadway(const MSVehicle *const veh) const
~MSCFModel_SmartSK()
Destructor.
MSCFModel_SmartSK(const MSVehicleType *vtype)
Constructor.
virtual double dawdle(double speed, SumoRNG *rng) const
Applies driver imperfection (dawdling / sigma)
double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
virtual double stopSpeed(const MSVehicle *const veh, const double speed, double gap2pred, double decel, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
The car-following model abstraction.
Definition MSCFModel.h:55
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
virtual double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences. Called at most once per simulation...
CalcReason
What the return value of stop/follow/free-Speed is used for.
Definition MSCFModel.h:77
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition MSCFModel.h:701
double myAccel
The vehicle's maximum acceleration [m/s^2].
Definition MSCFModel.h:698
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition MSCFModel.h:403
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
double getSpeed() const
Returns the vehicle's current speed.
Definition MSVehicle.h:490
MSCFModel::VehicleVariables * getCarFollowVariables() const
Returns the vehicle's car following model variables.
Definition MSVehicle.h:986
The car-following model and parameter.
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Structure representing possible vehicle parameter.