SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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-sim.org/
14 // Copyright (C) 2001-2013 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 // method definitions
59 // ===========================================================================
61  : myParameter(parameter), myOriginalType(0) {
62  assert(getLength() > 0);
63  assert(getMaxSpeed() > 0);
64 }
65 
66 
68  delete myCarFollowModel;
69 }
70 
71 
74  // for speedDev = 0.1, most 95% of the vehicles will drive between 80% and 120% of speedLimit * speedFactor
75  const SUMOReal devA = MIN2(SUMOReal(2.), RandHelper::randNorm(0, 1., rng));
76  // avoid voluntary speeds below 20% of the requested speedFactor
77  return MAX2(minDevFactor, SUMOReal(devA * myParameter.speedDev + 1.)) * myParameter.speedFactor;
78 }
79 
80 
81 // ------------ Setter methods
82 void
84  if (myOriginalType != 0 && length < 0) {
86  } else {
87  myParameter.length = length;
88  }
89 }
90 
91 
92 void
94  if (myOriginalType != 0 && minGap < 0) {
96  } else {
97  myParameter.minGap = minGap;
98  }
99 }
100 
101 
102 void
104  if (myOriginalType != 0 && maxSpeed < 0) {
106  } else {
107  myParameter.maxSpeed = maxSpeed;
108  }
109 }
110 
111 
112 void
114  myParameter.vehicleClass = vclass;
115 }
116 
117 
118 void
120  if (myOriginalType != 0 && prob < 0) {
122  } else {
124  }
125 }
126 
127 
128 void
130  if (myOriginalType != 0 && factor < 0) {
132  } else {
133  myParameter.speedFactor = factor;
134  }
135 }
136 
137 
138 void
140  if (myOriginalType != 0 && dev < 0) {
142  } else {
143  myParameter.speedDev = dev;
144  }
145 }
146 
147 
148 void
150  myParameter.emissionClass = eclass;
151 }
152 
153 
154 void
156  myParameter.color = color;
157 }
158 
159 
160 void
162  if (myOriginalType != 0 && width < 0) {
164  } else {
165  myParameter.width = width;
166  }
167 }
168 
169 
170 void
172  if (myOriginalType != 0 && impatience < 0) {
174  } else {
175  myParameter.impatience = impatience;
176  }
177 }
178 
179 
180 void
182  myParameter.shape = shape;
183 }
184 
185 
186 
187 // ------------ Static methods for building vehicle types
190  MSVehicleType* vtype = new MSVehicleType(from);
191  MSCFModel* model = 0;
192  switch (from.cfModel) {
193  case SUMO_TAG_CF_IDM:
194  model = new MSCFModel_IDM(vtype,
198  from.get(SUMO_ATTR_CF_IDM_DELTA, 4.),
199  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
200  break;
201  case SUMO_TAG_CF_IDMM:
202  model = new MSCFModel_IDM(vtype,
207  from.get(SUMO_ATTR_CF_IDMM_ADAPT_TIME, 600.),
208  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
209  break;
210  case SUMO_TAG_CF_BKERNER:
211  model = new MSCFModel_Kerner(vtype,
215  from.get(SUMO_ATTR_K, .5),
216  from.get(SUMO_ATTR_CF_KERNER_PHI, 5.));
217  break;
219  model = new MSCFModel_KraussOrig1(vtype,
224  break;
226  model = new MSCFModel_KraussPS(vtype,
231  break;
233  model = new MSCFModel_SmartSK(vtype,
243  break;
244  case SUMO_TAG_CF_DANIEL1:
245  model = new MSCFModel_Daniel1(vtype,
255  break;
257  model = new MSCFModel_PWag2009(vtype,
264  break;
266  model = new MSCFModel_Wiedemann(vtype,
271  break;
272  case SUMO_TAG_CF_KRAUSS:
273  default:
274  model = new MSCFModel_Krauss(vtype,
279  break;
280  }
281  vtype->myCarFollowModel = model;
282  return vtype;
283 }
284 
285 
287 MSVehicleType::build(const std::string& id, const MSVehicleType* from) {
288  MSVehicleType* vtype = new MSVehicleType(from->myParameter);
289  vtype->myParameter.id = id;
290  vtype->myCarFollowModel = from->myCarFollowModel->duplicate(vtype);
291  vtype->myOriginalType = from->myOriginalType != 0 ? from->myOriginalType : from;
292  return vtype;
293 }
294 
295 
296 /****************************************************************************/
297 
The Intellignet Driver Model (IDM) car-following model.
const SUMOReal DEFAULT_VEH_TMP5
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 ot 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
The car-following model abstraction.
Definition: MSCFModel.h:58
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.
static SUMOReal randNorm(SUMOReal mean, SUMOReal variance, MTRand &rng=myRandomNumberGenerator)
Access to a random number from a normal distribution.
Definition: RandHelper.h:91
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:63
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.
const SUMOReal DEFAULT_VEH_SIGMA
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
SUMOEmissionClass
Definition of vehicle emission classes.
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.
const SUMOReal DEFAULT_VEH_TAU
virtual ~MSVehicleType()
Destructor.
T MIN2(T a, T b)
Definition: StdDefs.h:57
void setEmissionClass(SUMOEmissionClass eclass)
Set a new value for this type&#39;s emission class.
const SUMOReal DEFAULT_VEH_TMP3
void setMinGap(const SUMOReal &minGap)
Set a new value for this type&#39;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&#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.
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.
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.
const SUMOReal DEFAULT_VEH_TMP2
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.
const SUMOReal DEFAULT_VEH_ACCEL
const SUMOReal DEFAULT_VEH_TMP1
#define SUMOReal
Definition: config.h:215
const SUMOReal DEFAULT_VEH_TMP4
Krauss car-following model, with acceleration decrease and faster start.
const SUMOReal DEFAULT_VEH_DECEL
SUMOEmissionClass emissionClass
The emission class of this vehicle.
SUMOReal minGap
This class&#39; free space in front of the vehicle itself.