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-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 && minGap < 0) {
105  } else {
106  myParameter.minGap = minGap;
107  }
108 }
109 
110 
111 void
113  if (myOriginalType != 0 && maxSpeed < 0) {
115  } else {
116  myParameter.maxSpeed = maxSpeed;
117  }
118 }
119 
120 
121 void
123  myParameter.vehicleClass = vclass;
124 }
125 
126 
127 void
129  if (myOriginalType != 0 && prob < 0) {
131  } else {
133  }
134 }
135 
136 
137 void
139  if (myOriginalType != 0 && factor < 0) {
141  } else {
142  myParameter.speedFactor = factor;
143  }
144 }
145 
146 
147 void
149  if (myOriginalType != 0 && dev < 0) {
151  } else {
152  myParameter.speedDev = dev;
153  }
154 }
155 
156 
157 void
159  myParameter.emissionClass = eclass;
160 }
161 
162 
163 void
165  myParameter.color = color;
166 }
167 
168 
169 void
171  if (myOriginalType != 0 && width < 0) {
173  } else {
174  myParameter.width = width;
175  }
176 }
177 
178 
179 void
181  if (myOriginalType != 0 && impatience < 0) {
183  } else {
184  myParameter.impatience = impatience;
185  }
186 }
187 
188 
189 void
191  myParameter.shape = shape;
192 }
193 
194 
195 
196 // ------------ Static methods for building vehicle types
199  MSVehicleType* vtype = new MSVehicleType(from);
203  const SUMOReal tau = from.get(SUMO_ATTR_TAU, 1.);
204  switch (from.cfModel) {
205  case SUMO_TAG_CF_IDM:
206  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, tau,
207  from.get(SUMO_ATTR_CF_IDM_DELTA, 4.),
208  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
209  break;
210  case SUMO_TAG_CF_IDMM:
211  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, tau,
213  from.get(SUMO_ATTR_CF_IDMM_ADAPT_TIME, 600.),
214  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
215  break;
216  case SUMO_TAG_CF_BKERNER:
217  vtype->myCarFollowModel = new MSCFModel_Kerner(vtype, accel, decel, tau,
218  from.get(SUMO_ATTR_K, .5),
219  from.get(SUMO_ATTR_CF_KERNER_PHI, 5.));
220  break;
222  vtype->myCarFollowModel = new MSCFModel_KraussOrig1(vtype, accel, decel, sigma, tau);
223  break;
225  vtype->myCarFollowModel = new MSCFModel_KraussPS(vtype, accel, decel, sigma, tau);
226  break;
228  vtype->myCarFollowModel = new MSCFModel_SmartSK(vtype, accel, decel, sigma, tau,
229  from.get(SUMO_ATTR_TMP1, 1.),
230  from.get(SUMO_ATTR_TMP2, 1.),
231  from.get(SUMO_ATTR_TMP3, 1.),
232  from.get(SUMO_ATTR_TMP4, 1.),
233  from.get(SUMO_ATTR_TMP5, 1.));
234  break;
235  case SUMO_TAG_CF_DANIEL1:
236  vtype->myCarFollowModel = new MSCFModel_Daniel1(vtype, accel, decel, sigma, tau,
237  from.get(SUMO_ATTR_TMP1, 1.),
238  from.get(SUMO_ATTR_TMP2, 1.),
239  from.get(SUMO_ATTR_TMP3, 1.),
240  from.get(SUMO_ATTR_TMP4, 1.),
241  from.get(SUMO_ATTR_TMP5, 1.));
242  break;
244  vtype->myCarFollowModel = new MSCFModel_PWag2009(vtype, accel, decel, sigma, tau,
247  break;
249  vtype->myCarFollowModel = new MSCFModel_Wiedemann(vtype, accel, decel,
252  break;
253  case SUMO_TAG_CF_KRAUSS:
254  default:
255  vtype->myCarFollowModel = new MSCFModel_Krauss(vtype, accel, decel, sigma, tau);
256  break;
257  }
258  return vtype;
259 }
260 
261 
263 MSVehicleType::build(const std::string& id, const MSVehicleType* from) {
264  MSVehicleType* vtype = new MSVehicleType(from->myParameter);
265  vtype->myParameter.id = id;
266  vtype->myCarFollowModel = from->myCarFollowModel->duplicate(vtype);
267  vtype->myOriginalType = from->myOriginalType != 0 ? from->myOriginalType : from;
268  return vtype;
269 }
270 
271 
272 /****************************************************************************/
273 
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.
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const =0
Duplicates the car-following model.
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.
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: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&#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
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:69
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 Krauss 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
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&#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.