SUMO - Simulation of Urban MObility
MSCFModel_Rail.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // <description missing>
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2012-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <iostream>
31 #include <utils/geom/GeomHelper.h>
32 #include <microsim/MSVehicle.h>
34 #include "MSCFModel_Rail.h"
35 
36 #define G 9.80665
37 
38 MSCFModel_Rail::MSCFModel_Rail(const MSVehicleType* vtype, std::string trainType) :
39  MSCFModel(vtype, -1, -1, -1, -1, -1) {
40 
41  if (trainType.compare("RB425") == 0) {
43  } else if (trainType.compare("RB628") == 0) {
45  } else if (trainType.compare("NGT400") == 0) {
47  } else if (trainType.compare("NGT400_16") == 0) {
49  } else if (trainType.compare("ICE1") == 0) {
51  } else if (trainType.compare("REDosto7") == 0) {
53  } else if (trainType.compare("Freight") == 0) {
55  } else if (trainType.compare("ICE3") == 0) {
57  } else {
58  WRITE_ERROR("Unknown train type: " + trainType + ". Exiting!");
59  throw ProcessError();
60  }
62 
63 }
64 
66 }
67 
68 double MSCFModel_Rail::followSpeed(const MSVehicle* const veh, double speed, double /* gap2pred*/,
69  double /* predSpeed */, double /* predMaxDecel*/) const {
70  return maxNextSpeed(speed, veh);
71 }
72 
73 int
75  return SUMO_TAG_CF_RAIL;
76 }
77 
78 MSCFModel*
79 MSCFModel_Rail::duplicate(const MSVehicleType* /* vtype */) const {
81  throw ProcessError("not yet implemented");
82 }
83 
84 double MSCFModel_Rail::maxNextSpeed(double speed, const MSVehicle* const veh) const {
85 
86  if (speed >= myTrainParams.vmax) {
87  return myTrainParams.vmax;
88  }
89 
90  double targetSpeed = myTrainParams.vmax;
91 
92  double res = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.resistance)); // kN
93 
94  double slope = veh->getSlope();
95  double gr = myTrainParams.weight * G * sin(DEG2RAD(slope)); //kN
96 
97  double totalRes = res + gr; //kN
98 
99  double trac = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.traction)); // kN
100 
101  double a;
102  if (speed < targetSpeed) {
103  a = (trac - totalRes) / myTrainParams.rotWeight; //kN/t == N/kg
104  } else {
105  a = 0.;
106  if (totalRes > trac) {
107  a = (trac - totalRes) / myTrainParams.rotWeight; //kN/t == N/kg
108  }
109  }
110 
111  double maxNextSpeed = speed + a * DELTA_T / 1000.;
112 
113 // std::cout << veh->getID() << " speed: " << (speed*3.6) << std::endl;
114 
115  return maxNextSpeed;
116 }
117 
118 double MSCFModel_Rail::minNextSpeed(double speed, const MSVehicle* const veh) const {
119 
120  double slope = veh->getSlope();
121  double gr = myTrainParams.weight * G * sin(DEG2RAD(slope)); //kN
122  double res = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.resistance)); // kN
123  double totalRes = res + gr; //kN
124 
125  double a = (myTrainParams.decl + totalRes) / myTrainParams.rotWeight;
126 
127  return speed - a * DELTA_T / 1000.;
128 
129 }
130 
131 double MSCFModel_Rail::getInterpolatedValueFromLookUpMap(double speed, const LookUpMap* lookUpMap) const {
132  std::map<double, double>::const_iterator low, prev;
133  low = lookUpMap->lower_bound(speed);
134 
135  if (low == lookUpMap->end()) { //speed > max speed
136  return (lookUpMap->rbegin())->second;
137  }
138 
139  if (low == lookUpMap->begin()) {
140  return low->second;
141  }
142 
143  prev = low;
144  --prev;
145 
146  double range = low->first - prev->first;
147  double dist = speed - prev->first;
148  assert(range > 0);
149  assert(dist > 0);
150 
151  double weight = dist / range;
152 
153  double res = (1 - weight) * prev->second + weight * low->second;
154 
155  return res;
156 
157 }
158 
159 
160 
161 //void
162 //MSCFModel_Rail::initVehicleVariables(const MSVehicle *const veh, MSCFModel_Rail::VehicleVariables *pVariables) const {
163 //
164 // pVariables->setInitialized();
165 //
166 //}
167 
168 double MSCFModel_Rail::getSpeedAfterMaxDecel(double /* speed */) const {
169 
170 // //TODO: slope not known here
171 // double gr = 0; //trainParams.weight * 9.81 * edge.grade
172 //
173 // double a = 0;//trainParams.decl - gr/trainParams.rotWeight;
174 //
175 // return speed + a * DELTA_T / 1000.;
176  WRITE_ERROR("function call not allowd for rail model. Exiting!");
177  throw ProcessError();
178 }
179 
181  VehicleVariables* ret = new VehicleVariables();
182  return ret;
183 }
184 
185 //mostly c 'n p from MSCFModel
186 double MSCFModel_Rail::moveHelper(MSVehicle* const veh, double vPos) const {
187  const double oldV = veh->getSpeed(); // save old v for optional acceleration computation
188  const double vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
189  // we need the acceleration for emission computation;
190  // in this case, we neglect dawdling, nonetheless, using
191  // vSafe does not incorporate speed reduction due to interaction
192  // on lane changing
193  double vMin, vNext;
194  const double vMax = MIN3(veh->getMaxSpeedOnLane(), maxNextSpeed(oldV, veh), vSafe);
196  // we cannot rely on never braking harder than maxDecel because TraCI or strange cf models may decide to do so
197  vMin = MIN2(minNextSpeed(oldV, veh), vMax);
198  vNext = veh->getLaneChangeModel().patchSpeed(vMin, vMax, vMax, *this);
199  } else {
200  // for ballistic update, negative vnext must be allowed to
201  // indicate a stop within the coming timestep (i.e., to attain negative values)
202  vMin = MIN2(minNextSpeed(oldV, veh), vMax);
203  vNext = veh->getLaneChangeModel().patchSpeed(vMin, vMax, vMax, *this);
204  // (Leo) moveHelper() is responsible for assuring that the next
205  // velocity is chosen in accordance with maximal decelerations.
206  // At this point vNext may also be negative indicating a stop within next step.
207  // Moreover, because maximumSafeStopSpeed() does not consider deceleration bounds
208  // vNext can be a large negative value at this point. We cap vNext here.
209  vNext = MAX2(vNext, vMin);
210  }
211 
212  return vNext;
213 }
214 
215 double MSCFModel_Rail::freeSpeed(const MSVehicle* const /* veh */, double /* speed */, double dist, double targetSpeed,
216  const bool onInsertion) const {
217 
218 // MSCFModel_Rail::VehicleVariables *vars = (MSCFModel_Rail::VehicleVariables *) veh->getCarFollowVariables();
219 // if (vars->isNotYetInitialized()) {
220 // initVehicleVariables(veh, vars);
221 // }
222 
223  //TODO: signals, coasting, ...
224 
226  // adapt speed to succeeding lane, no reaction time is involved
227  // when breaking for y steps the following distance g is covered
228  // (drive with v in the final step)
229  // g = (y^2 + y) * 0.5 * b + y * v
230  // y = ((((sqrt((b + 2.0*v)*(b + 2.0*v) + 8.0*b*g)) - b)*0.5 - v)/b)
231  const double v = SPEED2DIST(targetSpeed);
232  if (dist < v) {
233  return targetSpeed;
234  }
235  const double b = ACCEL2DIST(myDecel);
236  const double y = MAX2(0.0, ((sqrt((b + 2.0 * v) * (b + 2.0 * v) + 8.0 * b * dist) - b) * 0.5 - v) / b);
237  const double yFull = floor(y);
238  const double exactGap = (yFull * yFull + yFull) * 0.5 * b + yFull * v + (y > yFull ? v : 0.0);
239  const double fullSpeedGain = (yFull + (onInsertion ? 1. : 0.)) * ACCEL2SPEED(myTrainParams.decl);
240  return DIST2SPEED(MAX2(0.0, dist - exactGap) / (yFull + 1)) + fullSpeedGain + targetSpeed;
241  } else {
242  WRITE_ERROR("Anything else then semi implicit euler update is not yet implemented. Exiting!");
243  throw ProcessError();
244  }
245 }
246 
247 double MSCFModel_Rail::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
248  return MIN2(maximumSafeStopSpeed(gap, speed, false, TS), maxNextSpeed(speed, veh));
249 }
#define DIST2SPEED(x)
Definition: SUMOTime.h:57
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
TrainParams initRB425Params() const
#define SPEED2DIST(x)
Definition: SUMOTime.h:55
TrainParams initICE1Params() const
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
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:60
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:70
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:40
TrainParams initICE3Params() const
#define TS
Definition: SUMOTime.h:52
TrainParams initNGT400_16Params() const
double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
The car-following model and parameter.
Definition: MSVehicleType.h:74
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:2921
double getMaxSpeedOnLane() const
Returns the maximal speed for the vehicle on its current lane (including speed factor and deviation...
Definition: MSVehicle.h:498
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.
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:59
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:64
#define DEG2RAD(x)
Definition: GeomHelper.h:45
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:482
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:469
virtual ~MSCFModel_Rail()
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
virtual void setMaxDecel(double decel)
Sets a new value for maximum deceleration [m/s^2].
Definition: MSCFModel.h:399
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1145
TrainParams myTrainParams
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:63
double getSlope() const
Returns the slope of the road at vehicle&#39;s position.
Definition: MSVehicle.cpp:766
TrainParams initFreightParams() const
T MIN3(T a, T b, T c)
Definition: StdDefs.h:77
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:442
double getInterpolatedValueFromLookUpMap(double speed, const LookUpMap *lookUpMap) const
#define G