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(0.2 * myParameter.speedFactor,
79 }
80 
81 
82 // ------------ Setter methods
83 void
85  if (myOriginalType != 0 && length < 0) {
87  } else {
88  myParameter.length = length;
89  }
90 }
91 
92 
93 void
95  if (myOriginalType != 0 && minGap < 0) {
97  } else {
98  myParameter.minGap = minGap;
99  }
100 }
101 
102 
103 void
105  if (myOriginalType != 0 && maxSpeed < 0) {
107  } else {
108  myParameter.maxSpeed = maxSpeed;
109  }
110 }
111 
112 
113 void
115  myParameter.vehicleClass = vclass;
116 }
117 
118 
119 void
121  if (myOriginalType != 0 && prob < 0) {
123  } else {
125  }
126 }
127 
128 
129 void
131  if (myOriginalType != 0 && factor < 0) {
133  } else {
134  myParameter.speedFactor = factor;
135  }
136 }
137 
138 
139 void
141  if (myOriginalType != 0 && dev < 0) {
143  } else {
144  myParameter.speedDev = dev;
145  }
146 }
147 
148 
149 void
151  myParameter.emissionClass = eclass;
152 }
153 
154 
155 void
157  myParameter.color = color;
158 }
159 
160 
161 void
163  if (myOriginalType != 0 && width < 0) {
165  } else {
166  myParameter.width = width;
167  }
168 }
169 
170 
171 void
173  if (myOriginalType != 0 && impatience < 0) {
175  } else {
176  myParameter.impatience = impatience;
177  }
178 }
179 
180 
181 void
183  myParameter.shape = shape;
184 }
185 
186 
187 
188 // ------------ Static methods for building vehicle types
191  MSVehicleType* vtype = new MSVehicleType(from);
192  MSCFModel* model = 0;
193  switch (from.cfModel) {
194  case SUMO_TAG_CF_IDM:
195  model = new MSCFModel_IDM(vtype,
199  from.get(SUMO_ATTR_CF_IDM_DELTA, 4.),
200  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
201  break;
202  case SUMO_TAG_CF_IDMM:
203  model = new MSCFModel_IDM(vtype,
208  from.get(SUMO_ATTR_CF_IDMM_ADAPT_TIME, 600.),
209  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
210  break;
211  case SUMO_TAG_CF_BKERNER:
212  model = new MSCFModel_Kerner(vtype,
216  from.get(SUMO_ATTR_K, .5),
217  from.get(SUMO_ATTR_CF_KERNER_PHI, 5.));
218  break;
220  model = new MSCFModel_KraussOrig1(vtype,
225  break;
227  model = new MSCFModel_KraussPS(vtype,
232  break;
234  model = new MSCFModel_SmartSK(vtype,
244  break;
245  case SUMO_TAG_CF_DANIEL1:
246  model = new MSCFModel_Daniel1(vtype,
256  break;
258  model = new MSCFModel_PWag2009(vtype,
265  break;
267  model = new MSCFModel_Wiedemann(vtype,
272  break;
273  case SUMO_TAG_CF_KRAUSS:
274  default:
275  model = new MSCFModel_Krauss(vtype,
280  break;
281  }
282  vtype->myCarFollowModel = model;
283  return vtype;
284 }
285 
286 
288 MSVehicleType::build(const std::string& id, const MSVehicleType* from) {
289  MSVehicleType* vtype = new MSVehicleType(from->myParameter);
290  vtype->myParameter.id = id;
291  vtype->myCarFollowModel = from->myCarFollowModel->duplicate(vtype);
292  vtype->myOriginalType = from->myOriginalType != 0 ? from->myOriginalType : from;
293  return vtype;
294 }
295 
296 
297 /****************************************************************************/
298 
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.
SUMOReal computeChosenSpeedDeviation(MTRand &rng) const
Computes and returns the speed deviation.
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.
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:221
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.