Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSCFModel_Rail.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-2025 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/****************************************************************************/
19// <description missing>
20/****************************************************************************/
21#include <config.h>
22
23#include <iostream>
28#include <microsim/MSVehicle.h>
30#include "MSCFModel_Rail.h"
31
32// ===========================================================================
33// trainParams method definitions
34// ===========================================================================
35
36double
39 return (resCoef_quadratic * speed * speed + resCoef_linear * speed + resCoef_constant); // kN
40 } else {
42 }
43}
44
45
46double
48 if (maxPower != INVALID_DOUBLE) {
49 return MIN2(maxPower / speed, maxTraction); // kN
50 } else {
51 return LinearApproxHelpers::getInterpolatedValue(traction, speed); // kN
52 }
53}
54
55// ===========================================================================
56// method definitions
57// ===========================================================================
58
59
61 MSCFModel(vtype) {
62 const std::string trainType = vtype->getParameter().getCFParamString(SUMO_ATTR_TRAIN_TYPE, "NGT400");
63 if (trainType.compare("RB425") == 0) {
65 } else if (trainType.compare("RB628") == 0) {
67 } else if (trainType.compare("NGT400") == 0) {
69 } else if (trainType.compare("NGT400_16") == 0) {
71 } else if (trainType.compare("ICE1") == 0) {
73 } else if (trainType.compare("REDosto7") == 0) {
75 } else if (trainType.compare("Freight") == 0) {
77 } else if (trainType.compare("ICE3") == 0) {
79 } else if (trainType.compare("MireoPlusB") == 0) {
81 } else if (trainType.compare("MireoPlusH") == 0) {
83 } else if (trainType.compare("custom") == 0) {
85 } else {
86 WRITE_ERRORF(TL("Unknown train type: %. Exiting!"), trainType);
87 throw ProcessError();
88 }
89 // override with user values
90 if (vtype->wasSet(VTYPEPARS_MAXSPEED_SET)) {
92 }
93 if (vtype->wasSet(VTYPEPARS_LENGTH_SET)) {
95 }
100 // update type parameters so they are shown correctly in the gui (if defaults from trainType are used)
101 const_cast<MSVehicleType*>(vtype)->setMaxSpeed(myTrainParams.vmax);
102 const_cast<MSVehicleType*>(vtype)->setLength(myTrainParams.length);
103 if (!vtype->wasSet(VTYPEPARS_MASS_SET)) {
104 // tons to kg
105 const_cast<MSVehicleType*>(vtype)->setMass(myTrainParams.weight * 1000);
106 }
107
108 // init tabular curves
111
112 // init parametric curves
118
120 throw ProcessError(TLF("Undefined maxPower for vType '%'.", vtype->getID()));
122 throw ProcessError(TLF("Undefined maxTraction for vType '%'.", vtype->getID()));
123 }
125 WRITE_WARNING(TLF("Ignoring tractionTable because maxPower and maxTraction are set for vType '%'.", vtype->getID()));
126 }
127 const bool hasSomeResCoef = (myTrainParams.resCoef_constant != INVALID_DOUBLE
130 const bool hasAllResCoef = (myTrainParams.resCoef_constant != INVALID_DOUBLE
133 if (hasSomeResCoef && !hasAllResCoef) {
134 throw ProcessError(TLF("Some undefined resistance coefficients for vType '%' (requires resCoef_constant, resCoef_linear and resCoef_quadratic)", vtype->getID()));
135 }
137 WRITE_WARNING(TLF("Ignoring resistanceTable because resistance coefficients are set for vType '%'.", vtype->getID()));
138 }
139
141 throw ProcessError(TLF("Either tractionTable or maxPower must be defined for vType '%' with Rail model type '%'.", vtype->getID(), trainType));
142 }
144 throw ProcessError(TLF("Either resistanceTable or resCoef_constant must be defined for vType '%' with Rail model type '%'.", vtype->getID(), trainType));
145 }
146}
147
148
150
151
152double MSCFModel_Rail::followSpeed(const MSVehicle* const veh, double speed, double gap,
153 double /* predSpeed */, double /* predMaxDecel*/, const MSVehicle* const /*pred*/, const CalcReason /*usage*/) const {
154
155 // followSpeed module is used for the simulation of moving block operations. The safety gap is chosen similar to the existing german
156 // system CIR-ELKE (based on LZB). Other implementations of moving block systems may differ, but for now no appropriate parameter
157 // can be set (would be per lane, not per train) -> hard-coded
158
159 // @note: default train minGap of 5 is already subtracted from gap
160 if (speed >= 30 / 3.6) {
161 // safety distance for higher speeds (>= 30 km/h)
162 gap = MAX2(0.0, gap + veh->getVehicleType().getMinGap() - 50);
163 }
164
165 const double vsafe = maximumSafeStopSpeed(gap, myDecel, speed, false, TS, false); // absolute breaking distance
166 const double vmin = minNextSpeed(speed, veh);
167 const double vmax = maxNextSpeed(speed, veh);
168
170 return MIN2(vsafe, vmax);
171 } else {
172 // ballistic
173 // XXX: the euler variant can break as strong as it wishes immediately! The ballistic cannot, refs. #2575.
174 return MAX2(MIN2(vsafe, vmax), vmin);
175 }
176}
177
178
179int
183
184
187 return new MSCFModel_Rail(vtype);
188}
189
190double
192 return getWeight(veh) * myTrainParams.mf;
193}
194
195double
196MSCFModel_Rail::getWeight(const MSVehicle* const veh) const {
197 // kg to tons
198 return veh->getVehicleType().getMass() / 1000;
199}
200
201double MSCFModel_Rail::maxNextSpeed(double speed, const MSVehicle* const veh) const {
202
203 if (speed >= myTrainParams.vmax) {
204 return myTrainParams.vmax;
205 }
206
207 double targetSpeed = myTrainParams.vmax;
208
209 double res = myTrainParams.getResistance(speed); // kN
210
211 double slope = veh->getSlope();
212 double gr = getWeight(veh) * GRAVITY * sin(DEG2RAD(slope)); //kN
213
214 double totalRes = res + gr; //kN
215
216 double trac = myTrainParams.getTraction(speed); // kN
217 double a;
218 if (speed < targetSpeed) {
219 a = (trac - totalRes) / getRotWeight(veh); //kN/t == N/kg
220 } else {
221 a = 0.;
222 if (totalRes > trac) {
223 a = (trac - totalRes) / getRotWeight(veh); //kN/t == N/kg
224 }
225 }
226 double maxNextSpeed = speed + ACCEL2SPEED(a);
227
228// std::cout << veh->getID() << " speed: " << (speed*3.6) << std::endl;
229
231}
232
233
234double MSCFModel_Rail::minNextSpeed(double speed, const MSVehicle* const veh) const {
235
236 const double slope = veh->getSlope();
237 const double gr = getWeight(veh) * GRAVITY * sin(DEG2RAD(slope)); //kN
238 const double res = myTrainParams.getResistance(speed); // kN
239 const double totalRes = res + gr; //kN
240 const double a = myTrainParams.decl + totalRes / getRotWeight(veh);
241 const double vMin = speed - ACCEL2SPEED(a);
243 return MAX2(vMin, 0.);
244 } else {
245 // NOTE: ballistic update allows for negative speeds to indicate a stop within the next timestep
246 return vMin;
247 }
248
249}
250
251
252double
253MSCFModel_Rail::minNextSpeedEmergency(double speed, const MSVehicle* const veh) const {
254 return minNextSpeed(speed, veh);
255}
256
257
258//void
259//MSCFModel_Rail::initVehicleVariables(const MSVehicle *const veh, MSCFModel_Rail::VehicleVariables *pVariables) const {
260//
261// pVariables->setInitialized();
262//
263//}
264
265
266double MSCFModel_Rail::getSpeedAfterMaxDecel(double /* speed */) const {
267
268// //TODO: slope not known here
269// double gr = 0; //trainParams.weight * GRAVITY * edge.grade
270//
271// double a = 0;//trainParams.decl - gr/trainParams.rotWeight;
272//
273// return speed + a * DELTA_T / 1000.;
274 WRITE_ERROR("function call not allowed for rail model. Exiting!");
275 throw ProcessError();
276}
277
278
283
284
285double MSCFModel_Rail::finalizeSpeed(MSVehicle* const veh, double vPos) const {
286 return MSCFModel::finalizeSpeed(veh, vPos);
287}
288
289
290double MSCFModel_Rail::freeSpeed(const MSVehicle* const /* veh */, double /* speed */, double dist, double targetSpeed,
291 const bool onInsertion, const CalcReason /*usage*/) const {
292
293// MSCFModel_Rail::VehicleVariables *vars = (MSCFModel_Rail::VehicleVariables *) veh->getCarFollowVariables();
294// if (vars->isNotYetInitialized()) {
295// initVehicleVariables(veh, vars);
296// }
297
298 //TODO: signals, coasting, ...
299
301 // adapt speed to succeeding lane, no reaction time is involved
302 // when breaking for y steps the following distance g is covered
303 // (drive with v in the final step)
304 // g = (y^2 + y) * 0.5 * b + y * v
305 // y = ((((sqrt((b + 2.0*v)*(b + 2.0*v) + 8.0*b*g)) - b)*0.5 - v)/b)
306 const double v = SPEED2DIST(targetSpeed);
307 if (dist < v) {
308 return targetSpeed;
309 }
310 const double b = ACCEL2DIST(myDecel);
311 const double y = MAX2(0.0, ((sqrt((b + 2.0 * v) * (b + 2.0 * v) + 8.0 * b * dist) - b) * 0.5 - v) / b);
312 const double yFull = floor(y);
313 const double exactGap = (yFull * yFull + yFull) * 0.5 * b + yFull * v + (y > yFull ? v : 0.0);
314 const double fullSpeedGain = (yFull + (onInsertion ? 1. : 0.)) * ACCEL2SPEED(myTrainParams.decl);
315 return DIST2SPEED(MAX2(0.0, dist - exactGap) / (yFull + 1)) + fullSpeedGain + targetSpeed;
316 } else {
317 WRITE_ERROR(TL("Anything else than semi implicit euler update is not yet implemented. Exiting!"));
318 throw ProcessError();
319 }
320}
321
322
323double MSCFModel_Rail::stopSpeed(const MSVehicle* const veh, const double speed, double gap, double decel, const CalcReason /*usage*/) const {
324 return MIN2(maximumSafeStopSpeed(gap, decel, speed, false, TS, false), maxNextSpeed(speed, veh));
325}
#define DEG2RAD(x)
Definition GeomHelper.h:35
#define GRAVITY
Definition GeomHelper.h:37
#define WRITE_ERRORF(...)
Definition MsgHandler.h:296
#define WRITE_ERROR(msg)
Definition MsgHandler.h:295
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
#define SPEED2DIST(x)
Definition SUMOTime.h:45
#define ACCEL2SPEED(x)
Definition SUMOTime.h:51
#define TS
Definition SUMOTime.h:42
#define DIST2SPEED(x)
Definition SUMOTime.h:47
#define ACCEL2DIST(x)
Definition SUMOTime.h:49
const long long int VTYPEPARS_MAXSPEED_SET
const long long int VTYPEPARS_MASS_SET
const long long int VTYPEPARS_LENGTH_SET
@ SUMO_TAG_CF_RAIL
@ SUMO_ATTR_RESISTANCE_COEFFICIENT_CONSTANT
@ SUMO_ATTR_RESISTANCE_TABLE
@ SUMO_ATTR_TRAIN_TYPE
@ SUMO_ATTR_MASSFACTOR
@ SUMO_ATTR_MAXTRACTION
@ SUMO_ATTR_MAXPOWER
@ SUMO_ATTR_RESISTANCE_COEFFICIENT_QUADRATIC
@ SUMO_ATTR_DECEL
@ SUMO_ATTR_EMERGENCYDECEL
@ SUMO_ATTR_RESISTANCE_COEFFICIENT_LINEAR
@ SUMO_ATTR_TRACTION_TABLE
const double INVALID_DOUBLE
invalid double
Definition StdDefs.h:68
T MIN2(T a, T b)
Definition StdDefs.h:80
T MAX2(T a, T b)
Definition StdDefs.h:86
static double getInterpolatedValue(const LinearApproxMap &map, double axisValue)
Get interpolated value.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
TrainParams initICE3Params() const
TrainParams initNGT400_16Params() const
virtual ~MSCFModel_Rail()
TrainParams initREDosto7Params() const
MSCFModel::VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting.
virtual double minNextSpeedEmergency(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed after emergency braking, given the current speed (depends on the numerical ...
TrainParams initCustomParams() const
TrainParams initICE1Params() const
MSCFModel_Rail(const MSVehicleType *vtype)
Constructor.
TrainParams initMireoPlusB2TParams() const
double freeSpeed(const MSVehicle *const veh, double speed, double seen, double maxSpeed, const bool onInsertion, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed without a leader.
TrainParams initRB628Params() const
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
virtual int getModelID() const
Returns the model's ID; the XML-Tag number is used.
double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
TrainParams myTrainParams
virtual double minNextSpeed(double speed, const MSVehicle *const veh) const
Returns the minimum speed given the current speed (depends on the numerical update scheme and its ste...
double getWeight(const MSVehicle *const veh) const
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 follow speed (no dawdling)
double getRotWeight(const MSVehicle *const veh) const
TrainParams initRB425Params() const
TrainParams initFreightParams() const
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
TrainParams initNGT400Params() const
TrainParams initMireoPlusH2TParams() const
double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences. Called at most once per simulation...
double stopSpeed(const MSVehicle *const veh, const double speed, double gap, 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:57
virtual void setEmergencyDecel(double decel)
Sets a new value for maximal physically possible deceleration [m/s^2].
Definition MSCFModel.h:572
virtual double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences. Called at most once per simulation...
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition MSCFModel.h:564
CalcReason
What the return value of stop/follow/free-Speed is used for.
Definition MSCFModel.h:79
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition MSCFModel.h:746
double maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion=false, double headway=-1, bool relaxEmergency=true) const
Returns the maximum next velocity for stopping within gap.
static bool gSemiImplicitEulerUpdate
Definition MSGlobals.h:53
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
double getSlope() const
Returns the slope of the road at vehicle's position in degrees.
The car-following model and parameter.
double getMaxSpeed() const
Get vehicle's (technical) maximum speed [m/s].
const std::string & getID() const
Returns the name of the vehicle type.
double getMinGap() const
Get the free space in front of vehicles of this class.
bool wasSet(long long int what) const
Returns whether the given parameter was set.
double getLength() const
Get vehicle's length [m].
double getMass() const
Get this vehicle type's mass.
const SUMOVTypeParameter & getParameter() const
LinearApproxHelpers::LinearApproxMap getCFProfile(const SumoXMLAttr attr, const LinearApproxHelpers::LinearApproxMap &defaultProfile) const
Returns the named value from the map, or the default if it is not contained there.
double getCFParam(const SumoXMLAttr attr, const double defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
std::string getCFParamString(const SumoXMLAttr attr, const std::string defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
LinearApproxHelpers::LinearApproxMap traction
LinearApproxHelpers::LinearApproxMap resistance
double getTraction(double speed) const
double getResistance(double speed) const