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