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"
47 #include "MSVehicleType.h"
48 
49 #ifdef CHECK_MEMORY_LEAKS
50 #include <foreign/nvwa/debug_new.h>
51 #endif // CHECK_MEMORY_LEAKS
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 MSVehicleType::MSVehicleType(const std::string& id, const SUMOReal length,
58  const SUMOReal minGap, const SUMOReal maxSpeed, const SUMOReal prob,
59  const SUMOReal speedFactor, const SUMOReal speedDev,
60  const SUMOVehicleClass vclass,
61  const SUMOEmissionClass emissionClass,
62  const SUMOReal guiWidth, const SUMOReal height,
63  const SUMOVehicleShape shape, const std::string osgFile,
64  const std::string& lcModel,
65  const RGBColor& c)
66  : myID(id), myLength(length),
67  myMinGap(minGap), myMaxSpeed(maxSpeed),
68  myDefaultProbability(prob), mySpeedFactor(speedFactor),
69  mySpeedDev(speedDev), myLaneChangeModel(lcModel),
70  myEmissionClass(emissionClass), myColor(c),
71  myVehicleClass(vclass), myWidth(guiWidth),
72  myHeight(height), myShape(shape), myOSGFile(osgFile),
73  myOriginalType(0) {
74  assert(myLength > 0);
75  assert(getMaxSpeed() > 0);
76 }
77 
78 
80  delete myCarFollowModel;
81 }
82 
83 
84 void
85 MSVehicleType::saveState(std::ostream& os) {
92  FileHelpers::writeInt(os, (int) myShape);
102  //myCarFollowModel->saveState(os);
103 }
104 
105 
106 // ------------ Setter methods
107 void
109  assert(myOriginalType != 0);
110  if (length < 0) {
112  } else {
113  myLength = length;
114  }
115 }
116 
117 
118 void
120  assert(myOriginalType != 0);
121  if (minGap < 0) {
123  } else {
124  myMinGap = minGap;
125  }
126 }
127 
128 
129 void
131  assert(myOriginalType != 0);
132  if (maxSpeed < 0) {
134  } else {
135  myMaxSpeed = maxSpeed;
136  }
137 }
138 
139 
140 void
142  myVehicleClass = vclass;
143 }
144 
145 
146 void
148  assert(myOriginalType != 0);
149  if (prob < 0) {
151  } else {
152  myDefaultProbability = prob;
153  }
154 }
155 
156 
157 void
159  assert(myOriginalType != 0);
160  if (factor < 0) {
162  } else {
163  mySpeedFactor = factor;
164  }
165 }
166 
167 
168 void
170  assert(myOriginalType != 0);
171  if (dev < 0) {
173  } else {
174  mySpeedDev = dev;
175  }
176 }
177 
178 
179 void
181  myEmissionClass = eclass;
182 }
183 
184 
185 void
187  myColor = color;
188 }
189 
190 
191 void
193  assert(myOriginalType != 0);
194  if (width < 0) {
196  } else {
197  myWidth = width;
198  }
199 }
200 
201 
202 void
204  myShape = shape;
205 }
206 
207 
208 
209 // ------------ Static methods for building vehicle types
212  MSVehicleType* vtype = new MSVehicleType(
213  from.id, from.length, from.minGap, from.maxSpeed,
215  from.width, from.height, from.shape, from.osgFile, from.lcModel, from.color);
216  MSCFModel* model = 0;
217  switch (from.cfModel) {
218  case SUMO_TAG_CF_IDM:
219  model = new MSCFModel_IDM(vtype,
223  from.get(SUMO_ATTR_CF_IDM_DELTA, 4.),
224  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
225  break;
226  case SUMO_TAG_CF_IDMM:
227  model = new MSCFModel_IDM(vtype,
232  from.get(SUMO_ATTR_CF_IDMM_ADAPT_TIME, 600.),
233  from.get(SUMO_ATTR_CF_IDM_STEPPING, .25));
234  break;
235  case SUMO_TAG_CF_BKERNER:
236  model = new MSCFModel_Kerner(vtype,
240  from.get(SUMO_ATTR_K, .5),
241  from.get(SUMO_ATTR_CF_KERNER_PHI, 5.));
242  break;
244  model = new MSCFModel_KraussOrig1(vtype,
249  break;
251  model = new MSCFModel_PWag2009(vtype,
258  break;
260  model = new MSCFModel_Wiedemann(vtype,
265  break;
266  case SUMO_TAG_CF_KRAUSS:
267  default:
268  model = new MSCFModel_Krauss(vtype,
273  break;
274  }
275  vtype->myCarFollowModel = model;
276  return vtype;
277 }
278 
279 
281 MSVehicleType::build(const std::string& id, const MSVehicleType* from) {
282  MSVehicleType* vtype = new MSVehicleType(
283  id, from->myLength, from->myMinGap, from->myMaxSpeed,
285  from->myWidth, from->myHeight, from->myShape, from->myOSGFile, from->myLaneChangeModel, from->myColor);
286  vtype->myCarFollowModel = from->myCarFollowModel->duplicate(vtype);
287  vtype->myOriginalType = from->myOriginalType != 0 ? from->myOriginalType : from;
288  return vtype;
289 }
290 
291 
292 /****************************************************************************/
293