SUMO - Simulation of Urban MObility
MSVehicleType.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // The car-following model and parameter
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <cassert>
40 #include "MSNet.h"
41 #include "cfmodels/MSCFModel_IDM.h"
51 #include "MSVehicleControl.h"
52 #include "MSVehicleType.h"
53 
54 
55 // ===========================================================================
56 // static members
57 // ===========================================================================
59 
60 
61 // ===========================================================================
62 // method definitions
63 // ===========================================================================
65  : myParameter(parameter), myWarnedActionStepLengthTauOnce(false), myIndex(myNextIndex++), myCarFollowModel(0), myOriginalType(0) {
66  assert(getLength() > 0);
67  assert(getMaxSpeed() > 0);
68 
69  // Check if actionStepLength was set by user, if not init to global default
72  }
74 }
75 
76 
78  delete myCarFollowModel;
79 }
80 
81 
82 double
83 MSVehicleType::computeChosenSpeedDeviation(std::mt19937* rng, const double minDev) const {
84  return MAX2(minDev, myParameter.speedFactor.sample(rng));
85 }
86 
87 
88 // ------------ Setter methods
89 void
90 MSVehicleType::setLength(const double& length) {
91  if (myOriginalType != 0 && length < 0) {
93  } else {
94  myParameter.length = length;
95  }
97 }
98 
99 
100 void
101 MSVehicleType::setHeight(const double& height) {
102  if (myOriginalType != 0 && height < 0) {
104  } else {
105  myParameter.height = height;
106  }
108 }
109 
110 
111 void
112 MSVehicleType::setMinGap(const double& minGap) {
113  if (myOriginalType != 0 && minGap < 0) {
115  } else {
116  myParameter.minGap = minGap;
117  }
119 }
120 
121 
122 void
123 MSVehicleType::setMinGapLat(const double& minGapLat) {
124  if (myOriginalType != 0 && minGapLat < 0) {
126  } else {
127  myParameter.minGapLat = minGapLat;
128  }
130 }
131 
132 
133 void
134 MSVehicleType::setMaxSpeed(const double& maxSpeed) {
135  if (myOriginalType != 0 && maxSpeed < 0) {
137  } else {
138  myParameter.maxSpeed = maxSpeed;
139  }
141 }
142 
143 
144 void
145 MSVehicleType::setMaxSpeedLat(const double& maxSpeedLat) {
146  if (myOriginalType != 0 && maxSpeedLat < 0) {
148  } else {
149  myParameter.maxSpeedLat = maxSpeedLat;
150  }
152 }
153 
154 
155 void
157  myParameter.vehicleClass = vclass;
159 }
160 
161 void
163  myParameter.latAlignment = latAlignment;
165 }
166 
167 
168 void
170  if (myOriginalType != 0 && prob < 0) {
172  } else {
174  }
176 }
177 
178 
179 void
180 MSVehicleType::setSpeedFactor(const double& factor) {
181  if (myOriginalType != 0 && factor < 0) {
183  } else {
184  myParameter.speedFactor.getParameter()[0] = factor;
185  }
187 }
188 
189 
190 void
192  if (myOriginalType != 0 && dev < 0) {
194  } else {
196  }
198 }
199 
200 
201 void
202 MSVehicleType::setActionStepLength(const SUMOTime actionStepLength, bool resetActionOffset) {
203  assert(actionStepLength >= 0.);
205 
206  if (myParameter.actionStepLength == actionStepLength) {
207  return;
208  }
209 
210  SUMOTime previousActionStepLength = myParameter.actionStepLength;
211  myParameter.actionStepLength = actionStepLength;
213  check();
214 
215  if (isVehicleSpecific()) {
216  // don't perform vehicle lookup for singular vtype
217  return;
218  }
219 
220  // For non-singular vType reset all vehicle's actionOffsets
221  // Iterate through vehicles
223  for (auto vehIt = vc.loadedVehBegin(); vehIt != vc.loadedVehEnd(); ++vehIt) {
224  MSVehicle* veh = static_cast<MSVehicle*>(vehIt->second);
225  if (&veh->getVehicleType() == this) {
226  // Found vehicle of this type. Perform requested actionOffsetReset
227  if (resetActionOffset) {
228  veh->resetActionOffset();
229  } else {
230  veh->updateActionOffset(previousActionStepLength, actionStepLength);
231  }
232  }
233  }
234 }
235 
236 
237 void
239  myParameter.emissionClass = eclass;
241 }
242 
243 
244 void
246  myParameter.color = color;
248 }
249 
250 
251 void
252 MSVehicleType::setWidth(const double& width) {
253  if (myOriginalType != 0 && width < 0) {
255  } else {
256  myParameter.width = width;
257  }
259 }
260 
261 void
262 MSVehicleType::setImpatience(const double impatience) {
263  if (myOriginalType != 0 && impatience < 0) {
265  } else {
266  myParameter.impatience = impatience;
267  }
269 }
270 
271 
272 void
274  myParameter.shape = shape;
276 }
277 
278 
279 
280 // ------------ Static methods for building vehicle types
283  MSVehicleType* vtype = new MSVehicleType(from);
286  // by default decel and apparentDecel are identical (alternatively, defaults could be used)
287  //const double emergencyDecel = from.getCFParam(SUMO_ATTR_EMERGENCYDECEL, SUMOVTypeParameter::getDefaultEmergencyDecel(from.vehicleClass));
288  const double emergencyDecel = from.getCFParam(SUMO_ATTR_EMERGENCYDECEL, decel);
289  // by default decel and apparentDecel are identical
290  const double apparentDecel = from.getCFParam(SUMO_ATTR_APPARENTDECEL, decel);
291 
292  if (emergencyDecel < decel) {
293  WRITE_WARNING("Value of 'emergencyDecel' is should be higher than 'decel' for vType '" + from.id + "'.");
294  }
295  if (emergencyDecel < apparentDecel) {
296  WRITE_WARNING("Value of 'emergencyDecel' lower than 'apparentDecel' for vType '" + from.id + "' may cause collisions.");
297  }
298 
300  const double tau = from.getCFParam(SUMO_ATTR_TAU, 1.);
301  switch (from.cfModel) {
302  case SUMO_TAG_CF_IDM:
303  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, emergencyDecel, apparentDecel, tau,
306  break;
307  case SUMO_TAG_CF_IDMM:
308  vtype->myCarFollowModel = new MSCFModel_IDM(vtype, accel, decel, emergencyDecel, apparentDecel, tau,
312  break;
313  case SUMO_TAG_CF_BKERNER:
314  vtype->myCarFollowModel = new MSCFModel_Kerner(vtype, accel, decel, emergencyDecel, apparentDecel, tau,
315  from.getCFParam(SUMO_ATTR_K, .5),
317  break;
319  vtype->myCarFollowModel = new MSCFModel_KraussOrig1(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau);
320  break;
322  vtype->myCarFollowModel = new MSCFModel_KraussPS(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau);
323  break;
324  case SUMO_TAG_CF_KRAUSSX:
325  vtype->myCarFollowModel = new MSCFModel_KraussX(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau,
326  from.getCFParam(SUMO_ATTR_TMP1, 0.),
327  from.getCFParam(SUMO_ATTR_TMP2, 0.)
328  );
329  break;
331  vtype->myCarFollowModel = new MSCFModel_SmartSK(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau,
332  from.getCFParam(SUMO_ATTR_TMP1, 1.),
333  from.getCFParam(SUMO_ATTR_TMP2, 1.),
334  from.getCFParam(SUMO_ATTR_TMP3, 1.),
335  from.getCFParam(SUMO_ATTR_TMP4, 1.),
336  from.getCFParam(SUMO_ATTR_TMP5, 1.));
337  break;
338  case SUMO_TAG_CF_DANIEL1:
339  vtype->myCarFollowModel = new MSCFModel_Daniel1(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau,
340  from.getCFParam(SUMO_ATTR_TMP1, 1.),
341  from.getCFParam(SUMO_ATTR_TMP2, 1.),
342  from.getCFParam(SUMO_ATTR_TMP3, 1.),
343  from.getCFParam(SUMO_ATTR_TMP4, 1.),
344  from.getCFParam(SUMO_ATTR_TMP5, 1.));
345  break;
347  vtype->myCarFollowModel = new MSCFModel_PWag2009(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau,
350  break;
352  vtype->myCarFollowModel = new MSCFModel_Wiedemann(vtype, accel, decel, emergencyDecel, apparentDecel,
355  break;
356  case SUMO_TAG_CF_RAIL:
357  vtype->myCarFollowModel = new MSCFModel_Rail(vtype, from.getCFParamString(SUMO_ATTR_TRAIN_TYPE, "NGT400"));
358  break;
359  case SUMO_TAG_CF_KRAUSS:
360  default:
361  vtype->myCarFollowModel = new MSCFModel_Krauss(vtype, accel, decel, emergencyDecel, apparentDecel, sigma, tau);
362  break;
363  }
364  vtype->check();
365  return vtype;
366 }
367 
368 
370 MSVehicleType::buildSingularType(const std::string& id) const {
371  return duplicateType(id, false);
372 }
373 
374 
376 MSVehicleType::duplicateType(const std::string& id, bool persistent) const {
378  vtype->myParameter.id = id;
380  if (!persistent) {
381  vtype->myOriginalType = this;
382  }
383  if (!MSNet::getInstance()->getVehicleControl().addVType(vtype)) {
384  std::string singular = persistent ? "" : "singular ";
385  throw ProcessError("could not add " + singular + "type " + vtype->getID());
386  }
387  return vtype;
388 }
389 
390 void
396  std::stringstream s;
397  s << "Given action step length " << STEPS2TIME(myParameter.actionStepLength) << " for vehicle type '" << getID()
398  << "' is larger than its parameter tau (=" << getCarFollowModel().getHeadwayTime() << ")!"
399  << " This may lead to collisions. (This warning is only issued once per vehicle type).";
400  WRITE_WARNING(s.str());
401  }
402 }
403 
404 
405 /****************************************************************************/
406 
const int VTYPEPARS_MAXSPEED_SET
The Wiedemann Model car-following model.
const int VTYPEPARS_MINGAP_SET
void setMinGap(const double &minGap)
Set a new value for this type&#39;s minimum gap.
SumoXMLTag cfModel
The enum-representation of the car-following model to use.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
const int VTYPEPARS_LATALIGNMENT_SET
car-following model by B. Kerner
double impatience
The vehicle&#39;s impatience (willingness to obstruct others)
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
void setDefaultProbability(const double &prob)
Set a new value for this type&#39;s default probability.
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.
const int VTYPEPARS_MINGAP_LAT_SET
virtual MSCFModel * duplicate(const MSVehicleType *vtype) const =0
Duplicates the car-following model.
double defaultProbability
The probability when being added to a distribution without an explicit probability.
std::vector< double > & getParameter()
Returns the parameters of this distribution.
The Intelligent Driver Model (IDM) car-following model.
Definition: MSCFModel_IDM.h:47
Krauss car-following model, changing accel and speed by slope.
SUMOVehicleClass vehicleClass
The vehicle&#39;s class.
The original Krauss (1998) car-following model and parameter.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
T MAX2(T a, T b)
Definition: StdDefs.h:73
double getMinGapLat() const
Get the minimum lateral gap that vehicles of this type maintain.
const MSVehicleType * myOriginalType
The original type.
void setLength(const double &length)
Set a new value for this type&#39;s length.
void setMaxSpeed(const double &maxSpeed)
Set a new value for this type&#39;s maximum speed.
const int VTYPEPARS_MAXSPEED_LAT_SET
const int VTYPEPARS_PROBABILITY_SET
MSVehicleType * duplicateType(const std::string &id, bool persistent) const
Duplicates the microsim vehicle type giving the newly created type the given id.
static MSVehicleType * build(SUMOVTypeParameter &from)
Builds the microsim vehicle type described by the given parameter.
LateralAlignment
Numbers representing special SUMO-XML-attribute values Information how vehicles align themselves with...
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
The car-following model and parameter.
Definition: MSVehicleType.h:72
static double getDefaultAccel(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default acceleration for the given vehicle class This needs to be a function because the ...
double height
This class&#39; height.
bool isVehicleSpecific() const
Returns whether this type belongs to a single vehicle only (was modified)
static double getDefaultImperfection(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default driver&#39;s imperfection (sigma or epsilon in Krauss&#39; model) for the given vehicle c...
double getDefaultProbability() const
Get the default probability of this vehicle type.
void setMinGapLat(const double &minGapLat)
Set a new value for this type&#39;s minimum lataral gap.
bool wasSet(int what) const
Returns whether the given parameter was set.
double maxSpeed
The vehicle type&#39;s maximum speed [m/s].
double width
This class&#39; width.
const MSCFModel & getCarFollowModel() const
Returns the vehicle type&#39;s car following model definition (const version)
const int VTYPEPARS_ACTIONSTEPLENGTH_SET
void check()
Checks whether vehicle type parameters may be problematic (Currently, only the value for the action s...
MSVehicleType * buildSingularType(const std::string &id) const
Duplicates the microsim vehicle type giving the newly created type the given id, marking it as vehicl...
The original Krauss (1998) car-following model and parameter.
int SUMOEmissionClass
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:306
void setHeight(const double &height)
Set a new value for this type&#39;s height.
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
virtual ~MSVehicleType()
Destructor.
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
void resetActionOffset(const SUMOTime timeUntilNextAction=0)
Resets the action offset for the vehicle.
Definition: MSVehicle.cpp:1613
void setImpatience(const double impatience)
Set a new value for this type&#39;s impatience.
static double getDefaultDecel(const SUMOVehicleClass vc=SVC_IGNORING)
Returns the default deceleration for the given vehicle class This needs to be a function because the ...
void setEmissionClass(SUMOEmissionClass eclass)
Set a new value for this type&#39;s emission class.
double getMinGap() const
Get the free space in front of vehicles of this class.
void setSpeedDeviation(const double &dev)
Set a new value for this type&#39;s speed deviation.
void setSpeedFactor(const double &factor)
Set a new value for this type&#39;s speed factor.
const int VTYPEPARS_SPEEDFACTOR_SET
void setActionStepLength(const SUMOTime actionStepLength, bool resetActionOffset)
Set a new value for this type&#39;s action step length.
Scalable model based on Krauss by Peter Wagner.
double maxSpeedLat
The vehicle type&#39;s maximum lateral speed [m/s].
double getCFParam(const SumoXMLAttr attr, const double defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
int parametersSet
Information for the router which parameter were set.
The original Krauss (1998) car-following model and parameter.
SUMOVTypeParameter myParameter
the parameter container
double getMaxSpeedLat() const
Get vehicle&#39;s maximum lateral speed [m/s].
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
MSCFModel * myCarFollowModel
instance of the car following model.
double getHeight() const
Get the height which vehicles of this class shall have when being drawn.
static SUMOTime gActionStepLength
default value for the interval between two action points for MSVehicle (defaults to DELTA_T) ...
Definition: MSGlobals.h:118
double minGapLat
The vehicle type&#39;s minimum lateral gap [m].
std::string getCFParamString(const SumoXMLAttr attr, const std::string defaultValue) const
Returns the named value from the map, or the default if it is not contained there.
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
virtual double getHeadwayTime() const
Get the driver&#39;s desired headway [s].
Definition: MSCFModel.h:246
RGBColor color
The color.
static int myNextIndex
next value for the running index
const std::string & getID() const
Returns the name of the vehicle type.
void setWidth(const double &width)
Set a new value for this type&#39;s width.
std::string id
The vehicle type&#39;s id.
void updateActionOffset(const SUMOTime oldActionStepLength, const SUMOTime newActionStepLength)
Process an updated action step length value (only affects the vehicle&#39;s action offset, The actionStepLength is stored in the (singular) vtype)
Definition: MSVehicle.cpp:1618
double getLength() const
Get vehicle&#39;s length [m].
MSVehicleType(const SUMOVTypeParameter &parameter)
Constructor.
void setVClass(SUMOVehicleClass vclass)
Set a new value for this type&#39;s vehicle class.
LateralAlignment latAlignment
The vehicles desired lateral alignment.
SUMOTime actionStepLength
The vehicle type&#39;s default actionStepLength [ms], i.e. the interval between two control actions...
double minGap
This class&#39; free space in front of the vehicle itself.
const int VTYPEPARS_HEIGHT_SET
void setColor(const RGBColor &color)
Set a new value for this type&#39;s color.
double sample(std::mt19937 *which=0) const
Draw a sample of the distribution.
long long int SUMOTime
Definition: TraCIDefs.h:51
bool myWarnedActionStepLengthTauOnce
Indicator whether the user was already warned once about an action step length larger than the desire...
const int VTYPEPARS_WIDTH_SET
double getImpatience() const
Returns this type&#39;s impatience.
The class responsible for building and deletion of vehicles.
double computeChosenSpeedDeviation(std::mt19937 *rng, const double minDev=-1.) const
Computes and returns the speed deviation.
void setMaxSpeedLat(const double &maxSpeedLat)
Set a new value for this type&#39;s maximum lateral speed.
void setPreferredLateralAlignment(LateralAlignment latAlignment)
Set vehicle&#39;s preferred lateral alignment.
Krauss car-following model, with acceleration decrease and faster start.
const int VTYPEPARS_LENGTH_SET
const int VTYPEPARS_VEHICLECLASS_SET
Krauss car-following model, changing accel and speed by slope.
const int VTYPEPARS_EMISSIONCLASS_SET
const int VTYPEPARS_COLOR_SET
Distribution_Parameterized speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street...
const int VTYPEPARS_SHAPE_SET
double length
The physical vehicle length.
SUMOEmissionClass emissionClass
The emission class of this vehicle.
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
double myCachedActionStepLengthSecs
the vtypes actionsStepLength in seconds (cached because needed very often)
const int VTYPEPARS_IMPATIENCE_SET