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-2018 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  double slope = veh->getSlope();
145  double gr = myTrainParams.weight * G * sin(DEG2RAD(slope)); //kN
146  double res = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.resistance)); // kN
147  double totalRes = res + gr; //kN
148 
149 
150  double a = myTrainParams.decl + totalRes / myTrainParams.rotWeight;
151 
152  return speed - a * DELTA_T / 1000.;
153 
154 }
155 
156 
157 double
158 MSCFModel_Rail::minNextSpeedEmergency(double speed, const MSVehicle* const veh) const {
159  return minNextSpeed(speed, veh);
160 }
161 
162 
163 double MSCFModel_Rail::getInterpolatedValueFromLookUpMap(double speed, const LookUpMap* lookUpMap) const {
164  speed = speed * 3.6; // lookup values in km/h
165  std::map<double, double>::const_iterator low, prev;
166  low = lookUpMap->lower_bound(speed);
167 
168  if (low == lookUpMap->end()) { //speed > max speed
169  return (lookUpMap->rbegin())->second;
170  }
171 
172  if (low == lookUpMap->begin()) {
173  return low->second;
174  }
175 
176  prev = low;
177  --prev;
178 
179  double range = low->first - prev->first;
180  double dist = speed - prev->first;
181  assert(range > 0);
182  assert(dist > 0);
183 
184  double weight = dist / range;
185 
186  double res = (1 - weight) * prev->second + weight * low->second;
187 
188  return res;
189 
190 }
191 
192 
193 
194 //void
195 //MSCFModel_Rail::initVehicleVariables(const MSVehicle *const veh, MSCFModel_Rail::VehicleVariables *pVariables) const {
196 //
197 // pVariables->setInitialized();
198 //
199 //}
200 
201 double MSCFModel_Rail::getSpeedAfterMaxDecel(double /* speed */) const {
202 
203 // //TODO: slope not known here
204 // double gr = 0; //trainParams.weight * 9.81 * edge.grade
205 //
206 // double a = 0;//trainParams.decl - gr/trainParams.rotWeight;
207 //
208 // return speed + a * DELTA_T / 1000.;
209  WRITE_ERROR("function call not allowd for rail model. Exiting!");
210  throw ProcessError();
211 }
212 
214  VehicleVariables* ret = new VehicleVariables();
215  return ret;
216 }
217 
218 
219 double MSCFModel_Rail::finalizeSpeed(MSVehicle* const veh, double vPos) const {
220  return MSCFModel::finalizeSpeed(veh, vPos);
221 }
222 
223 double MSCFModel_Rail::freeSpeed(const MSVehicle* const /* veh */, double /* speed */, double dist, double targetSpeed,
224  const bool onInsertion) const {
225 
226 // MSCFModel_Rail::VehicleVariables *vars = (MSCFModel_Rail::VehicleVariables *) veh->getCarFollowVariables();
227 // if (vars->isNotYetInitialized()) {
228 // initVehicleVariables(veh, vars);
229 // }
230 
231  //TODO: signals, coasting, ...
232 
234  // adapt speed to succeeding lane, no reaction time is involved
235  // when breaking for y steps the following distance g is covered
236  // (drive with v in the final step)
237  // g = (y^2 + y) * 0.5 * b + y * v
238  // y = ((((sqrt((b + 2.0*v)*(b + 2.0*v) + 8.0*b*g)) - b)*0.5 - v)/b)
239  const double v = SPEED2DIST(targetSpeed);
240  if (dist < v) {
241  return targetSpeed;
242  }
243  const double b = ACCEL2DIST(myDecel);
244  const double y = MAX2(0.0, ((sqrt((b + 2.0 * v) * (b + 2.0 * v) + 8.0 * b * dist) - b) * 0.5 - v) / b);
245  const double yFull = floor(y);
246  const double exactGap = (yFull * yFull + yFull) * 0.5 * b + yFull * v + (y > yFull ? v : 0.0);
247  const double fullSpeedGain = (yFull + (onInsertion ? 1. : 0.)) * ACCEL2SPEED(myTrainParams.decl);
248  return DIST2SPEED(MAX2(0.0, dist - exactGap) / (yFull + 1)) + fullSpeedGain + targetSpeed;
249  } else {
250  WRITE_ERROR("Anything else than semi implicit euler update is not yet implemented. Exiting!");
251  throw ProcessError();
252  }
253 }
254 
255 double MSCFModel_Rail::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
256  return MIN2(maximumSafeStopSpeed(gap, speed, false, TS), maxNextSpeed(speed, veh));
257 }
const int VTYPEPARS_MAXSPEED_SET
#define DIST2SPEED(x)
Definition: SUMOTime.h:50
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
TrainParams initRB425Params() const
#define SPEED2DIST(x)
Definition: SUMOTime.h:48
TrainParams initICE1Params() const
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:54
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:76
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:45
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:52
TrainParams initRB628Params() const
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
T MIN2(T a, T b)
Definition: StdDefs.h:70
#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:709
const SUMOVTypeParameter & getParameter() const
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:593
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:247
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:1115
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