SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2016 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"
50 #include "MSVehicleType.h"
51 
52 #ifdef CHECK_MEMORY_LEAKS
53 #include <foreign/nvwa/debug_new.h>
54 #endif // CHECK_MEMORY_LEAKS
55 
56 
57 // ===========================================================================
58 // static members
59 // ===========================================================================
61 
62 
63 // ===========================================================================
64 // method definitions
65 // ===========================================================================
67  : myParameter(parameter), myIndex(myNextIndex++), myCarFollowModel(0), myOriginalType(0) {
68  assert(getLength() > 0);
69  assert(getMaxSpeed() > 0);
70 }
71 
72 
74  delete myCarFollowModel;
75 }
76 
77 
80  if (myParameter.speedDev == 0) {
81  return myParameter.speedFactor;
82  }
83  // for speedDev = 0.1, most 95% of the vehicles will drive between 80% and 120% of speedLimit * speedFactor
84  const SUMOReal devA = MIN2(SUMOReal(2.), RandHelper::randNorm(0, 1., rng));
85  // avoid voluntary speeds below 20% of the requested speedFactor
86  return MAX2(minDevFactor, SUMOReal(devA * myParameter.speedDev + 1.)) * myParameter.speedFactor;
87 }
88 
89 
90 // ------------ Setter methods
91 void
93  if (myOriginalType != 0 && length < 0) {
95  } else {
96  myParameter.length = length;
97  }
98 }
99 
100 
101 void
103  if (myOriginalType != 0 && height < 0) {
105  } else {
106  myParameter.height = height;
107  }
108 }
109 
110 
111 void
113  if (myOriginalType != 0 && minGap < 0) {
115  } else {
116  myParameter.minGap = minGap;
117  }
118 }
119 
120 
121 void
123  if (myOriginalType != 0 && maxSpeed < 0) {
125  } else {
126  myParameter.maxSpeed = maxSpeed;
127  }
128 }
129 
130 
131 void
133  myParameter.vehicleClass = vclass;
134 }
135 
136 
137 void
139  if (myOriginalType != 0 && prob < 0) {
141  } else {
143  }
144 }
145 
146 
147 void
149  if (myOriginalType != 0 && factor < 0) {
151  } else {
152  myParameter.speedFactor = factor;
153  }
154 }
155 
156 
157 void
159  if (myOriginalType != 0 && dev < 0) {
161  } else {
162  myParameter.speedDev = dev;
163  }
164 }
165 
166 
167 void
169  myParameter.emissionClass = eclass;
170 }
171 
172 
173 void
175  myParameter.color = color;
176 }
177 
178 
179 void
181  if (myOriginalType != 0 && width < 0) {
183  } else {
184  myParameter.width = width;
185  }
186 }
187 
188 
189 void
191  if (myOriginalType != 0 && impatience < 0) {
193  } else {
194  myParameter.impatience = impatience;
195  }
196 }
197 
198 
199 void
201  myParameter.shape = shape;
202 }
203 
204 
205 
206 // ------------ Static methods for building vehicle types
209  MSVehicleType* vtype = new MSVehicleType(from);
213  const SUMOReal tau = from.getCFParam(SUMO_ATTR_TAU, 1.);
214  switch (from.cfModel) {
215  case SUMO_TAG_CF_IDM:
216  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, tau,
219  break;
220  case SUMO_TAG_CF_IDMM:
221  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, tau,
225  break;
226  case SUMO_TAG_CF_BKERNER:
227  vtype->myCarFollowModel = new MSCFModel_Kerner(vtype, accel, decel, tau,
228  from.getCFParam(SUMO_ATTR_K, .5),
230  break;
232  vtype->myCarFollowModel = new MSCFModel_KraussOrig1(vtype, accel, decel, sigma, tau);
233  break;
235  vtype->myCarFollowModel = new MSCFModel_KraussPS(vtype, accel, decel, sigma, tau);
236  break;
238  vtype->myCarFollowModel = new MSCFModel_SmartSK(vtype, accel, decel, sigma, tau,
239  from.getCFParam(SUMO_ATTR_TMP1, 1.),
240  from.getCFParam(SUMO_ATTR_TMP2, 1.),
241  from.getCFParam(SUMO_ATTR_TMP3, 1.),
242  from.getCFParam(SUMO_ATTR_TMP4, 1.),
243  from.getCFParam(SUMO_ATTR_TMP5, 1.));
244  break;
245  case SUMO_TAG_CF_DANIEL1:
246  vtype->myCarFollowModel = new MSCFModel_Daniel1(vtype, accel, decel, sigma, tau,
247  from.getCFParam(SUMO_ATTR_TMP1, 1.),
248  from.getCFParam(SUMO_ATTR_TMP2, 1.),
249  from.getCFParam(SUMO_ATTR_TMP3, 1.),
250  from.getCFParam(SUMO_ATTR_TMP4, 1.),
251  from.getCFParam(SUMO_ATTR_TMP5, 1.));
252  break;
254  vtype->myCarFollowModel = new MSCFModel_PWag2009(vtype, accel, decel, sigma, tau,
257  break;
259  vtype->myCarFollowModel = new MSCFModel_Wiedemann(vtype, accel, decel,
262  break;
263  case SUMO_TAG_CF_KRAUSS:
264  default:
265  vtype->myCarFollowModel = new MSCFModel_Krauss(vtype, accel, decel, sigma, tau);
266  break;
267  }
268  return vtype;
269 }
270 
271 
273 MSVehicleType::build(const std::string& id, const MSVehicleType* from) {
274  MSVehicleType* vtype = new MSVehicleType(from->myParameter);
275  vtype->myParameter.id = id;
276  vtype->myCarFollowModel = from->myCarFollowModel->duplicate(vtype);
277  vtype->myOriginalType = from->myOriginalType != 0 ? from->myOriginalType : from;
278  return vtype;
279 }
280 
281 
282 /****************************************************************************/
283 
The Wiedemann Model 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:97
void setImpatience(const SUMOReal impatience)
Set a new value for this type's impatience.
SumoXMLTag cfModel
The enum-representation of the car-following model to use.
SUMOReal getMaxSpeed() const
Get vehicle'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's shape.
SUMOVehicleShape shape
This class' shape.
Structure representing possible vehicle parameter.
SUMOReal getCFParam(const SumoXMLAttr attr, const SUMOReal defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
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'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's length.
Krauss car-following model, changing accel and speed by slope.
SUMOReal length
The physical vehicle length.
SUMOReal getLength() const
Get vehicle's length [m].
SUMOReal getImpatience() const
Returns this type's impatience.
SUMOVehicleClass vehicleClass
The vehicle's class.
The original Krauss (1998) car-following model and parameter.
T MAX2(T a, T b)
Definition: StdDefs.h:75
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's width.
SUMOReal width
This class' width.
SUMOReal getHeight() const
Get the height which vehicles of this class shall have when being drawn.
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
static SUMOReal getDefaultImperfection(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default driver's imperfection (sigma or epsilon in Krauss' 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's speed deviation.
SUMOReal getSpeedDeviation() const
Returns this type'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:69
void setEmissionClass(SUMOEmissionClass eclass)
Set a new value for this type's emission class.
void setMinGap(const SUMOReal &minGap)
Set a new value for this type's minimum gap.
Scalable model based on Krauss by Peter Wagner.
The original Krauss (1998) car-following model and parameter.
SUMOVTypeParameter myParameter
the parameter container
SUMOReal maxSpeed
The vehicle type's maximum speed [m/s].
SUMOReal getSpeedFactor() const
Returns this type's speed factor.
SUMOReal getWidth() const
Get the width which vehicles of this class shall have when being drawn.
MSCFModel * myCarFollowModel
instance 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'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's id.
MSVehicleType(const SUMOVTypeParameter &parameter)
Constructor.
void setVClass(SUMOVehicleClass vclass)
Set a new value for this type's vehicle class.
void setDefaultProbability(const SUMOReal &prob)
Set a new value for this type's default probability.
void setHeight(const SUMOReal &height)
Set a new value for this type's height.
void setMaxSpeed(const SUMOReal &maxSpeed)
Set a new value for this type's maximum speed.
void setColor(const RGBColor &color)
Set a new value for this type'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 ...
SUMOReal height
This class' height.
Krauss car-following model, with acceleration decrease and faster start.
SUMOEmissionClass emissionClass
The emission class of this vehicle.
SUMOReal minGap
This class' free space in front of the vehicle itself.