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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // <description missing>
18 /****************************************************************************/
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #ifdef _MSC_VER
23 #include <windows_config.h>
24 #else
25 #include <config.h>
26 #endif
27 
28 #include <iostream>
30 #include <utils/geom/GeomHelper.h>
31 #include <microsim/MSVehicle.h>
33 #include "MSCFModel_Rail.h"
34 
35 #define G 9.80665
36 
37 MSCFModel_Rail::MSCFModel_Rail(const MSVehicleType* vtype, std::string trainType)
38  :
39 
40  MSCFModel(vtype, -1, -1, -1, -1, 1) {
41 
42  if (trainType.compare("RB425") == 0) {
44  } else if (trainType.compare("RB628") == 0) {
46  } else if (trainType.compare("NGT400") == 0) {
48  } else if (trainType.compare("NGT400_16") == 0) {
50  } else if (trainType.compare("ICE1") == 0) {
52  } else if (trainType.compare("REDosto7") == 0) {
54  } else if (trainType.compare("Freight") == 0) {
56  } else if (trainType.compare("ICE3") == 0) {
58  } else {
59  WRITE_ERROR("Unknown train type: " + trainType + ". Exiting!");
60  throw ProcessError();
61  }
63 
64 }
65 
67 }
68 
69 double MSCFModel_Rail::followSpeed(const MSVehicle* const veh, double speed, double /* gap2pred*/,
70  double /* predSpeed */, double /* predMaxDecel*/) const {
71  return maxNextSpeed(speed, veh);
72 }
73 
74 int
76  return SUMO_TAG_CF_RAIL;
77 }
78 
79 MSCFModel*
80 MSCFModel_Rail::duplicate(const MSVehicleType* /* vtype */) const {
82  throw ProcessError("not yet implemented");
83 }
84 
85 double MSCFModel_Rail::maxNextSpeed(double speed, const MSVehicle* const veh) const {
86 
87  if (speed >= myTrainParams.vmax) {
88  return myTrainParams.vmax;
89  }
90 
91  double targetSpeed = myTrainParams.vmax;
92 
93  double res = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.resistance)); // kN
94 
95  double slope = veh->getSlope();
96  double gr = myTrainParams.weight * G * sin(DEG2RAD(slope)); //kN
97 
98  double totalRes = res + gr; //kN
99 
100  double trac = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.traction)); // kN
101 
102  double a;
103  if (speed < targetSpeed) {
104  a = (trac - totalRes) / myTrainParams.rotWeight; //kN/t == N/kg
105  } else {
106  a = 0.;
107  if (totalRes > trac) {
108  a = (trac - totalRes) / myTrainParams.rotWeight; //kN/t == N/kg
109  }
110  }
111 
112  double maxNextSpeed = speed + a * DELTA_T / 1000.;
113 
114 // std::cout << veh->getID() << " speed: " << (speed*3.6) << std::endl;
115 
116  return maxNextSpeed;
117 }
118 
119 double MSCFModel_Rail::minNextSpeed(double speed, const MSVehicle* const veh) const {
120 
121  double slope = veh->getSlope();
122  double gr = myTrainParams.weight * G * sin(DEG2RAD(slope)); //kN
123  double res = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.resistance)); // kN
124  double totalRes = res + gr; //kN
125 
126 
127  double a = myTrainParams.decl + totalRes / myTrainParams.rotWeight;
128 
129  return speed - a * DELTA_T / 1000.;
130 
131 }
132 
133 double MSCFModel_Rail::getInterpolatedValueFromLookUpMap(double speed, const LookUpMap* lookUpMap) const {
134  std::map<double, double>::const_iterator low, prev;
135  low = lookUpMap->lower_bound(speed);
136 
137  if (low == lookUpMap->end()) { //speed > max speed
138  return (lookUpMap->rbegin())->second;
139  }
140 
141  if (low == lookUpMap->begin()) {
142  return low->second;
143  }
144 
145  prev = low;
146  --prev;
147 
148  double range = low->first - prev->first;
149  double dist = speed - prev->first;
150  assert(range > 0);
151  assert(dist > 0);
152 
153  double weight = dist / range;
154 
155  double res = (1 - weight) * prev->second + weight * low->second;
156 
157  return res;
158 
159 }
160 
161 
162 
163 //void
164 //MSCFModel_Rail::initVehicleVariables(const MSVehicle *const veh, MSCFModel_Rail::VehicleVariables *pVariables) const {
165 //
166 // pVariables->setInitialized();
167 //
168 //}
169 
170 double MSCFModel_Rail::getSpeedAfterMaxDecel(double /* speed */) const {
171 
172 // //TODO: slope not known here
173 // double gr = 0; //trainParams.weight * 9.81 * edge.grade
174 //
175 // double a = 0;//trainParams.decl - gr/trainParams.rotWeight;
176 //
177 // return speed + a * DELTA_T / 1000.;
178  WRITE_ERROR("function call not allowd for rail model. Exiting!");
179  throw ProcessError();
180 }
181 
183  VehicleVariables* ret = new VehicleVariables();
184  return ret;
185 }
186 
187 
188 double MSCFModel_Rail::moveHelper(MSVehicle* const veh, double vPos) const {
189  const double oldV = veh->getSpeed(); // save old v for optional acceleration computation
190  const double vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
191  const double vMin = minNextSpeed(oldV, veh);
192  const double vMax = MAX2(vMin, MIN3(veh->getMaxSpeedOnLane(), maxNextSpeed(oldV, veh), vSafe));
193  const double vNext = veh->getLaneChangeModel().patchSpeed(vMin, vMax, vMax, *this);
194  return vNext;
195 }
196 
197 double MSCFModel_Rail::freeSpeed(const MSVehicle* const /* veh */, double /* speed */, double dist, double targetSpeed,
198  const bool onInsertion) const {
199 
200 // MSCFModel_Rail::VehicleVariables *vars = (MSCFModel_Rail::VehicleVariables *) veh->getCarFollowVariables();
201 // if (vars->isNotYetInitialized()) {
202 // initVehicleVariables(veh, vars);
203 // }
204 
205  //TODO: signals, coasting, ...
206 
208  // adapt speed to succeeding lane, no reaction time is involved
209  // when breaking for y steps the following distance g is covered
210  // (drive with v in the final step)
211  // g = (y^2 + y) * 0.5 * b + y * v
212  // y = ((((sqrt((b + 2.0*v)*(b + 2.0*v) + 8.0*b*g)) - b)*0.5 - v)/b)
213  const double v = SPEED2DIST(targetSpeed);
214  if (dist < v) {
215  return targetSpeed;
216  }
217  const double b = ACCEL2DIST(myDecel);
218  const double y = MAX2(0.0, ((sqrt((b + 2.0 * v) * (b + 2.0 * v) + 8.0 * b * dist) - b) * 0.5 - v) / b);
219  const double yFull = floor(y);
220  const double exactGap = (yFull * yFull + yFull) * 0.5 * b + yFull * v + (y > yFull ? v : 0.0);
221  const double fullSpeedGain = (yFull + (onInsertion ? 1. : 0.)) * ACCEL2SPEED(myTrainParams.decl);
222  return DIST2SPEED(MAX2(0.0, dist - exactGap) / (yFull + 1)) + fullSpeedGain + targetSpeed;
223  } else {
224  WRITE_ERROR("Anything else then semi implicit euler update is not yet implemented. Exiting!");
225  throw ProcessError();
226  }
227 }
228 
229 double MSCFModel_Rail::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
230  return MIN2(maximumSafeStopSpeed(gap, speed, false, TS), maxNextSpeed(speed, veh));
231 }
#define DIST2SPEED(x)
Definition: SUMOTime.h:56
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
TrainParams initRB425Params() const
#define SPEED2DIST(x)
Definition: SUMOTime.h:54
TrainParams initICE1Params() const
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:60
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::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:59
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:73
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:39
TrainParams initICE3Params() const
#define TS
Definition: SUMOTime.h:51
TrainParams initNGT400_16Params() const
double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
The car-following model and parameter.
Definition: MSVehicleType.h:72
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:3674
double getMaxSpeedOnLane() const
Returns the maximal speed for the vehicle on its current lane (including speed factor and deviation...
Definition: MSVehicle.h:574
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 ...
double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
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:58
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle&#39;s follow speed (no dawdling)
TrainParams initRB628Params() const
T MIN2(T a, T b)
Definition: StdDefs.h:67
#define DEG2RAD(x)
Definition: GeomHelper.h:44
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:662
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:537
virtual ~MSCFModel_Rail()
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:451
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1376
TrainParams myTrainParams
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:62
double getSlope() const
Returns the slope of the road at vehicle&#39;s position.
Definition: MSVehicle.cpp:890
TrainParams initFreightParams() const
T MIN3(T a, T b, T c)
Definition: StdDefs.h:80
MSCFModel_Rail(const MSVehicleType *vtype, std::string trainType)
Constructor.
virtual int getModelID() const
Returns the model&#39;s ID; the XML-Tag number is used.
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:482
double getInterpolatedValueFromLookUpMap(double speed, const LookUpMap *lookUpMap) const
#define G