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  :
40 
41  MSCFModel(vtype, -1, -1, -1, -1, 1) {
42 
43  if (trainType.compare("RB425") == 0) {
45  } else if (trainType.compare("RB628") == 0) {
47  } else if (trainType.compare("NGT400") == 0) {
49  } else if (trainType.compare("NGT400_16") == 0) {
51  } else if (trainType.compare("ICE1") == 0) {
53  } else if (trainType.compare("REDosto7") == 0) {
55  } else if (trainType.compare("Freight") == 0) {
57  } else if (trainType.compare("ICE3") == 0) {
59  } else {
60  WRITE_ERROR("Unknown train type: " + trainType + ". Exiting!");
61  throw ProcessError();
62  }
64 
65 }
66 
68 }
69 
70 double MSCFModel_Rail::followSpeed(const MSVehicle* const veh, double speed, double /* gap2pred*/,
71  double /* predSpeed */, double /* predMaxDecel*/) const {
72  return maxNextSpeed(speed, veh);
73 }
74 
75 int
77  return SUMO_TAG_CF_RAIL;
78 }
79 
80 MSCFModel*
81 MSCFModel_Rail::duplicate(const MSVehicleType* /* vtype */) const {
83  throw ProcessError("not yet implemented");
84 }
85 
86 double MSCFModel_Rail::maxNextSpeed(double speed, const MSVehicle* const veh) const {
87 
88  if (speed >= myTrainParams.vmax) {
89  return myTrainParams.vmax;
90  }
91 
92  double targetSpeed = myTrainParams.vmax;
93 
94  double res = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.resistance)); // kN
95 
96  double slope = veh->getSlope();
97  double gr = myTrainParams.weight * G * sin(DEG2RAD(slope)); //kN
98 
99  double totalRes = res + gr; //kN
100 
101  double trac = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.traction)); // kN
102 
103  double a;
104  if (speed < targetSpeed) {
105  a = (trac - totalRes) / myTrainParams.rotWeight; //kN/t == N/kg
106  } else {
107  a = 0.;
108  if (totalRes > trac) {
109  a = (trac - totalRes) / myTrainParams.rotWeight; //kN/t == N/kg
110  }
111  }
112 
113  double maxNextSpeed = speed + a * DELTA_T / 1000.;
114 
115 // std::cout << veh->getID() << " speed: " << (speed*3.6) << std::endl;
116 
117  return maxNextSpeed;
118 }
119 
120 double MSCFModel_Rail::minNextSpeed(double speed, const MSVehicle* const veh) const {
121 
122  double slope = veh->getSlope();
123  double gr = myTrainParams.weight * G * sin(DEG2RAD(slope)); //kN
124  double res = getInterpolatedValueFromLookUpMap(speed, &(myTrainParams.resistance)); // kN
125  double totalRes = res + gr; //kN
126 
127 
128  double a = myTrainParams.decl + totalRes / myTrainParams.rotWeight;
129 
130  return speed - a * DELTA_T / 1000.;
131 
132 }
133 
134 double MSCFModel_Rail::getInterpolatedValueFromLookUpMap(double speed, const LookUpMap* lookUpMap) const {
135  std::map<double, double>::const_iterator low, prev;
136  low = lookUpMap->lower_bound(speed);
137 
138  if (low == lookUpMap->end()) { //speed > max speed
139  return (lookUpMap->rbegin())->second;
140  }
141 
142  if (low == lookUpMap->begin()) {
143  return low->second;
144  }
145 
146  prev = low;
147  --prev;
148 
149  double range = low->first - prev->first;
150  double dist = speed - prev->first;
151  assert(range > 0);
152  assert(dist > 0);
153 
154  double weight = dist / range;
155 
156  double res = (1 - weight) * prev->second + weight * low->second;
157 
158  return res;
159 
160 }
161 
162 
163 
164 //void
165 //MSCFModel_Rail::initVehicleVariables(const MSVehicle *const veh, MSCFModel_Rail::VehicleVariables *pVariables) const {
166 //
167 // pVariables->setInitialized();
168 //
169 //}
170 
171 double MSCFModel_Rail::getSpeedAfterMaxDecel(double /* speed */) const {
172 
173 // //TODO: slope not known here
174 // double gr = 0; //trainParams.weight * 9.81 * edge.grade
175 //
176 // double a = 0;//trainParams.decl - gr/trainParams.rotWeight;
177 //
178 // return speed + a * DELTA_T / 1000.;
179  WRITE_ERROR("function call not allowd for rail model. Exiting!");
180  throw ProcessError();
181 }
182 
184  VehicleVariables* ret = new VehicleVariables();
185  return ret;
186 }
187 
188 
189 double MSCFModel_Rail::moveHelper(MSVehicle* const veh, double vPos) const {
190  const double oldV = veh->getSpeed(); // save old v for optional acceleration computation
191  const double vSafe = MIN2(vPos, veh->processNextStop(vPos)); // process stops
192  const double vMin = minNextSpeed(oldV, veh);
193  const double vMax = MAX2(vMin, MIN3(veh->getMaxSpeedOnLane(), maxNextSpeed(oldV, veh), vSafe));
194  const double vNext = veh->getLaneChangeModel().patchSpeed(vMin, vMax, vMax, *this);
195  return vNext;
196 }
197 
198 double MSCFModel_Rail::freeSpeed(const MSVehicle* const /* veh */, double /* speed */, double dist, double targetSpeed,
199  const bool onInsertion) const {
200 
201 // MSCFModel_Rail::VehicleVariables *vars = (MSCFModel_Rail::VehicleVariables *) veh->getCarFollowVariables();
202 // if (vars->isNotYetInitialized()) {
203 // initVehicleVariables(veh, vars);
204 // }
205 
206  //TODO: signals, coasting, ...
207 
209  // adapt speed to succeeding lane, no reaction time is involved
210  // when breaking for y steps the following distance g is covered
211  // (drive with v in the final step)
212  // g = (y^2 + y) * 0.5 * b + y * v
213  // y = ((((sqrt((b + 2.0*v)*(b + 2.0*v) + 8.0*b*g)) - b)*0.5 - v)/b)
214  const double v = SPEED2DIST(targetSpeed);
215  if (dist < v) {
216  return targetSpeed;
217  }
218  const double b = ACCEL2DIST(myDecel);
219  const double y = MAX2(0.0, ((sqrt((b + 2.0 * v) * (b + 2.0 * v) + 8.0 * b * dist) - b) * 0.5 - v) / b);
220  const double yFull = floor(y);
221  const double exactGap = (yFull * yFull + yFull) * 0.5 * b + yFull * v + (y > yFull ? v : 0.0);
222  const double fullSpeedGain = (yFull + (onInsertion ? 1. : 0.)) * ACCEL2SPEED(myTrainParams.decl);
223  return DIST2SPEED(MAX2(0.0, dist - exactGap) / (yFull + 1)) + fullSpeedGain + targetSpeed;
224  } else {
225  WRITE_ERROR("Anything else then semi implicit euler update is not yet implemented. Exiting!");
226  throw ProcessError();
227  }
228 }
229 
230 double MSCFModel_Rail::stopSpeed(const MSVehicle* const veh, const double speed, double gap) const {
231  return MIN2(maximumSafeStopSpeed(gap, speed, false, TS), maxNextSpeed(speed, veh));
232 }
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const
Duplicates the car-following model.
#define DIST2SPEED(x)
Definition: SUMOTime.h:57
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
TrainParams initFreightParams() const
#define SPEED2DIST(x)
Definition: SUMOTime.h:55
#define ACCEL2SPEED(x)
Definition: SUMOTime.h:61
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...
The car-following model abstraction.
Definition: MSCFModel.h:60
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:604
TrainParams initRB628Params() const
std::map< double, double > LookUpMap
MSCFModel::VehicleVariables * createVehicleVariables() const
Returns model specific values which are stored inside a vehicle and must be used with casting...
T MAX2(T a, T b)
Definition: StdDefs.h:74
SUMOTime DELTA_T
Definition: SUMOTime.cpp:40
virtual int getModelID() const
Returns the model&#39;s ID; the XML-Tag number is used.
#define TS
Definition: SUMOTime.h:52
TrainParams initRB425Params() const
The car-following model and parameter.
Definition: MSVehicleType.h:73
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:3144
double getSlope() const
Returns the slope of the road at vehicle&#39;s position.
Definition: MSVehicle.cpp:795
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.
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
#define ACCEL2DIST(x)
Definition: SUMOTime.h:59
TrainParams initNGT400Params() const
TrainParams initNGT400_16Params() const
TrainParams initICE1Params() const
T MIN2(T a, T b)
Definition: StdDefs.h:68
double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
#define DEG2RAD(x)
Definition: GeomHelper.h:45
double myDecel
The vehicle&#39;s maximum deceleration [m/s^2].
Definition: MSCFModel.h:527
virtual ~MSCFModel_Rail()
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
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.
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) ...
TrainParams initICE3Params() const
double getMaxSpeedOnLane() const
Returns the maximal speed for the vehicle on its current lane (including speed factor and deviation...
Definition: MSVehicle.h:509
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:441
double processNextStop(double currentVelocity)
Processes stops, returns the velocity needed to reach the stop.
Definition: MSVehicle.cpp:1284
TrainParams myTrainParams
double moveHelper(MSVehicle *const veh, double vPos) const
Applies interaction with stops and lane changing model influences.
double getInterpolatedValueFromLookUpMap(double speed, const LookUpMap *lookUpMap) const
double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle&#39;s follow speed (no dawdling)
static bool gSemiImplicitEulerUpdate
Definition: MSGlobals.h:63
T MIN3(T a, T b, T c)
Definition: StdDefs.h:81
MSCFModel_Rail(const MSVehicleType *vtype, std::string trainType)
Constructor.
TrainParams initREDosto7Params() const
#define G
double getSpeed() const
Returns the vehicle&#39;s current speed.
Definition: MSVehicle.h:443