Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSCFModel_Daniel1.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/****************************************************************************/
20// The original Krauss (1998) car-following model and parameter
21/****************************************************************************/
22#include <config.h>
23
24#include <microsim/MSVehicle.h>
25#include <microsim/MSLane.h>
26#include "MSCFModel_Daniel1.h"
29
30
31// ===========================================================================
32// method definitions
33// ===========================================================================
35 MSCFModel(vtype),
36 myDawdle(vtype->getParameter().getCFParam(SUMO_ATTR_SIGMA, SUMOVTypeParameter::getDefaultImperfection(vtype->getParameter().vehicleClass))),
37 myTauDecel(myDecel * myHeadwayTime),
38 myTmp1(vtype->getParameter().getCFParam(SUMO_ATTR_TMP1, 1.0)),
39 myTmp2(vtype->getParameter().getCFParam(SUMO_ATTR_TMP2, 1.0)),
40 myTmp3(vtype->getParameter().getCFParam(SUMO_ATTR_TMP3, 1.0)),
41 myTmp4(vtype->getParameter().getCFParam(SUMO_ATTR_TMP4, 1.0)),
42 myTmp5(vtype->getParameter().getCFParam(SUMO_ATTR_TMP5, 1.0)) {
43}
44
45
47
48
49double
50MSCFModel_Daniel1::finalizeSpeed(MSVehicle* const veh, double vPos) const {
51 const double oldV = veh->getSpeed(); // save old v for optional acceleration computation
52 const double vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
53 // we need the acceleration for emission computation;
54 // in this case, we neglect dawdling, nonetheless, using
55 // vSafe does not incorporate speed reduction due to interaction
56 // on lane changing
57 const double vMin = getSpeedAfterMaxDecel(oldV);
58 const double vMax = MIN3(veh->getLane()->getVehicleMaxSpeed(veh), maxNextSpeed(oldV, veh), vSafe);
59#ifdef _DEBUG
60 if (vMin > vMax) {
61 WRITE_WARNINGF(TL("Maximum speed of vehicle '%' is lower than the minimum speed (min: %, max: %)."), veh->getID(), toString(vMin), toString(vMax));
62 }
63#endif
64 return veh->getLaneChangeModel().patchSpeed(vMin, MAX2(vMin, dawdle(vMax, veh->getRNG())), vMax, *this);
65}
66
67
68double
69MSCFModel_Daniel1::followSpeed(const MSVehicle* const veh, double speed, double gap, double predSpeed, double /*predMaxDecel*/, const MSVehicle* const /*pred*/, const CalcReason /*usage*/) const {
70 return MIN2(_vsafe(gap, predSpeed), maxNextSpeed(speed, veh));
71}
72
73
74double
75MSCFModel_Daniel1::stopSpeed(const MSVehicle* const veh, const double speed, double gap, double /*decel*/, const CalcReason /*usage*/) const {
76 return MIN2(_vsafe(gap, 0), maxNextSpeed(speed, veh));
77}
78
79
80double
81MSCFModel_Daniel1::dawdle(double speed, SumoRNG* rng) const {
82 return MAX2(0., speed - ACCEL2SPEED(myDawdle * myAccel * RandHelper::rand(rng)));
83}
84
85
87double MSCFModel_Daniel1::_vsafe(double gap, double predSpeed) const {
88 if (predSpeed == 0 && gap < 0.01) {
89 return 0;
90 }
91 double vsafe = (double)(-1. * myTauDecel
92 + sqrt(
94 + (predSpeed * predSpeed)
95 + (2. * myDecel * gap)
96 ));
97 assert(vsafe >= 0);
98 return vsafe;
99}
100
101
104 return new MSCFModel_Daniel1(vtype);
105}
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:296
#define TL(string)
Definition MsgHandler.h:315
#define ACCEL2SPEED(x)
Definition SUMOTime.h:51
@ SUMO_ATTR_TMP4
@ SUMO_ATTR_TMP3
@ SUMO_ATTR_TMP2
@ SUMO_ATTR_SIGMA
@ SUMO_ATTR_TMP1
@ SUMO_ATTR_TMP5
T MIN3(T a, T b, T c)
Definition StdDefs.h:89
T MIN2(T a, T b)
Definition StdDefs.h:76
T MAX2(T a, T b)
Definition StdDefs.h:82
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
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 ...
SumoRNG * getRNG() const
The original Krauss (1998) car-following model and parameter.
~MSCFModel_Daniel1()
Destructor.
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
double myDawdle
The vehicle's dawdle-parameter. 0 for no dawdling, 1 for max.
MSCFModel_Daniel1(const MSVehicleType *vtype)
Constructor.
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 myTauDecel
The precomputed value for myDecel*myTau.
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)
virtual double dawdle(double speed, SumoRNG *rng) const
Applies driver imperfection (dawdling / sigma)
virtual double _vsafe(double gap, double predSpeed) const
Returns the "safe" velocity.
double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
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.
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
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
Definition MSLane.h:574
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
MSAbstractLaneChangeModel & getLaneChangeModel()
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition MSVehicle.h:581
double getSpeed() const
Returns the vehicle's current speed.
Definition MSVehicle.h:490
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
The car-following model and parameter.
const std::string & getID() const
Returns the id.
Definition Named.h:74
static double rand(SumoRNG *rng=nullptr)
Returns a random real number in [0, 1)
Structure representing possible vehicle parameter.