SUMO - Simulation of Urban MObility
MSVehicleType.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // The car-following model and parameter
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
15 /****************************************************************************/
16 //
17 // This file is part of SUMO.
18 // SUMO is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 3 of the License, or
21 // (at your option) any later version.
22 //
23 /****************************************************************************/
24 
25 
26 // ===========================================================================
27 // included modules
28 // ===========================================================================
29 #ifdef _MSC_VER
30 #include <windows_config.h>
31 #else
32 #include <config.h>
33 #endif
34 
35 #include <cassert>
41 #include "MSNet.h"
42 #include "cfmodels/MSCFModel_IDM.h"
52 #include "MSVehicleControl.h"
53 #include "MSVehicleType.h"
54 
55 
56 // ===========================================================================
57 // static members
58 // ===========================================================================
60 
61 
62 // ===========================================================================
63 // method definitions
64 // ===========================================================================
66  : myParameter(parameter), myIndex(myNextIndex++), myCarFollowModel(0), myOriginalType(0) {
67  assert(getLength() > 0);
68  assert(getMaxSpeed() > 0);
69 }
70 
71 
73  delete myCarFollowModel;
74 }
75 
76 
77 double
78 MSVehicleType::computeChosenSpeedDeviation(std::mt19937* rng, const double minDev) const {
79  return MAX2(minDev, myParameter.speedFactor.sample(rng));
80 }
81 
82 
83 // ------------ Setter methods
84 void
85 MSVehicleType::setLength(const double& length) {
86  if (myOriginalType != 0 && length < 0) {
88  } else {
89  myParameter.length = length;
90  }
91 }
92 
93 
94 void
95 MSVehicleType::setHeight(const double& height) {
96  if (myOriginalType != 0 && height < 0) {
98  } else {
99  myParameter.height = height;
100  }
101 }
102 
103 
104 void
105 MSVehicleType::setMinGap(const double& minGap) {
106  if (myOriginalType != 0 && minGap < 0) {
108  } else {
109  myParameter.minGap = minGap;
110  }
111 }
112 
113 
114 void
115 MSVehicleType::setMinGapLat(const double& minGapLat) {
116  if (myOriginalType != 0 && minGapLat < 0) {
118  } else {
119  myParameter.minGapLat = minGapLat;
120  }
121 }
122 
123 
124 void
125 MSVehicleType::setMaxSpeed(const double& maxSpeed) {
126  if (myOriginalType != 0 && maxSpeed < 0) {
128  } else {
129  myParameter.maxSpeed = maxSpeed;
130  }
131 }
132 
133 
134 void
135 MSVehicleType::setMaxSpeedLat(const double& maxSpeedLat) {
136  if (myOriginalType != 0 && maxSpeedLat < 0) {
138  } else {
139  myParameter.maxSpeedLat = maxSpeedLat;
140  }
141 }
142 
143 
144 void
146  myParameter.vehicleClass = vclass;
147 }
148 
149 void
151  myParameter.latAlignment = latAlignment;
152 }
153 
154 
155 void
157  if (myOriginalType != 0 && prob < 0) {
159  } else {
161  }
162 }
163 
164 
165 void
166 MSVehicleType::setSpeedFactor(const double& factor) {
167  if (myOriginalType != 0 && factor < 0) {
169  } else {
170  myParameter.speedFactor.getParameter()[0] = factor;
171  }
172 }
173 
174 
175 void
177  if (myOriginalType != 0 && dev < 0) {
179  } else {
181  }
182 }
183 
184 
185 void
187  myParameter.emissionClass = eclass;
188 }
189 
190 
191 void
193  myParameter.color = color;
194 }
195 
196 
197 void
198 MSVehicleType::setWidth(const double& width) {
199  if (myOriginalType != 0 && width < 0) {
201  } else {
202  myParameter.width = width;
203  }
204 }
205 
206 
207 void
208 MSVehicleType::setImpatience(const double impatience) {
209  if (myOriginalType != 0 && impatience < 0) {
211  } else {
212  myParameter.impatience = impatience;
213  }
214 }
215 
216 
217 void
219  myParameter.shape = shape;
220 }
221 
222 
223 
224 // ------------ Static methods for building vehicle types
227  MSVehicleType* vtype = new MSVehicleType(from);
230  // by default decel and apparentDecel are identical (alternatively, defaults could be used)
231  //const double emergencyDecel = from.getCFParam(SUMO_ATTR_EMERGENCYDECEL, SUMOVTypeParameter::getDefaultEmergencyDecel(from.vehicleClass));
232  const double emergencyDecel = from.getCFParam(SUMO_ATTR_EMERGENCYDECEL, decel);
233  // by default decel and apparentDecel are identical
234  const double apparentDecel = from.getCFParam(SUMO_ATTR_APPARENTDECEL, decel);
235 
236  if (emergencyDecel < decel) {
237  WRITE_WARNING("Value of 'emergencyDecel' is should be higher than 'decel' for vType '" + from.id + "'.");
238  }
239  if (emergencyDecel < apparentDecel) {
240  WRITE_WARNING("Value of 'emergencyDecel' lower than 'apparentDecel' for vType '" + from.id + "' may cause collisions.");
241  }
242 
244  const double tau = from.getCFParam(SUMO_ATTR_TAU, 1.);
245  switch (from.cfModel) {
246  case SUMO_TAG_CF_IDM:
247  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, emergencyDecel, apparentDecel, tau,
250  break;
251  case SUMO_TAG_CF_IDMM:
252  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, emergencyDecel, apparentDecel, tau,
256  break;
257  case SUMO_TAG_CF_BKERNER:
258  vtype->myCarFollowModel = new MSCFModel_Kerner(vtype, accel, decel, emergencyDecel, apparentDecel, tau,
259  from.getCFParam(SUMO_ATTR_K, .5),
261  break;
263  vtype->myCarFollowModel = new MSCFModel_KraussOrig1(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau);
264  break;
266  vtype->myCarFollowModel = new MSCFModel_KraussPS(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau);
267  break;
268  case SUMO_TAG_CF_KRAUSSX:
269  vtype->myCarFollowModel = new MSCFModel_KraussX(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau,
270  from.getCFParam(SUMO_ATTR_TMP1, 0.),
271  from.getCFParam(SUMO_ATTR_TMP2, 0.)
272  );
273  break;
275  vtype->myCarFollowModel = new MSCFModel_SmartSK(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau,
276  from.getCFParam(SUMO_ATTR_TMP1, 1.),
277  from.getCFParam(SUMO_ATTR_TMP2, 1.),
278  from.getCFParam(SUMO_ATTR_TMP3, 1.),
279  from.getCFParam(SUMO_ATTR_TMP4, 1.),
280  from.getCFParam(SUMO_ATTR_TMP5, 1.));
281  break;
282  case SUMO_TAG_CF_DANIEL1:
283  vtype->myCarFollowModel = new MSCFModel_Daniel1(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau,
284  from.getCFParam(SUMO_ATTR_TMP1, 1.),
285  from.getCFParam(SUMO_ATTR_TMP2, 1.),
286  from.getCFParam(SUMO_ATTR_TMP3, 1.),
287  from.getCFParam(SUMO_ATTR_TMP4, 1.),
288  from.getCFParam(SUMO_ATTR_TMP5, 1.));
289  break;
291  vtype->myCarFollowModel = new MSCFModel_PWag2009(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau,
294  break;
296  vtype->myCarFollowModel = new MSCFModel_Wiedemann(vtype, accel, decel, emergencyDecel, apparentDecel,
299  break;
300  case SUMO_TAG_CF_RAIL:
301  vtype->myCarFollowModel = new MSCFModel_Rail(vtype, from.getCFParamString(SUMO_ATTR_TRAIN_TYPE, "NGT400"));
302  break;
303  case SUMO_TAG_CF_KRAUSS:
304  default:
305  vtype->myCarFollowModel = new MSCFModel_Krauss(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau);
306  break;
307  }
308  return vtype;
309 }
310 
311 
313 MSVehicleType::buildSingularType(const std::string& id) const {
314  return duplicateType(id, false);
315 }
316 
317 
319 MSVehicleType::duplicateType(const std::string& id, bool persistent) const {
321  vtype->myParameter.id = id;
323  if (!persistent) {
324  vtype->myOriginalType = this;
325  }
326  if (!MSNet::getInstance()->getVehicleControl().addVType(vtype)) {
327  std::string singular = persistent ? "" : "singular ";
328  throw ProcessError("could not add " + singular + "type " + vtype->getID());
329  }
330  return vtype;
331 }
332 
333 
334 
335 /****************************************************************************/
336 
The Wiedemann Model car-following model.
void setMinGap(const double &minGap)
Set a new value for this type&#39;s minimum gap.
double getMinGap() const
Get the free space in front of vehicles of this class.
SumoXMLTag cfModel
The enum-representation of the car-following model to use.
double getImpatience() const
Returns this type&#39;s impatience.
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const =0
Duplicates the car-following model.
car-following model by B. Kerner
double impatience
The vehicle&#39;s impatience (willingness to obstruct others)
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 setShape(SUMOVehicleShape shape)
Set a new value for this type&#39;s shape.
SUMOVehicleShape shape
This class&#39; shape.
Structure representing possible vehicle parameter.
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:48
Krauss car-following model, changing accel and speed by slope.
SUMOVehicleClass vehicleClass
The vehicle&#39;s class.
double getDefaultProbability() const
Get the default probability of this vehicle type.
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:169
T MAX2(T a, T b)
Definition: StdDefs.h:74
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
const MSVehicleType * myOriginalType
The original type.
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.
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:200
The car-following model and parameter.
Definition: MSVehicleType.h:73
static double getDefaultAccel(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default acceleration for the given vehicle class This needs to be a function because the ...
double height
This class&#39; height.
double computeChosenSpeedDeviation(std::mt19937 *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
static double getDefaultImperfection(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default driver&#39;s imperfection (sigma or epsilon in Krauss&#39; model) for the given vehicle c...
void setMinGapLat(const double &minGapLat)
Set a new value for this type&#39;s minimum lataral gap.
double maxSpeed
The vehicle type&#39;s maximum speed [m/s].
double width
This class&#39; width.
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.
double getHeight() const
Get the height which vehicles of this class shall have when being drawn.
The original Krauss (1998) car-following model and parameter.
int SUMOEmissionClass
void setHeight(const double &height)
Set a new value for this type&#39;s height.
virtual ~MSVehicleType()
Destructor.
double sample(std::mt19937 *which=0) const
Draw a sample of the distribution.
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 getWidth() const
Get the width which vehicles of this class shall have when being drawn.
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.
Scalable model based on Krauss by Peter Wagner.
double maxSpeedLat
The vehicle type&#39;s maximum lateral speed [m/s].
The original Krauss (1998) car-following model and parameter.
SUMOVTypeParameter myParameter
the parameter container
double getMinGapLat() const
Get the minimum lateral gap that vehicles of this type maintain.
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.
MSCFModel * myCarFollowModel
instance of the car following model.
double getLength() const
Get vehicle&#39;s length [m].
double minGapLat
The vehicle type&#39;s minimum lateral gap [m].
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
RGBColor color
The color.
static int myNextIndex
next value for the running index
void setWidth(const double &width)
Set a new value for this type&#39;s width.
const std::string & getID() const
Returns the name of the vehicle type.
std::string id
The vehicle type&#39;s id.
MSVehicleType(const SUMOVTypeParameter &parameter)
Constructor.
MSVehicleType * buildSingularType(const std::string &id) const
Duplicates the microsim vehicle type giving the newly created type the given id, marking it as vehicl...
void setVClass(SUMOVehicleClass vclass)
Set a new value for this type&#39;s vehicle class.
LateralAlignment latAlignment
The vehicles desired lateral alignment.
double minGap
This class&#39; free space in front of the vehicle itself.
void setColor(const RGBColor &color)
Set a new value for this type&#39;s color.
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.
MSVehicleType * duplicateType(const std::string &id, bool persistent) const
Duplicates the microsim vehicle type giving the newly created type the given id.
double getMaxSpeedLat() const
Get vehicle&#39;s maximum lateral speed [m/s].
Krauss car-following model, changing accel and speed by slope.
Distribution_Parameterized speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street...
double length
The physical vehicle length.
SUMOEmissionClass emissionClass
The emission class of this vehicle.