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