SUMO - Simulation of Urban MObility
MSVehicleType.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-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 /****************************************************************************/
19 // The car-following model and parameter
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <cassert>
36 #include "MSNet.h"
37 #include "cfmodels/MSCFModel_IDM.h"
47 #include "cfmodels/MSCFModel_ACC.h"
48 #include "MSVehicleControl.h"
49 #include "MSVehicleType.h"
50 
51 
52 // ===========================================================================
53 // static members
54 // ===========================================================================
56 
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
62  : myParameter(parameter), myWarnedActionStepLengthTauOnce(false), myIndex(myNextIndex++), myCarFollowModel(0), myOriginalType(0) {
63  assert(getLength() > 0);
64  assert(getMaxSpeed() > 0);
65 
66  // Check if actionStepLength was set by user, if not init to global default
69  }
71 }
72 
73 
75  delete myCarFollowModel;
76 }
77 
78 
79 double
80 MSVehicleType::computeChosenSpeedDeviation(std::mt19937* rng, const double minDev) const {
81  return MAX2(minDev, myParameter.speedFactor.sample(rng));
82 }
83 
84 
85 // ------------ Setter methods
86 void
87 MSVehicleType::setLength(const double& length) {
88  if (myOriginalType != 0 && length < 0) {
90  } else {
91  myParameter.length = length;
92  }
94 }
95 
96 
97 void
98 MSVehicleType::setHeight(const double& height) {
99  if (myOriginalType != 0 && height < 0) {
101  } else {
102  myParameter.height = height;
103  }
105 }
106 
107 
108 void
109 MSVehicleType::setMinGap(const double& minGap) {
110  if (myOriginalType != 0 && minGap < 0) {
112  } else {
113  myParameter.minGap = minGap;
114  }
116 }
117 
118 
119 void
120 MSVehicleType::setMinGapLat(const double& minGapLat) {
121  if (myOriginalType != 0 && minGapLat < 0) {
123  } else {
124  myParameter.minGapLat = minGapLat;
125  }
127 }
128 
129 
130 void
131 MSVehicleType::setMaxSpeed(const double& maxSpeed) {
132  if (myOriginalType != 0 && maxSpeed < 0) {
134  } else {
135  myParameter.maxSpeed = maxSpeed;
136  }
138 }
139 
140 
141 void
142 MSVehicleType::setMaxSpeedLat(const double& maxSpeedLat) {
143  if (myOriginalType != 0 && maxSpeedLat < 0) {
145  } else {
146  myParameter.maxSpeedLat = maxSpeedLat;
147  }
149 }
150 
151 
152 void
154  myParameter.vehicleClass = vclass;
156 }
157 
158 void
160  myParameter.latAlignment = latAlignment;
162 }
163 
164 
165 void
167  if (myOriginalType != 0 && prob < 0) {
169  } else {
171  }
173 }
174 
175 
176 void
177 MSVehicleType::setSpeedFactor(const double& factor) {
178  if (myOriginalType != 0 && factor < 0) {
180  } else {
181  myParameter.speedFactor.getParameter()[0] = factor;
182  }
184 }
185 
186 
187 void
189  if (myOriginalType != 0 && dev < 0) {
191  } else {
193  }
195 }
196 
197 
198 void
199 MSVehicleType::setActionStepLength(const SUMOTime actionStepLength, bool resetActionOffset) {
200  assert(actionStepLength >= 0.);
202 
203  if (myParameter.actionStepLength == actionStepLength) {
204  return;
205  }
206 
207  SUMOTime previousActionStepLength = myParameter.actionStepLength;
208  myParameter.actionStepLength = actionStepLength;
210  check();
211 
212  if (isVehicleSpecific()) {
213  // don't perform vehicle lookup for singular vtype
214  return;
215  }
216 
217  // For non-singular vType reset all vehicle's actionOffsets
218  // Iterate through vehicles
220  for (auto vehIt = vc.loadedVehBegin(); vehIt != vc.loadedVehEnd(); ++vehIt) {
221  MSVehicle* veh = static_cast<MSVehicle*>(vehIt->second);
222  if (&veh->getVehicleType() == this) {
223  // Found vehicle of this type. Perform requested actionOffsetReset
224  if (resetActionOffset) {
225  veh->resetActionOffset();
226  } else {
227  veh->updateActionOffset(previousActionStepLength, actionStepLength);
228  }
229  }
230  }
231 }
232 
233 
234 void
236  myParameter.emissionClass = eclass;
238 }
239 
240 
241 void
243  myParameter.color = color;
245 }
246 
247 
248 void
249 MSVehicleType::setWidth(const double& width) {
250  if (myOriginalType != 0 && width < 0) {
252  } else {
253  myParameter.width = width;
254  }
256 }
257 
258 void
259 MSVehicleType::setImpatience(const double impatience) {
260  if (myOriginalType != 0 && impatience < 0) {
262  } else {
263  myParameter.impatience = impatience;
264  }
266 }
267 
268 
269 void
271  myParameter.shape = shape;
273 }
274 
275 
276 
277 // ------------ Static methods for building vehicle types
280  MSVehicleType* vtype = new MSVehicleType(from);
282  const double emergencyDecel = from.getCFParam(SUMO_ATTR_EMERGENCYDECEL, SUMOVTypeParameter::getDefaultEmergencyDecel(from.vehicleClass, decel));
283  // by default decel and apparentDecel are identical
284  const double apparentDecel = from.getCFParam(SUMO_ATTR_APPARENTDECEL, decel);
285 
286  if (emergencyDecel < decel) {
287  WRITE_WARNING("Value of 'emergencyDecel' (" + toString(emergencyDecel) + ") should be higher than 'decel' (" + toString(decel) + ") for vType '" + from.id + "'.");
288  }
289  if (emergencyDecel < apparentDecel) {
290  WRITE_WARNING("Value of 'emergencyDecel' (" + toString(emergencyDecel) + ") is lower than 'apparentDecel' (" + toString(apparentDecel) + ") for vType '" + from.id + "' may cause collisions.");
291  }
292 
293  switch (from.cfModel) {
294  case SUMO_TAG_CF_IDM:
295  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, false);
296  break;
297  case SUMO_TAG_CF_IDMM:
298  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, true);
299  break;
300  case SUMO_TAG_CF_BKERNER:
301  vtype->myCarFollowModel = new MSCFModel_Kerner(vtype);
302  break;
304  vtype->myCarFollowModel = new MSCFModel_KraussOrig1(vtype);
305  break;
307  vtype->myCarFollowModel = new MSCFModel_KraussPS(vtype);
308  break;
309  case SUMO_TAG_CF_KRAUSSX:
310  vtype->myCarFollowModel = new MSCFModel_KraussX(vtype);
311  break;
313  vtype->myCarFollowModel = new MSCFModel_SmartSK(vtype);
314  break;
315  case SUMO_TAG_CF_DANIEL1:
316  vtype->myCarFollowModel = new MSCFModel_Daniel1(vtype);
317  break;
319  vtype->myCarFollowModel = new MSCFModel_PWag2009(vtype);
320  break;
322  vtype->myCarFollowModel = new MSCFModel_Wiedemann(vtype);
323  break;
324  case SUMO_TAG_CF_RAIL:
325  vtype->myCarFollowModel = new MSCFModel_Rail(vtype);
326  break;
327  case SUMO_TAG_CF_ACC:
328  vtype->myCarFollowModel = new MSCFModel_ACC(vtype);
329  break;
330  case SUMO_TAG_CF_KRAUSS:
331  default:
332  vtype->myCarFollowModel = new MSCFModel_Krauss(vtype);
333  break;
334  }
335  vtype->check();
336  return vtype;
337 }
338 
339 
341 MSVehicleType::buildSingularType(const std::string& id) const {
342  return duplicateType(id, false);
343 }
344 
345 
347 MSVehicleType::duplicateType(const std::string& id, bool persistent) const {
349  vtype->myParameter.id = id;
351  if (!persistent) {
352  vtype->myOriginalType = this;
353  }
354  if (!MSNet::getInstance()->getVehicleControl().addVType(vtype)) {
355  std::string singular = persistent ? "" : "singular ";
356  throw ProcessError("could not add " + singular + "type " + vtype->getID());
357  }
358  return vtype;
359 }
360 
361 void
367  std::stringstream s;
368  s << "Given action step length " << STEPS2TIME(myParameter.actionStepLength) << " for vehicle type '" << getID()
369  << "' is larger than its parameter tau (=" << getCarFollowModel().getHeadwayTime() << ")!"
370  << " This may lead to collisions. (This warning is only issued once per vehicle type).";
371  WRITE_WARNING(s.str());
372  }
373 }
374 
375 void
376 MSVehicleType::setAccel(double accel) {
377  if (myOriginalType != 0 && accel < 0) {
379  }
382 }
383 
384 void
385 MSVehicleType::setDecel(double decel) {
386  if (myOriginalType != 0 && decel < 0) {
388  }
391 }
392 
393 void
394 MSVehicleType::setEmergencyDecel(double emergencyDecel) {
395  if (myOriginalType != 0 && emergencyDecel < 0) {
396  emergencyDecel = myOriginalType->getCarFollowModel().getEmergencyDecel();
397  }
398  myCarFollowModel->setEmergencyDecel(emergencyDecel);
400 }
401 
402 void
403 MSVehicleType::setApparentDecel(double apparentDecel) {
404  if (myOriginalType != 0 && apparentDecel < 0) {
406  }
407  myCarFollowModel->setApparentDecel(apparentDecel);
409 }
410 
411 void
412 MSVehicleType::setImperfection(double imperfection) {
413  if (myOriginalType != 0 && imperfection < 0) {
415  }
416  myCarFollowModel->setImperfection(imperfection);
418 }
419 
420 void
422  if (myOriginalType != 0 && tau < 0) {
424  }
427 }
428 
429 
430 /****************************************************************************/
431 
const int VTYPEPARS_MAXSPEED_SET
The Wiedemann Model car-following model.
double getApparentDecel() const
Get the vehicle type&#39;s apparent deceleration [m/s^2] (the one regarded by its followers.
Definition: MSCFModel.h:234
const int VTYPEPARS_MINGAP_SET
void setMinGap(const double &minGap)
Set a new value for this type&#39;s minimum gap.
SumoXMLTag cfModel
The enum-representation of the car-following model to use.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
const int VTYPEPARS_LATALIGNMENT_SET
long long int SUMOTime
Definition: SUMOTime.h:36
car-following model by B. Kerner
double impatience
The vehicle&#39;s impatience (willingness to obstruct others)
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
void setDefaultProbability(const double &prob)
Set a new value for this type&#39;s default probability.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
void setTau(double tau)
Set a new value for this type&#39;s headway.
void setShape(SUMOVehicleShape shape)
Set a new value for this type&#39;s shape.
SUMOVehicleShape shape
This class&#39; shape.
Structure representing possible vehicle parameter.
const int VTYPEPARS_MINGAP_LAT_SET
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const =0
Duplicates the car-following model.
virtual double getImperfection() const
Get the driver&#39;s imperfection.
Definition: MSCFModel.h:245
double defaultProbability
The probability when being added to a distribution without an explicit probability.
std::vector< double > & getParameter()
Returns the parameters of this distribution.
The Intelligent Driver Model (IDM) car-following model.
Definition: MSCFModel_IDM.h:41
void setDecel(double decel)
Set a new value for this type&#39;s deceleration.
Krauss car-following model, changing accel and speed by slope.
SUMOVehicleClass vehicleClass
The vehicle&#39;s class.
The original Krauss (1998) car-following model and parameter.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:160
T MAX2(T a, T b)
Definition: StdDefs.h:68
double getMinGapLat() const
Get the minimum lateral gap that vehicles of this type maintain.
const MSVehicleType * myOriginalType
The original type.
void setApparentDecel(double apparentDecel)
Set a new value for this type&#39;s apparent deceleration.
void setLength(const double &length)
Set a new value for this type&#39;s length.
void setMaxSpeed(const double &maxSpeed)
Set a new value for this type&#39;s maximum speed.
const int VTYPEPARS_MAXSPEED_LAT_SET
const int VTYPEPARS_PROBABILITY_SET
void setImperfection(double imperfection)
Set a new value for this type&#39;s imperfection.
MSVehicleType * duplicateType(const std::string &id, bool persistent) const
Duplicates the microsim vehicle type giving the newly created type the given id.
virtual void setApparentDecel(double decel)
Sets a new value for the apparent deceleration [m/s^2].
Definition: MSCFModel.h:484
static MSVehicleType * build(SUMOVTypeParameter &from)
Builds the microsim vehicle type described by the given parameter.
LateralAlignment
Numbers representing special SUMO-XML-attribute values Information how vehicles align themselves with...
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:242
The car-following model and parameter.
Definition: MSVehicleType.h:66
double height
This class&#39; height.
bool isVehicleSpecific() const
Returns whether this type belongs to a single vehicle only (was modified)
double getMaxAccel() const
Get the vehicle type&#39;s maximum acceleration [m/s^2].
Definition: MSCFModel.h:210
double getDefaultProbability() const
Get the default probability of this vehicle type.
void setMinGapLat(const double &minGapLat)
Set a new value for this type&#39;s minimum lataral gap.
bool wasSet(int what) const
Returns whether the given parameter was set.
double maxSpeed
The vehicle type&#39;s maximum speed [m/s].
double width
This class&#39; width.
const MSCFModel & getCarFollowModel() const
Returns the vehicle type&#39;s car following model definition (const version)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
const int VTYPEPARS_ACTIONSTEPLENGTH_SET
void setAccel(double accel)
Set a new value for this type&#39;s acceleration.
void check()
Checks whether vehicle type parameters may be problematic (Currently, only the value for the action s...
MSVehicleType * buildSingularType(const std::string &id) const
Duplicates the microsim vehicle type giving the newly created type the given id, marking it as vehicl...
The original Krauss (1998) car-following model and parameter.
int SUMOEmissionClass
double getEmergencyDecel() const
Get the vehicle type&#39;s maximal phisically possible deceleration [m/s^2].
Definition: MSCFModel.h:226
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:309
virtual void setHeadwayTime(double headwayTime)
Sets a new value for desired headway [s].
Definition: MSCFModel.h:500
void setHeight(const double &height)
Set a new value for this type&#39;s height.
The ACC car-following model.
Definition: MSCFModel_ACC.h:48
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
virtual ~MSVehicleType()
Destructor.
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
void resetActionOffset(const SUMOTime timeUntilNextAction=0)
Resets the action offset for the vehicle.
Definition: MSVehicle.cpp:1699
void setImpatience(const double impatience)
Set a new value for this type&#39;s impatience.
static double getDefaultDecel(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default deceleration for the given vehicle class This needs to be a function because the ...
void setEmissionClass(SUMOEmissionClass eclass)
Set a new value for this type&#39;s emission class.
double getMinGap() const
Get the free space in front of vehicles of this class.
double getMaxDecel() const
Get the vehicle type&#39;s maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:218
void setSpeedDeviation(const double &dev)
Set a new value for this type&#39;s speed deviation.
void setSpeedFactor(const double &factor)
Set a new value for this type&#39;s speed factor.
const int VTYPEPARS_SPEEDFACTOR_SET
void setActionStepLength(const SUMOTime actionStepLength, bool resetActionOffset)
Set a new value for this type&#39;s action step length.
Scalable model based on Krauss by Peter Wagner.
double maxSpeedLat
The vehicle type&#39;s maximum lateral speed [m/s].
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.
int parametersSet
Information for the router which parameter were set.
The original Krauss (1998) car-following model and parameter.
SUMOVTypeParameter myParameter
the parameter container
double getMaxSpeedLat() const
Get vehicle&#39;s maximum lateral speed [m/s].
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
MSCFModel * myCarFollowModel
instance of the car following model.
double getHeight() const
Get the height which vehicles of this class shall have when being drawn.
static SUMOTime gActionStepLength
default value for the interval between two action points for MSVehicle (defaults to DELTA_T) ...
Definition: MSGlobals.h:112
double minGapLat
The vehicle type&#39;s minimum lateral gap [m].
void setEmergencyDecel(double emergencyDecel)
Set a new value for this type&#39;s emergency deceleration.
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
Definition: MSCFModel.h:468
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
virtual void setMaxAccel(double accel)
Sets a new value for maximum acceleration [m/s^2].
Definition: MSCFModel.h:460
virtual double getHeadwayTime() const
Get the driver&#39;s desired headway [s].
Definition: MSCFModel.h:253
virtual void setImperfection(double imperfection)
Sets a new value for driver imperfection.
Definition: MSCFModel.h:492
SubParams cfParameter
Car-following parameter.
RGBColor color
The color.
static int myNextIndex
next value for the running index
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
void setWidth(const double &width)
Set a new value for this type&#39;s width.
std::string id
The vehicle type&#39;s id.
void updateActionOffset(const SUMOTime oldActionStepLength, const SUMOTime newActionStepLength)
Process an updated action step length value (only affects the vehicle&#39;s action offset, The actionStepLength is stored in the (singular) vtype)
Definition: MSVehicle.cpp:1704
double getLength() const
Get vehicle&#39;s length [m].
MSVehicleType(const SUMOVTypeParameter &parameter)
Constructor.
void setVClass(SUMOVehicleClass vclass)
Set a new value for this type&#39;s vehicle class.
LateralAlignment latAlignment
The vehicles desired lateral alignment.
SUMOTime actionStepLength
The vehicle type&#39;s default actionStepLength [ms], i.e. the interval between two control actions...
double minGap
This class&#39; free space in front of the vehicle itself.
const int VTYPEPARS_HEIGHT_SET
void setColor(const RGBColor &color)
Set a new value for this type&#39;s color.
static double getDefaultEmergencyDecel(const SUMOVehicleClass vc, double decel)
Returns the default emergency deceleration for the given vehicle class This needs to be a function be...
double sample(std::mt19937 *which=0) const
Draw a sample of the distribution.
virtual void setEmergencyDecel(double decel)
Sets a new value for maximal physically possible deceleration [m/s^2].
Definition: MSCFModel.h:476
bool myWarnedActionStepLengthTauOnce
Indicator whether the user was already warned once about an action step length larger than the desire...
const int VTYPEPARS_WIDTH_SET
double getImpatience() const
Returns this type&#39;s impatience.
The class responsible for building and deletion of vehicles.
double computeChosenSpeedDeviation(std::mt19937 *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
void setMaxSpeedLat(const double &maxSpeedLat)
Set a new value for this type&#39;s maximum lateral speed.
void setPreferredLateralAlignment(LateralAlignment latAlignment)
Set vehicle&#39;s preferred lateral alignment.
Krauss car-following model, with acceleration decrease and faster start.
const int VTYPEPARS_LENGTH_SET
const int VTYPEPARS_VEHICLECLASS_SET
Krauss car-following model, changing accel and speed by slope.
const int VTYPEPARS_EMISSIONCLASS_SET
const int VTYPEPARS_COLOR_SET
Distribution_Parameterized speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street...
const int VTYPEPARS_SHAPE_SET
double length
The physical vehicle length.
SUMOEmissionClass emissionClass
The emission class of this vehicle.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
double myCachedActionStepLengthSecs
the vtypes actionsStepLength in seconds (cached because needed very often)
const int VTYPEPARS_IMPATIENCE_SET