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-sim.org/
14 // Copyright (C) 2001-2014 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++), myOriginalType(0) {
68  assert(getLength() > 0);
69  assert(getMaxSpeed() > 0);
70 }
71 
72 
74  delete myCarFollowModel;
75 }
76 
77 
80  // for speedDev = 0.1, most 95% of the vehicles will drive between 80% and 120% of speedLimit * speedFactor
81  const SUMOReal devA = MIN2(SUMOReal(2.), RandHelper::randNorm(0, 1., rng));
82  // avoid voluntary speeds below 20% of the requested speedFactor
83  return MAX2(minDevFactor, SUMOReal(devA * myParameter.speedDev + 1.)) * myParameter.speedFactor;
84 }
85 
86 
87 // ------------ Setter methods
88 void
90  if (myOriginalType != 0 && length < 0) {
92  } else {
93  myParameter.length = length;
94  }
95 }
96 
97 
98 void
100  if (myOriginalType != 0 && minGap < 0) {
102  } else {
103  myParameter.minGap = minGap;
104  }
105 }
106 
107 
108 void
110  if (myOriginalType != 0 && maxSpeed < 0) {
112  } else {
113  myParameter.maxSpeed = maxSpeed;
114  }
115 }
116 
117 
118 void
120  myParameter.vehicleClass = vclass;
121 }
122 
123 
124 void
126  if (myOriginalType != 0 && prob < 0) {
128  } else {
130  }
131 }
132 
133 
134 void
136  if (myOriginalType != 0 && factor < 0) {
138  } else {
139  myParameter.speedFactor = factor;
140  }
141 }
142 
143 
144 void
146  if (myOriginalType != 0 && dev < 0) {
148  } else {
149  myParameter.speedDev = dev;
150  }
151 }
152 
153 
154 void
156  myParameter.emissionClass = eclass;
157 }
158 
159 
160 void
162  myParameter.color = color;
163 }
164 
165 
166 void
168  if (myOriginalType != 0 && width < 0) {
170  } else {
171  myParameter.width = width;
172  }
173 }
174 
175 
176 void
178  if (myOriginalType != 0 && impatience < 0) {
180  } else {
181  myParameter.impatience = impatience;
182  }
183 }
184 
185 
186 void
188  myParameter.shape = shape;
189 }
190 
191 
192 
193 // ------------ Static methods for building vehicle types
196  MSVehicleType* vtype = new MSVehicleType(from);
200  const SUMOReal tau = from.get(SUMO_ATTR_TAU, 1.);
201  switch (from.cfModel) {
202  case SUMO_TAG_CF_IDM:
203  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, tau,
204  from.get(SUMO_ATTR_CF_IDM_DELTA, 4.),
205  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
206  break;
207  case SUMO_TAG_CF_IDMM:
208  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, tau,
210  from.get(SUMO_ATTR_CF_IDMM_ADAPT_TIME, 600.),
211  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
212  break;
213  case SUMO_TAG_CF_BKERNER:
214  vtype->myCarFollowModel = new MSCFModel_Kerner(vtype, accel, decel, tau,
215  from.get(SUMO_ATTR_K, .5),
216  from.get(SUMO_ATTR_CF_KERNER_PHI, 5.));
217  break;
219  vtype->myCarFollowModel = new MSCFModel_KraussOrig1(vtype, accel, decel, sigma, tau);
220  break;
222  vtype->myCarFollowModel = new MSCFModel_KraussPS(vtype, accel, decel, sigma, tau);
223  break;
225  vtype->myCarFollowModel = new MSCFModel_SmartSK(vtype, accel, decel, sigma, tau,
226  from.get(SUMO_ATTR_TMP1, 1.),
227  from.get(SUMO_ATTR_TMP2, 1.),
228  from.get(SUMO_ATTR_TMP3, 1.),
229  from.get(SUMO_ATTR_TMP4, 1.),
230  from.get(SUMO_ATTR_TMP5, 1.));
231  break;
232  case SUMO_TAG_CF_DANIEL1:
233  vtype->myCarFollowModel = new MSCFModel_Daniel1(vtype, accel, decel, sigma, tau,
234  from.get(SUMO_ATTR_TMP1, 1.),
235  from.get(SUMO_ATTR_TMP2, 1.),
236  from.get(SUMO_ATTR_TMP3, 1.),
237  from.get(SUMO_ATTR_TMP4, 1.),
238  from.get(SUMO_ATTR_TMP5, 1.));
239  break;
241  vtype->myCarFollowModel = new MSCFModel_PWag2009(vtype, accel, decel, sigma, tau,
244  break;
246  vtype->myCarFollowModel = new MSCFModel_Wiedemann(vtype, accel, decel,
249  break;
250  case SUMO_TAG_CF_KRAUSS:
251  default:
252  vtype->myCarFollowModel = new MSCFModel_Krauss(vtype, accel, decel, sigma, tau);
253  break;
254  }
255  return vtype;
256 }
257 
258 
260 MSVehicleType::build(const std::string& id, const MSVehicleType* from) {
261  MSVehicleType* vtype = new MSVehicleType(from->myParameter);
262  vtype->myParameter.id = id;
263  vtype->myCarFollowModel = from->myCarFollowModel->duplicate(vtype);
264  vtype->myOriginalType = from->myOriginalType != 0 ? from->myOriginalType : from;
265  return vtype;
266 }
267 
268 
269 /****************************************************************************/
270 
The Intellignet Driver Model (IDM) car-following model.
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 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'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.
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.
static SUMOReal randNorm(SUMOReal mean, SUMOReal variance, MTRand &rng=myRandomNumberGenerator)
Access to a random number from a normal distribution.
Definition: RandHelper.h:92
SUMOVehicleClass vehicleClass
The vehicle's class.
The original Krauss (1998) car-following model and parameter.
T MAX2(T a, T b)
Definition: StdDefs.h:72
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.
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.
virtual ~MSVehicleType()
Destructor.
T MIN2(T a, T b)
Definition: StdDefs.h:66
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.
SUMOReal computeChosenSpeedDeviation(MTRand &rng, const SUMOReal minDevFactor=0.2) const
Computes and returns the speed deviation.
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'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
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'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 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:215
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' free space in front of the vehicle itself.