Eclipse SUMO - Simulation of Urban MObility
MSCFModel_Rail.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2012-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // <description missing>
16 /****************************************************************************/
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
22 #include <iostream>
24 #include <utils/geom/GeomHelper.h>
25 #include <microsim/MSVehicle.h>
27 #include "MSCFModel_Rail.h"
28 
29 #define G 9.80665
30 
32  MSCFModel(vtype) {
33  const std::string trainType = vtype->getParameter().getCFParamString(SUMO_ATTR_TRAIN_TYPE, "NGT400");
34  if (trainType.compare("RB425") == 0) {
36  } else if (trainType.compare("RB628") == 0) {
38  } else if (trainType.compare("NGT400") == 0) {
40  } else if (trainType.compare("NGT400_16") == 0) {
42  } else if (trainType.compare("ICE1") == 0) {
44  } else if (trainType.compare("REDosto7") == 0) {
46  } else if (trainType.compare("Freight") == 0) {
48  } else if (trainType.compare("ICE3") == 0) {
50  } else {
51  WRITE_ERROR("Unknown train type: " + trainType + ". Exiting!");
52  throw ProcessError();
53  }
54  // override with user values
55  if (vtype->wasSet(VTYPEPARS_MAXSPEED_SET)) {
56  myTrainParams.vmax = vtype->getMaxSpeed();
57  }
58  if (vtype->wasSet(VTYPEPARS_LENGTH_SET)) {
59  myTrainParams.length = vtype->getLength();
60  }
64  // update type parameters so they are shown correctly in the gui (if defaults from trainType are used)
65  const_cast<MSVehicleType*>(vtype)->setMaxSpeed(myTrainParams.vmax);
66  const_cast<MSVehicleType*>(vtype)->setLength(myTrainParams.length);
67 
68 }
69 
71 
72 double MSCFModel_Rail::followSpeed(const MSVehicle* const veh, double speed, double gap,
73  double /* predSpeed */, double /* predMaxDecel*/, const MSVehicle* const /*pred*/) const {
74 
75  // followSpeed module is used for the simulation of moving block operations. The safety gap is chosen similar to the existing german
76  // system CIR-ELKE (based on LZB). Other implementations of moving block systems may differ, but for now no appropriate parameter
77  // can be set (would be per lane, not per train) -> hard-coded
78 
79  double safetyGap = 5.0; // default value for low speeds (< 30 km/h)
80  if (speed >= 30 / 3.6) {
81  safetyGap = 50.0; // safety distance for higher speeds (>= 30 km/h)
82  }
83 
84  const double vsafe = maximumSafeStopSpeed(gap - safetyGap, speed, false, TS); // absolute breaking distance
85  const double vmin = minNextSpeed(speed, veh);
86  const double vmax = maxNextSpeed(speed, veh);
87 
89  return MIN2(vsafe, vmax);
90  } else {
91  // ballistic
92  // XXX: the euler variant can break as strong as it wishes immediately! The ballistic cannot, refs. #2575.
93  return MAX2(MIN2(vsafe, vmax), vmin);
94  }
95 }
96 
97 int
99  return SUMO_TAG_CF_RAIL;
100 }
101 
102 MSCFModel*
104  return new MSCFModel_Rail(vtype);
105 }
106 
107 double MSCFModel_Rail::maxNextSpeed(double speed, const MSVehicle* const veh) const {
108 
109  if (speed >= myTrainParams.vmax) {
110  return myTrainParams.vmax;
111  }
112 
113  double targetSpeed = myTrainParams.vmax;
114 
115  double res = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.resistance)); // kN
116 
117  double slope = veh->getSlope();
118  double gr = myTrainParams.weight * G * sin(DEG2RAD(slope)); //kN
119 
120  double totalRes = res + gr; //kN
121 
122  double trac = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.traction)); // kN
123 
124  double a;
125  if (speed < targetSpeed) {
126  a = (trac - totalRes) / myTrainParams.rotWeight; //kN/t == N/kg
127  } else {
128  a = 0.;
129  if (totalRes > trac) {
130  a = (trac - totalRes) / myTrainParams.rotWeight; //kN/t == N/kg
131  }
132  }
133 
134  double maxNextSpeed = speed + a * DELTA_T / 1000.;
135 
136 // std::cout << veh->getID() << " speed: " << (speed*3.6) << std::endl;
137 
138  return maxNextSpeed;
139 }
140 
141 double MSCFModel_Rail::minNextSpeed(double speed, const MSVehicle* const veh) const {
142 
143  const double slope = veh->getSlope();
144  const double gr = myTrainParams.weight * G * sin(DEG2RAD(slope)); //kN
145  const double res = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.resistance)); // kN
146  const double totalRes = res + gr; //kN
147  const double a = myTrainParams.decl + totalRes / myTrainParams.rotWeight;
148  const double vMin = speed - a * DELTA_T / 1000.;
150  return MAX2(vMin, 0.);
151  } else {
152  // NOTE: ballistic update allows for negative speeds to indicate a stop within the next timestep
153  return vMin;
154  }
155 
156 }
157 
158 
159 double
160 MSCFModel_Rail::minNextSpeedEmergency(double speed, const MSVehicle* const veh) const {
161  return minNextSpeed(speed, veh);
162 }
163 
164 
165 double MSCFModel_Rail::getInterpolatedValueFromLookUpMap(double speed, const LookUpMap* lookUpMap) const {
166  speed = speed * 3.6; // lookup values in km/h
167  std::map<double, double>::const_iterator low, prev;
168  low = lookUpMap->lower_bound(speed);
169 
170  if (low == lookUpMap->end()) { //speed > max speed
171  return (lookUpMap->rbegin())->second;
172  }
173 
174  if (low == lookUpMap->begin()) {
175  return low->second;
176  }
177 
178  prev = low;
179  --prev;
180 
181  double range = low->first - prev->first;
182  double dist = speed - prev->first;
183  assert(range > 0);
184  assert(dist > 0);
185 
186  double weight = dist / range;
187 
188  double res = (1 - weight) * prev->second + weight * low->second;
189 
190  return res;
191 
192 }
193 
194 
195 
196 //void
197 //MSCFModel_Rail::initVehicleVariables(const MSVehicle *const veh, MSCFModel_Rail::VehicleVariables *pVariables) const {
198 //
199 // pVariables->setInitialized();
200 //
201 //}
202 
203 double MSCFModel_Rail::getSpeedAfterMaxDecel(double /* speed */) const {
204 
205 // //TODO: slope not known here
206 // double gr = 0; //trainParams.weight * 9.81 * edge.grade
207 //
208 // double a = 0;//trainParams.decl - gr/trainParams.rotWeight;
209 //
210 // return speed + a * DELTA_T / 1000.;
211  WRITE_ERROR("function call not allowd for rail model. Exiting!");
212  throw ProcessError();
213 }
214 
216  VehicleVariables* ret = new VehicleVariables();
217  return ret;
218 }
219 
220 
221 double MSCFModel_Rail::finalizeSpeed(MSVehicle* const veh, double vPos) const {
222  return MSCFModel::finalizeSpeed(veh, vPos);
223 }
224 
225 double MSCFModel_Rail::freeSpeed(const MSVehicle* const /* veh */, double /* speed */, double dist, double targetSpeed,
226  const bool onInsertion) const {
227 
228 // MSCFModel_Rail::VehicleVariables *vars = (MSCFModel_Rail::VehicleVariables *) veh->getCarFollowVariables();
229 // if (vars->isNotYetInitialized()) {
230 // initVehicleVariables(veh, vars);
231 // }
232 
233  //TODO: signals, coasting, ...
234 
236  // adapt speed to succeeding lane, no reaction time is involved
237  // when breaking for y steps the following distance g is covered
238  // (drive with v in the final step)
239  // g = (y^2 + y) * 0.5 * b + y * v
240  // y = ((((sqrt((b + 2.0*v)*(b + 2.0*v) + 8.0*b*g)) - b)*0.5 - v)/b)
241  const double v = SPEED2DIST(targetSpeed);
242  if (dist < v) {
243  return targetSpeed;
244  }
245  const double b = ACCEL2DIST(myDecel);
246  const double y = MAX2(0.0, ((sqrt((b + 2.0 * v) * (b + 2.0 * v) + 8.0 * b * dist) - b) * 0.5 - v) / b);
247  const double yFull = floor(y);
248  const double exactGap = (yFull * yFull + yFull) * 0.5 * b + yFull * v + (y > yFull ? v : 0.0);
249  const double fullSpeedGain = (yFull + (onInsertion ? 1. : 0.)) * ACCEL2SPEED(myTrainParams.decl);
250  return DIST2SPEED(MAX2(0.0, dist - exactGap) / (yFull + 1)) + fullSpeedGain + targetSpeed;
251  } else {
252  WRITE_ERROR("Anything else than semi implicit euler update is not yet implemented. Exiting!");
253  throw ProcessError();
254  }
255 }
256 
257 double MSCFModel_Rail::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
258  return MIN2(maximumSafeStopSpeed(gap, speed, false, TS), maxNextSpeed(speed, veh));
259 }
MSVehicleType
The car-following model and parameter.
Definition: MSVehicleType.h:65
MSCFModel_Rail::getModelID
virtual int getModelID() const
Returns the model's ID; the XML-Tag number is used.
Definition: MSCFModel_Rail.cpp:98
SPEED2DIST
#define SPEED2DIST(x)
Definition: SUMOTime.h:46
MIN2
T MIN2(T a, T b)
Definition: StdDefs.h:73
DIST2SPEED
#define DIST2SPEED(x)
Definition: SUMOTime.h:48
MSCFModel::setEmergencyDecel
virtual void setEmergencyDecel(double decel)
Sets a new value for maximal physically possible deceleration [m/s^2].
Definition: MSCFModel.h:483
DELTA_T
SUMOTime DELTA_T
Definition: SUMOTime.cpp:36
MSCFModel_Rail::createVehicleVariables
MSCFModel::VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting.
Definition: MSCFModel_Rail.cpp:215
MSCFModel_Rail::initRB628Params
TrainParams initRB628Params() const
Definition: MSCFModel_Rail.h:571
MSCFModel_Rail::initICE3Params
TrainParams initICE3Params() const
Definition: MSCFModel_Rail.h:427
ACCEL2SPEED
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:52
MSCFModel_Rail::initICE1Params
TrainParams initICE1Params() const
Definition: MSCFModel_Rail.h:413
MsgHandler.h
MSCFModel_Rail::MSCFModel_Rail
MSCFModel_Rail(const MSVehicleType *vtype)
Constructor.
Definition: MSCFModel_Rail.cpp:31
SUMO_TAG_CF_RAIL
@ SUMO_TAG_CF_RAIL
Definition: SUMOXMLDefinitions.h:289
MSCFModel_Rail.h
MSCFModel_Rail::initNGT400Params
TrainParams initNGT400Params() const
Definition: MSCFModel_Rail.h:217
G
#define G
Definition: MSCFModel_Rail.cpp:29
MSCFModel_Rail::initREDosto7Params
TrainParams initREDosto7Params() const
Definition: MSCFModel_Rail.h:513
MSCFModel_Rail::minNextSpeedEmergency
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 ...
Definition: MSCFModel_Rail.cpp:160
MSCFModel_Rail::TrainParams::rotWeight
double rotWeight
Definition: MSCFModel_Rail.h:70
MSCFModel_Rail::getSpeedAfterMaxDecel
double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
Definition: MSCFModel_Rail.cpp:203
MSCFModel::finalizeSpeed
virtual double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences. Called at most once per simulation...
Definition: MSCFModel.cpp:164
MSCFModel_Rail::getInterpolatedValueFromLookUpMap
double getInterpolatedValueFromLookUpMap(double speed, const LookUpMap *lookUpMap) const
Definition: MSCFModel_Rail.cpp:165
MSVehicle::getSlope
double getSlope() const
Returns the slope of the road at vehicle's position.
Definition: MSVehicle.cpp:1258
MSVehicle.h
MAX2
T MAX2(T a, T b)
Definition: StdDefs.h:79
ACCEL2DIST
#define ACCEL2DIST(x)
Definition: SUMOTime.h:50
MSCFModel::setMaxDecel
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:475
MSCFModel_Rail::myTrainParams
TrainParams myTrainParams
Definition: MSCFModel_Rail.h:107
SUMO_ATTR_DECEL
@ SUMO_ATTR_DECEL
Definition: SUMOXMLDefinitions.h:446
MSCFModel_Rail::TrainParams::weight
double weight
Definition: MSCFModel_Rail.h:64
MSCFModel_Rail::minNextSpeed
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...
Definition: MSCFModel_Rail.cpp:141
TS
#define TS
Definition: SUMOTime.h:43
MSCFModel_Rail::freeSpeed
double freeSpeed(const MSVehicle *const veh, double speed, double seen, double maxSpeed, const bool onInsertion) const
Computes the vehicle's safe speed without a leader.
Definition: MSCFModel_Rail.cpp:225
MSCFModel::maximumSafeStopSpeed
double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap.
Definition: MSCFModel.cpp:711
MSCFModel_Rail::maxNextSpeed
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
Definition: MSCFModel_Rail.cpp:107
MSCFModel_Rail::stopSpeed
double stopSpeed(const MSVehicle *const veh, const double speed, double gap) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
Definition: MSCFModel_Rail.cpp:257
ProcessError
Definition: UtilExceptions.h:39
MSCFModel_Rail::TrainParams::decl
double decl
Definition: MSCFModel_Rail.h:67
SUMOVTypeParameter::getCFParam
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.
Definition: SUMOVTypeParameter.cpp:458
MSCFModel_Rail::LookUpMap
std::map< double, double > LookUpMap
Definition: MSCFModel_Rail.h:61
DEG2RAD
#define DEG2RAD(x)
Definition: GeomHelper.h:37
SUMO_ATTR_TRAIN_TYPE
@ SUMO_ATTR_TRAIN_TYPE
Definition: SUMOXMLDefinitions.h:583
MSCFModel::VehicleVariables
Definition: MSCFModel.h:60
MSCFModel_Rail::TrainParams::vmax
double vmax
Definition: MSCFModel_Rail.h:68
MSVehicleType::getLength
double getLength() const
Get vehicle's length [m].
Definition: MSVehicleType.h:109
MSVehicleType::wasSet
bool wasSet(int what) const
Returns whether the given parameter was set.
Definition: MSVehicleType.h:82
MSCFModel_Rail::finalizeSpeed
double finalizeSpeed(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences. Called at most once per simulation...
Definition: MSCFModel_Rail.cpp:221
MSCFModel::myDecel
double myDecel
The vehicle's maximum deceleration [m/s^2].
Definition: MSCFModel.h:620
MSVehicleType::getParameter
const SUMOVTypeParameter & getParameter() const
Definition: MSVehicleType.h:560
SUMO_ATTR_EMERGENCYDECEL
@ SUMO_ATTR_EMERGENCYDECEL
Definition: SUMOXMLDefinitions.h:447
MSVehicleType::getMaxSpeed
double getMaxSpeed() const
Get vehicle's maximum speed [m/s].
Definition: MSVehicleType.h:161
MSCFModel
The car-following model abstraction.
Definition: MSCFModel.h:56
config.h
SUMOVTypeParameter::getCFParamString
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.
Definition: SUMOVTypeParameter.cpp:468
GeomHelper.h
VTYPEPARS_LENGTH_SET
const int VTYPEPARS_LENGTH_SET
Definition: SUMOVTypeParameter.h:45
MSCFModel_Rail::~MSCFModel_Rail
virtual ~MSCFModel_Rail()
Definition: MSCFModel_Rail.cpp:70
MSCFModel_Rail::followSpeed
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0) const
Computes the vehicle's follow speed (no dawdling)
Definition: MSCFModel_Rail.cpp:72
MSCFModel_Rail::TrainParams::length
double length
Definition: MSCFModel_Rail.h:66
MSCFModel_Rail::TrainParams::resistance
LookUpMap resistance
Definition: MSCFModel_Rail.h:72
MSCFModel_Rail::initRB425Params
TrainParams initRB425Params() const
Definition: MSCFModel_Rail.h:715
MSGlobals::gSemiImplicitEulerUpdate
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:55
MSCFModel_Rail::TrainParams::traction
LookUpMap traction
Definition: MSCFModel_Rail.h:71
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283
MSCFModel_Rail::duplicate
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
Definition: MSCFModel_Rail.cpp:103
VTYPEPARS_MAXSPEED_SET
const int VTYPEPARS_MAXSPEED_SET
Definition: SUMOVTypeParameter.h:47
MSCFModel_Rail::initFreightParams
TrainParams initFreightParams() const
Definition: MSCFModel_Rail.h:621
MSAbstractLaneChangeModel.h
MSCFModel_Rail::initNGT400_16Params
TrainParams initNGT400_16Params() const
Definition: MSCFModel_Rail.h:337
MSVehicle
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79