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.sourceforge.net/
14 // Copyright (C) 2001-2012 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"
49 #include "MSVehicleType.h"
50 
51 #ifdef CHECK_MEMORY_LEAKS
52 #include <foreign/nvwa/debug_new.h>
53 #endif // CHECK_MEMORY_LEAKS
54 
55 
56 // ===========================================================================
57 // method definitions
58 // ===========================================================================
60  : myParameter(parameter), myOriginalType(0) {
61  assert(getLength() > 0);
62  assert(getMaxSpeed() > 0);
63 }
64 
65 
67  delete myCarFollowModel;
68 }
69 
70 
73  // for speedDev = 0.1, most 95% of the vehicles will drive between 80% and 120% of speedLimit * speedFactor
74  const SUMOReal devA = MIN2(SUMOReal(2.), RandHelper::randNorm(0, 1., rng));
75  // avoid voluntary speeds below 20% of the requested speedFactor
76  return MAX2(0.2 * myParameter.speedFactor,
78 }
79 
80 
81 void
82 MSVehicleType::saveState(std::ostream& os) {
99  //myCarFollowModel->saveState(os);
100 }
101 
102 
103 // ------------ Setter methods
104 void
106  assert(myOriginalType != 0);
107  if (length < 0) {
109  } else {
110  myParameter.length = length;
111  }
112 }
113 
114 
115 void
117  assert(myOriginalType != 0);
118  if (minGap < 0) {
120  } else {
121  myParameter.minGap = minGap;
122  }
123 }
124 
125 
126 void
128  assert(myOriginalType != 0);
129  if (maxSpeed < 0) {
131  } else {
132  myParameter.maxSpeed = maxSpeed;
133  }
134 }
135 
136 
137 void
139  myParameter.vehicleClass = vclass;
140 }
141 
142 
143 void
145  assert(myOriginalType != 0);
146  if (prob < 0) {
148  } else {
150  }
151 }
152 
153 
154 void
156  assert(myOriginalType != 0);
157  if (factor < 0) {
159  } else {
160  myParameter.speedFactor = factor;
161  }
162 }
163 
164 
165 void
167  assert(myOriginalType != 0);
168  if (dev < 0) {
170  } else {
171  myParameter.speedDev = dev;
172  }
173 }
174 
175 
176 void
178  myParameter.emissionClass = eclass;
179 }
180 
181 
182 void
184  myParameter.color = color;
185 }
186 
187 
188 void
190  assert(myOriginalType != 0);
191  if (width < 0) {
193  } else {
194  myParameter.width = width;
195  }
196 }
197 
198 
199 void
201  myParameter.shape = shape;
202 }
203 
204 
205 
206 // ------------ Static methods for building vehicle types
209  MSVehicleType* vtype = new MSVehicleType(from);
210  MSCFModel* model = 0;
211  switch (from.cfModel) {
212  case SUMO_TAG_CF_IDM:
213  model = new MSCFModel_IDM(vtype,
217  from.get(SUMO_ATTR_CF_IDM_DELTA, 4.),
218  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
219  break;
220  case SUMO_TAG_CF_IDMM:
221  model = new MSCFModel_IDM(vtype,
226  from.get(SUMO_ATTR_CF_IDMM_ADAPT_TIME, 600.),
227  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
228  break;
229  case SUMO_TAG_CF_BKERNER:
230  model = new MSCFModel_Kerner(vtype,
234  from.get(SUMO_ATTR_K, .5),
235  from.get(SUMO_ATTR_CF_KERNER_PHI, 5.));
236  break;
238  model = new MSCFModel_KraussOrig1(vtype,
243  break;
245  model = new MSCFModel_SmartSK(vtype,
255  break;
256  case SUMO_TAG_CF_DANIEL1:
257  model = new MSCFModel_Daniel1(vtype,
267  break;
269  model = new MSCFModel_PWag2009(vtype,
276  break;
278  model = new MSCFModel_Wiedemann(vtype,
283  break;
284  case SUMO_TAG_CF_KRAUSS:
285  default:
286  model = new MSCFModel_Krauss(vtype,
291  break;
292  }
293  vtype->myCarFollowModel = model;
294  return vtype;
295 }
296 
297 
299 MSVehicleType::build(const std::string& id, const MSVehicleType* from) {
300  MSVehicleType* vtype = new MSVehicleType(from->myParameter);
301  vtype->myParameter.id = id;
302  vtype->myCarFollowModel = from->myCarFollowModel->duplicate(vtype);
303  vtype->myOriginalType = from->myOriginalType != 0 ? from->myOriginalType : from;
304  return vtype;
305 }
306 
307 
308 /****************************************************************************/
309