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