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-2015 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>
40 #include "MSNet.h"
41 #include "cfmodels/MSCFModel_IDM.h"
51 #include "MSVehicleType.h"
52 
53 #ifdef CHECK_MEMORY_LEAKS
54 #include <foreign/nvwa/debug_new.h>
55 #endif // CHECK_MEMORY_LEAKS
56 
57 
58 // ===========================================================================
59 // static members
60 // ===========================================================================
62 
63 
64 // ===========================================================================
65 // method definitions
66 // ===========================================================================
68  : myParameter(parameter), myIndex(myNextIndex++), myOriginalType(0) {
69  assert(getLength() > 0);
70  assert(getMaxSpeed() > 0);
71 }
72 
73 
75  delete myCarFollowModel;
76 }
77 
78 
81  if (myParameter.speedDev == 0) {
82  return myParameter.speedFactor;
83  }
84  // for speedDev = 0.1, most 95% of the vehicles will drive between 80% and 120% of speedLimit * speedFactor
85  const SUMOReal devA = MIN2(SUMOReal(2.), RandHelper::randNorm(0, 1., rng));
86  // avoid voluntary speeds below 20% of the requested speedFactor
87  return MAX2(minDevFactor, SUMOReal(devA * myParameter.speedDev + 1.)) * myParameter.speedFactor;
88 }
89 
90 
91 // ------------ Setter methods
92 void
94  if (myOriginalType != 0 && length < 0) {
96  } else {
97  myParameter.length = length;
98  }
99 }
100 
101 
102 void
104  if (myOriginalType != 0 && minGap < 0) {
106  } else {
107  myParameter.minGap = minGap;
108  }
109 }
110 
111 
112 void
114  if (myOriginalType != 0 && maxSpeed < 0) {
116  } else {
117  myParameter.maxSpeed = maxSpeed;
118  }
119 }
120 
121 
122 void
124  myParameter.vehicleClass = vclass;
125 }
126 
127 
128 void
130  if (myOriginalType != 0 && prob < 0) {
132  } else {
134  }
135 }
136 
137 
138 void
140  if (myOriginalType != 0 && factor < 0) {
142  } else {
143  myParameter.speedFactor = factor;
144  }
145 }
146 
147 
148 void
150  if (myOriginalType != 0 && dev < 0) {
152  } else {
153  myParameter.speedDev = dev;
154  }
155 }
156 
157 
158 void
160  myParameter.emissionClass = eclass;
161 }
162 
163 
164 void
166  myParameter.color = color;
167 }
168 
169 
170 void
172  if (myOriginalType != 0 && width < 0) {
174  } else {
175  myParameter.width = width;
176  }
177 }
178 
179 
180 void
182  if (myOriginalType != 0 && impatience < 0) {
184  } else {
185  myParameter.impatience = impatience;
186  }
187 }
188 
189 
190 void
192  myParameter.shape = shape;
193 }
194 
195 
196 
197 // ------------ Static methods for building vehicle types
200  MSVehicleType* vtype = new MSVehicleType(from);
204  const SUMOReal tau = from.get(SUMO_ATTR_TAU, 1.);
205  switch (from.cfModel) {
206  case SUMO_TAG_CF_IDM:
207  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, tau,
208  from.get(SUMO_ATTR_CF_IDM_DELTA, 4.),
209  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
210  break;
211  case SUMO_TAG_CF_IDMM:
212  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, tau,
214  from.get(SUMO_ATTR_CF_IDMM_ADAPT_TIME, 600.),
215  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
216  break;
217  case SUMO_TAG_CF_BKERNER:
218  vtype->myCarFollowModel = new MSCFModel_Kerner(vtype, accel, decel, tau,
219  from.get(SUMO_ATTR_K, .5),
220  from.get(SUMO_ATTR_CF_KERNER_PHI, 5.));
221  break;
223  vtype->myCarFollowModel = new MSCFModel_KraussOrig1(vtype, accel, decel, sigma, tau);
224  break;
226  vtype->myCarFollowModel = new MSCFModel_KraussPS(vtype, accel, decel, sigma, tau);
227  break;
229  vtype->myCarFollowModel = new MSCFModel_KraussAccelBound(vtype, accel, decel, sigma, tau);
230  break;
232  vtype->myCarFollowModel = new MSCFModel_SmartSK(vtype, accel, decel, sigma, tau,
233  from.get(SUMO_ATTR_TMP1, 1.),
234  from.get(SUMO_ATTR_TMP2, 1.),
235  from.get(SUMO_ATTR_TMP3, 1.),
236  from.get(SUMO_ATTR_TMP4, 1.),
237  from.get(SUMO_ATTR_TMP5, 1.));
238  break;
239  case SUMO_TAG_CF_DANIEL1:
240  vtype->myCarFollowModel = new MSCFModel_Daniel1(vtype, accel, decel, sigma, tau,
241  from.get(SUMO_ATTR_TMP1, 1.),
242  from.get(SUMO_ATTR_TMP2, 1.),
243  from.get(SUMO_ATTR_TMP3, 1.),
244  from.get(SUMO_ATTR_TMP4, 1.),
245  from.get(SUMO_ATTR_TMP5, 1.));
246  break;
248  vtype->myCarFollowModel = new MSCFModel_PWag2009(vtype, accel, decel, sigma, tau,
251  break;
253  vtype->myCarFollowModel = new MSCFModel_Wiedemann(vtype, accel, decel,
256  break;
257  case SUMO_TAG_CF_KRAUSS:
258  default:
259  vtype->myCarFollowModel = new MSCFModel_Krauss(vtype, accel, decel, sigma, tau);
260  break;
261  }
262  return vtype;
263 }
264 
265 
267 MSVehicleType::build(const std::string& id, const MSVehicleType* from) {
268  MSVehicleType* vtype = new MSVehicleType(from->myParameter);
269  vtype->myParameter.id = id;
270  vtype->myCarFollowModel = from->myCarFollowModel->duplicate(vtype);
271  vtype->myOriginalType = from->myOriginalType != 0 ? from->myOriginalType : from;
272  return vtype;
273 }
274 
275 
276 /****************************************************************************/
277 
The Intellignet Driver Model (IDM) car-following model.
static SUMOReal randNorm(SUMOReal mean, SUMOReal variance, MTRand *rng=0)
Access to a random number from a normal distribution.
Definition: RandHelper.h:102
void setImpatience(const SUMOReal impatience)
Set a new value for this type&#39;s impatience.
SumoXMLTag cfModel
The enum-representation of the car-following model to use.
SUMOReal get(const SumoXMLAttr attr, const SUMOReal defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
SUMOReal getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
car-following model by B. Kerner
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.
void setSpeedFactor(const SUMOReal &factor)
Set a new value for this type&#39;s speed factor.
SUMOReal speedDev
The standard deviation for speed variations.
The Intelligent Driver Model (IDM) car-following model.
Definition: MSCFModel_IDM.h:48
void setLength(const SUMOReal &length)
Set a new value for this type&#39;s length.
Krauss car-following model, changing accel and speed by slope.
SUMOReal length
The physical vehicle length.
SUMOReal getLength() const
Get vehicle&#39;s length [m].
SUMOReal getImpatience() const
Returns this type&#39;s impatience.
SUMOVehicleClass vehicleClass
The vehicle&#39;s class.
The original Krauss (1998) car-following model and parameter.
T MAX2(T a, T b)
Definition: StdDefs.h:79
SUMOReal computeChosenSpeedDeviation(MTRand *rng, const SUMOReal minDevFactor=0.2) const
Computes and returns the speed deviation.
const MSVehicleType * myOriginalType
The original type.
void setWidth(const SUMOReal &width)
Set a new value for this type&#39;s width.
SUMOReal width
This class&#39; width.
static MSVehicleType * build(SUMOVTypeParameter &from)
Builds the microsim vehicle type described by the given parameter.
The car-following model and parameter.
Definition: MSVehicleType.h:74
Krauss car-following model, with PHEMlight-based acceleration limits.
static SUMOReal 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...
SUMOReal speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street...
void setSpeedDeviation(const SUMOReal &dev)
Set a new value for this type&#39;s speed deviation.
SUMOReal getSpeedDeviation() const
Returns this type&#39;s speed deviation.
SUMOReal getMinGap() const
Get the free space in front of vehicles of this class.
The original Krauss (1998) car-following model and parameter.
int SUMOEmissionClass
virtual ~MSVehicleType()
Destructor.
T MIN2(T a, T b)
Definition: StdDefs.h:73
void setEmissionClass(SUMOEmissionClass eclass)
Set a new value for this type&#39;s emission class.
void setMinGap(const SUMOReal &minGap)
Set a new value for this type&#39;s minimum gap.
Scalable model based on Krauß by Peter Wagner.
The original Krauss (1998) car-following model and parameter.
SUMOVTypeParameter myParameter
the parameter container
SUMOReal maxSpeed
The vehicle type&#39;s maximum speed [m/s].
SUMOReal getSpeedFactor() const
Returns this type&#39;s speed factor.
SUMOReal getWidth() const
Get the width which vehicles of this class shall have when being drawn.
MSCFModel * myCarFollowModel
ID of the car following model.
static SUMOReal getDefaultDecel(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default deceleration for the given vehicle class This needs to be a function because the ...
SUMOReal impatience
The vehicle&#39;s impatience (willingness to obstruct others)
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
SUMOReal defaultProbability
The probability when being added to a distribution without an explicit probability.
SUMOReal getDefaultProbability() const
Get the default probability of this vehicle type.
RGBColor color
The color.
static int myNextIndex
next value for the running index
std::string id
The vehicle type&#39;s id.
MSVehicleType(const SUMOVTypeParameter &parameter)
Constructor.
void setVClass(SUMOVehicleClass vclass)
Set a new value for this type&#39;s vehicle class.
void setDefaultProbability(const SUMOReal &prob)
Set a new value for this type&#39;s default probability.
void setMaxSpeed(const SUMOReal &maxSpeed)
Set a new value for this type&#39;s maximum speed.
void setColor(const RGBColor &color)
Set a new value for this type&#39;s color.
#define SUMOReal
Definition: config.h:214
static SUMOReal getDefaultAccel(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default acceleration for the given vehicle class This needs to be a function because the ...
Krauss car-following model, with acceleration decrease and faster start.
SUMOEmissionClass emissionClass
The emission class of this vehicle.
SUMOReal minGap
This class&#39; free space in front of the vehicle itself.