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 "MSVehicleType.h"
53 
54 
55 // ===========================================================================
56 // static members
57 // ===========================================================================
59 
60 
61 // ===========================================================================
62 // method definitions
63 // ===========================================================================
65  : myParameter(parameter), myIndex(myNextIndex++), myCarFollowModel(0), myOriginalType(0) {
66  assert(getLength() > 0);
67  assert(getMaxSpeed() > 0);
68 }
69 
70 
72  delete myCarFollowModel;
73 }
74 
75 
76 double
77 MSVehicleType::computeChosenSpeedDeviation(MTRand* rng, const double minDev) const {
78  return MAX2(minDev, myParameter.speedFactor.sample(rng));
79 }
80 
81 
82 // ------------ Setter methods
83 void
84 MSVehicleType::setLength(const double& length) {
85  if (myOriginalType != 0 && length < 0) {
87  } else {
88  myParameter.length = length;
89  }
90 }
91 
92 
93 void
94 MSVehicleType::setHeight(const double& height) {
95  if (myOriginalType != 0 && height < 0) {
97  } else {
98  myParameter.height = height;
99  }
100 }
101 
102 
103 void
104 MSVehicleType::setMinGap(const double& minGap) {
105  if (myOriginalType != 0 && minGap < 0) {
107  } else {
108  myParameter.minGap = minGap;
109  }
110 }
111 
112 
113 void
114 MSVehicleType::setMinGapLat(const double& minGapLat) {
115  if (myOriginalType != 0 && minGapLat < 0) {
117  } else {
118  myParameter.minGapLat = minGapLat;
119  }
120 }
121 
122 
123 void
124 MSVehicleType::setMaxSpeed(const double& maxSpeed) {
125  if (myOriginalType != 0 && maxSpeed < 0) {
127  } else {
128  myParameter.maxSpeed = maxSpeed;
129  }
130 }
131 
132 
133 void
134 MSVehicleType::setMaxSpeedLat(const double& maxSpeedLat) {
135  if (myOriginalType != 0 && maxSpeedLat < 0) {
137  } else {
138  myParameter.maxSpeedLat = maxSpeedLat;
139  }
140 }
141 
142 
143 void
145  myParameter.vehicleClass = vclass;
146 }
147 
148 void
150  myParameter.latAlignment = latAlignment;
151 }
152 
153 
154 void
156  if (myOriginalType != 0 && prob < 0) {
158  } else {
160  }
161 }
162 
163 
164 void
165 MSVehicleType::setSpeedFactor(const double& factor) {
166  if (myOriginalType != 0 && factor < 0) {
168  } else {
169  myParameter.speedFactor.getParameter()[0] = factor;
170  }
171 }
172 
173 
174 void
176  if (myOriginalType != 0 && dev < 0) {
178  } else {
180  }
181 }
182 
183 
184 void
186  myParameter.emissionClass = eclass;
187 }
188 
189 
190 void
192  myParameter.color = color;
193 }
194 
195 
196 void
197 MSVehicleType::setWidth(const double& width) {
198  if (myOriginalType != 0 && width < 0) {
200  } else {
201  myParameter.width = width;
202  }
203 }
204 
205 
206 void
207 MSVehicleType::setImpatience(const double impatience) {
208  if (myOriginalType != 0 && impatience < 0) {
210  } else {
211  myParameter.impatience = impatience;
212  }
213 }
214 
215 
216 void
218  myParameter.shape = shape;
219 }
220 
221 
222 
223 // ------------ Static methods for building vehicle types
226  MSVehicleType* vtype = new MSVehicleType(from);
229 // const double emergencyDecel = from.getCFParam(SUMO_ATTR_EMERGENCYDECEL, SUMOVTypeParameter::getDefaultEmergencyDecel(from.vehicleClass));
230  const double emergencyDecel = from.getCFParam(SUMO_ATTR_EMERGENCYDECEL, decel);
231  // by default decel and apparentDecel are identical
232  const double apparentDecel = from.getCFParam(SUMO_ATTR_APPARENTDECEL, decel);
233 
235  const double tau = from.getCFParam(SUMO_ATTR_TAU, 1.);
236  switch (from.cfModel) {
237  case SUMO_TAG_CF_IDM:
238  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, emergencyDecel, tau,
241  break;
242  case SUMO_TAG_CF_IDMM:
243  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, emergencyDecel, tau,
247  break;
248  case SUMO_TAG_CF_BKERNER:
249  vtype->myCarFollowModel = new MSCFModel_Kerner(vtype, accel, decel, emergencyDecel, tau,
250  from.getCFParam(SUMO_ATTR_K, .5),
252  break;
254  vtype->myCarFollowModel = new MSCFModel_KraussOrig1(vtype, accel, decel, emergencyDecel, decel, sigma, tau);
255  break;
257  vtype->myCarFollowModel = new MSCFModel_KraussPS(vtype, accel, decel, emergencyDecel, sigma, tau);
258  break;
259  case SUMO_TAG_CF_KRAUSSX:
260  vtype->myCarFollowModel = new MSCFModel_KraussX(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau,
261  from.getCFParam(SUMO_ATTR_TMP1, 0.),
262  from.getCFParam(SUMO_ATTR_TMP2, 0.)
263  );
264  break;
266  vtype->myCarFollowModel = new MSCFModel_SmartSK(vtype, accel, decel, emergencyDecel, sigma, tau,
267  from.getCFParam(SUMO_ATTR_TMP1, 1.),
268  from.getCFParam(SUMO_ATTR_TMP2, 1.),
269  from.getCFParam(SUMO_ATTR_TMP3, 1.),
270  from.getCFParam(SUMO_ATTR_TMP4, 1.),
271  from.getCFParam(SUMO_ATTR_TMP5, 1.));
272  break;
273  case SUMO_TAG_CF_DANIEL1:
274  vtype->myCarFollowModel = new MSCFModel_Daniel1(vtype, accel, decel, emergencyDecel, sigma, tau,
275  from.getCFParam(SUMO_ATTR_TMP1, 1.),
276  from.getCFParam(SUMO_ATTR_TMP2, 1.),
277  from.getCFParam(SUMO_ATTR_TMP3, 1.),
278  from.getCFParam(SUMO_ATTR_TMP4, 1.),
279  from.getCFParam(SUMO_ATTR_TMP5, 1.));
280  break;
282  vtype->myCarFollowModel = new MSCFModel_PWag2009(vtype, accel, decel, emergencyDecel, sigma, tau,
285  break;
287  vtype->myCarFollowModel = new MSCFModel_Wiedemann(vtype, accel, decel, emergencyDecel,
290  break;
291  case SUMO_TAG_CF_RAIL:
292  vtype->myCarFollowModel = new MSCFModel_Rail(vtype, from.getCFParamString(SUMO_ATTR_TRAIN_TYPE, "NGT400"));
293  break;
294  case SUMO_TAG_CF_KRAUSS:
295  default:
296  vtype->myCarFollowModel = new MSCFModel_Krauss(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau);
297  break;
298  }
299  return vtype;
300 }
301 
302 
304 MSVehicleType::buildSingularType(const std::string& id, const MSVehicleType* from) {
305  MSVehicleType* vtype = new MSVehicleType(from->myParameter);
306  vtype->myParameter.id = id;
307  vtype->myCarFollowModel = from->myCarFollowModel->duplicate(vtype);
308  if (from->myOriginalType != 0) {
309  vtype->myOriginalType = from->myOriginalType;
311  } else {
312  vtype->myOriginalType = from;
313  }
314  if (!MSNet::getInstance()->getVehicleControl().addVType(vtype)) {
315  throw ProcessError("could not add singular type " + vtype->getID());
316  }
317  return vtype;
318 }
319 
320 
321 /****************************************************************************/
322 
The Wiedemann Model car-following model.
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.
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.
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const =0
Duplicates the car-following model.
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.
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:158
T MAX2(T a, T b)
Definition: StdDefs.h:70
double getMinGapLat() const
Get the minimum lateral gap that vehicles of this type maintain.
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...
The car-following model and parameter.
Definition: MSVehicleType.h:74
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.
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...
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.
static MSVehicleType * buildSingularType(const std::string &id, const MSVehicleType *from)
Duplicates the microsim vehicle type giving it a the given id.
double maxSpeed
The vehicle type&#39;s maximum speed [m/s].
double width
This class&#39; width.
The original Krauss (1998) car-following model and parameter.
int SUMOEmissionClass
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:310
void setHeight(const double &height)
Set a new value for this type&#39;s height.
void removeVType(const MSVehicleType *vehType)
virtual ~MSVehicleType()
Destructor.
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
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.
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].
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.
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.
double minGapLat
The vehicle type&#39;s minimum lateral gap [m].
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.
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
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.
void setWidth(const double &width)
Set a new value for this type&#39;s width.
std::string id
The vehicle type&#39;s id.
double getLength() const
Get vehicle&#39;s length [m].
double sample(MTRand *which=0) const
Draw a sample of the distribution.
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.
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.
double computeChosenSpeedDeviation(MTRand *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
double getImpatience() const
Returns this type&#39;s impatience.
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.
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.