SUMO - Simulation of Urban MObility
SUMOVehicleParameter.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // Structure representing possible vehicle parameter
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include "SUMOVehicleParameter.h"
34 #include <utils/common/ToString.h>
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // member method definitions
47 // ===========================================================================
49  : vtypeid(DEFAULT_VTYPE_ID), color(RGBColor::DEFAULT_COLOR),
50  depart(-1), departProcedure(DEPART_GIVEN),
51  departLane(0), departLaneProcedure(DEPART_LANE_DEFAULT),
52  departPos(0), departPosProcedure(DEPART_POS_DEFAULT),
53  departSpeed(-1), departSpeedProcedure(DEPART_SPEED_DEFAULT),
54  arrivalLane(0), arrivalLaneProcedure(ARRIVAL_LANE_DEFAULT),
55  arrivalPos(0), arrivalPosProcedure(ARRIVAL_POS_DEFAULT),
56  arrivalSpeed(-1), arrivalSpeedProcedure(ARRIVAL_SPEED_DEFAULT),
57  repetitionNumber(-1), repetitionsDone(-1), repetitionOffset(-1), repetitionProbability(-1), repetitionEnd(-1),
58  line(), fromTaz(), toTaz(), personNumber(0), containerNumber(0), setParameter(0) {
59 }
60 
61 
62 bool
63 SUMOVehicleParameter::defaultOptionOverrides(const OptionsCont& oc, const std::string& optionName) const {
64  return oc.isSet(optionName) && oc.getBool("defaults-override");
65 }
66 
67 
68 void
73  }
75  dev.writeAttr(SUMO_ATTR_DEPART, "triggered");
77  dev.writeAttr(SUMO_ATTR_DEPART, "containerTriggered");
78  } else {
80  }
81 
82  // optional parameter
83  // departlane
84  if (wasSet(VEHPARS_DEPARTLANE_SET) && !defaultOptionOverrides(oc, "departlane")) {
85  std::string val;
86  switch (departLaneProcedure) {
87  case DEPART_LANE_GIVEN:
88  val = toString(departLane);
89  break;
90  case DEPART_LANE_RANDOM:
91  val = "random";
92  break;
93  case DEPART_LANE_FREE:
94  val = "free";
95  break;
97  val = "allowed";
98  break;
100  val = "best";
101  break;
103  val = "first";
104  break;
105  case DEPART_LANE_DEFAULT:
106  default:
107  break;
108  }
110  } else if (oc.isSet("departlane")) {
111  dev.writeNonEmptyAttr(SUMO_ATTR_DEPARTLANE, oc.getString("departlane"));
112  }
113  // departpos
114  if (wasSet(VEHPARS_DEPARTPOS_SET) && !defaultOptionOverrides(oc, "departpos")) {
115  std::string val;
116  switch (departPosProcedure) {
117  case DEPART_POS_GIVEN:
118  val = toString(departPos);
119  break;
120  case DEPART_POS_RANDOM:
121  val = "random";
122  break;
124  val = "random_free";
125  break;
126  case DEPART_POS_FREE:
127  val = "free";
128  break;
130  val = "pwagSimple";
131  break;
133  val = "pwagGeneric";
134  break;
136  val = "maxSpeedGap";
137  break;
138  case DEPART_POS_BASE:
139  val = "base";
140  break;
141  case DEPART_POS_DEFAULT:
142  default:
143  break;
144  }
146  } else if (oc.isSet("departpos")) {
147  dev.writeNonEmptyAttr(SUMO_ATTR_DEPARTPOS, oc.getString("departpos"));
148  }
149  // departspeed
150  if (wasSet(VEHPARS_DEPARTSPEED_SET) && !defaultOptionOverrides(oc, "departspeed")) {
151  std::string val;
152  switch (departSpeedProcedure) {
153  case DEPART_SPEED_GIVEN:
154  val = toString(departSpeed);
155  break;
156  case DEPART_SPEED_RANDOM:
157  val = "random";
158  break;
159  case DEPART_SPEED_MAX:
160  val = "max";
161  break;
163  default:
164  break;
165  }
167  } else if (oc.isSet("departspeed")) {
168  dev.writeNonEmptyAttr(SUMO_ATTR_DEPARTSPEED, oc.getString("departspeed"));
169  }
170 
171  // arrivallane
172  if (wasSet(VEHPARS_ARRIVALLANE_SET) && !defaultOptionOverrides(oc, "arrivallane")) {
173  std::string val;
174  switch (arrivalLaneProcedure) {
175  case ARRIVAL_LANE_GIVEN:
176  val = toString(arrivalLane);
177  break;
179  val = "current";
180  break;
182  default:
183  break;
184  }
186  } else if (oc.isSet("arrivallane")) {
187  dev.writeNonEmptyAttr(SUMO_ATTR_ARRIVALLANE, oc.getString("arrivallane"));
188  }
189  // arrivalpos
190  if (wasSet(VEHPARS_ARRIVALPOS_SET) && !defaultOptionOverrides(oc, "arrivalpos")) {
191  std::string val;
192  switch (arrivalPosProcedure) {
193  case ARRIVAL_POS_GIVEN:
194  val = toString(arrivalPos);
195  break;
196  case ARRIVAL_POS_RANDOM:
197  val = "random";
198  break;
199  case ARRIVAL_POS_MAX:
200  val = "max";
201  break;
202  case ARRIVAL_POS_DEFAULT:
203  default:
204  break;
205  }
207  } else if (oc.isSet("arrivalpos")) {
208  dev.writeNonEmptyAttr(SUMO_ATTR_ARRIVALPOS, oc.getString("arrivalpos"));
209  }
210  // arrivalspeed
211  if (wasSet(VEHPARS_ARRIVALSPEED_SET) && !defaultOptionOverrides(oc, "arrivalspeed")) {
212  std::string val;
213  switch (arrivalSpeedProcedure) {
214  case ARRIVAL_SPEED_GIVEN:
215  val = toString(arrivalSpeed);
216  break;
218  val = "current";
219  break;
221  default:
222  break;
223  }
225  } else if (oc.isSet("arrivalspeed")) {
226  dev.writeNonEmptyAttr(SUMO_ATTR_ARRIVALSPEED, oc.getString("arrivalspeed"));
227  }
228 
229  // color
230  if (wasSet(VEHPARS_COLOR_SET)) {
232  }
233  if (wasSet(VEHPARS_LINE_SET)) {
235  }
238  }
239  if (wasSet(VEHPARS_TO_TAZ_SET)) {
241  }
244  }
247  }
248 }
249 
250 
251 void
253  for (std::vector<Stop>::const_iterator stop = stops.begin(); stop != stops.end(); ++stop) {
254  dev.openTag(SUMO_TAG_STOP);
255  if (stop->busstop != "") {
256  dev.writeAttr(SUMO_ATTR_BUS_STOP, stop->busstop);
257  }
258  if (stop->containerstop != "") {
259  dev.writeAttr(SUMO_ATTR_CONTAINER_STOP, stop->containerstop);
260  }
261  if (stop->busstop == "" && stop->containerstop == "") {
262  dev.writeAttr(SUMO_ATTR_LANE, stop->lane);
263  if ((stop->setParameter & STOP_START_SET) != 0) {
264  dev.writeAttr(SUMO_ATTR_STARTPOS, stop->startPos);
265  }
266  if ((stop->setParameter & STOP_END_SET) != 0) {
267  dev.writeAttr(SUMO_ATTR_ENDPOS, stop->endPos);
268  }
269  }
270  if (stop->duration >= 0) {
271  dev.writeAttr(SUMO_ATTR_DURATION, STEPS2TIME(stop->duration));
272  }
273  if (stop->until >= 0) {
274  dev.writeAttr(SUMO_ATTR_UNTIL, STEPS2TIME(stop->until));
275  }
276  if ((stop->setParameter & STOP_TRIGGER_SET) != 0) {
277  dev.writeAttr(SUMO_ATTR_TRIGGERED, stop->triggered);
278  }
279  if ((stop->setParameter & STOP_CONTAINER_TRIGGER_SET) != 0) {
280  dev.writeAttr(SUMO_ATTR_CONTAINER_TRIGGERED, stop->containerTriggered);
281  }
282  if ((stop->setParameter & STOP_PARKING_SET) != 0) {
283  dev.writeAttr(SUMO_ATTR_PARKING, stop->parking);
284  }
285  // look, we are writing the set of expected persons in its current state...
286  // if this method is used somewhere in the simulation output,
287  // one should consider keeping the original values additionally,
288  // as the ones we write may hev changed.
289  if ((stop->setParameter & STOP_EXPECTED_SET) != 0) {
290  dev.writeAttr(SUMO_ATTR_EXPECTED, stop->awaitedPersons);
291  }
292  if ((stop->setParameter & STOP_EXPECTED_CONTAINERS_SET) != 0) {
293  dev.writeAttr(SUMO_ATTR_EXPECTED_CONTAINERS, stop->awaitedContainers);
294  }
295  dev.closeTag();
296  }
297 }
298 
299 
300 bool
301 SUMOVehicleParameter::parseDepart(const std::string& val, const std::string& element, const std::string& id,
302  SUMOTime& depart, DepartDefinition& dd, std::string& error) {
303  if (val == "triggered") {
304  dd = DEPART_TRIGGERED;
305  } else if (val == "containerTriggered") {
307  } else if (val == "now") {
308  dd = DEPART_NOW;
309  } else {
310  try {
311  depart = string2time(val);
312  dd = DEPART_GIVEN;
313  if (depart < 0) {
314  error = "Negative departure time in the definition of '" + id + "'.";
315  return false;
316  }
317  } catch (...) {
318  error = "Invalid departure time for " + element + " '" + id + "';\n must be one of (\"triggered\", \"containerTriggered\", \"now\", or a float >= 0)";
319  return false;
320  }
321  }
322  return true;
323 }
324 
325 
326 bool
327 SUMOVehicleParameter::parseDepartLane(const std::string& val, const std::string& element, const std::string& id,
328  int& lane, DepartLaneDefinition& dld, std::string& error) {
329  bool ok = true;
330  if (val == "random") {
331  dld = DEPART_LANE_RANDOM;
332  } else if (val == "free") {
333  dld = DEPART_LANE_FREE;
334  } else if (val == "allowed") {
336  } else if (val == "best") {
337  dld = DEPART_LANE_BEST_FREE;
338  } else if (val == "first") {
340  } else {
341  try {
342  lane = TplConvert::_2int(val.c_str());
343  dld = DEPART_LANE_GIVEN;
344  if (lane < 0) {
345  ok = false;
346  }
347  } catch (...) {
348  ok = false;
349  }
350  }
351  if (!ok) {
352  error = "Invalid departLane definition for " + element + " '" + id + "';\n must be one of (\"random\", \"free\", \"allowed\", \"best\", \"first\", or an int>=0)";
353  }
354  return ok;
355 }
356 
357 
358 bool
359 SUMOVehicleParameter::parseDepartPos(const std::string& val, const std::string& element, const std::string& id,
360  SUMOReal& pos, DepartPosDefinition& dpd, std::string& error) {
361  bool ok = true;
362  if (val == "random") {
363  dpd = DEPART_POS_RANDOM;
364  } else if (val == "random_free") {
366  } else if (val == "free") {
367  dpd = DEPART_POS_FREE;
368  } else if (val == "base") {
369  dpd = DEPART_POS_BASE;
370  } else if (val == "pwagSimple") {
372  } else if (val == "pwagGeneric") {
374  } else if (val == "maxSpeedGap") {
376  } else {
377  try {
378  pos = TplConvert::_2SUMOReal(val.c_str());
379  dpd = DEPART_POS_GIVEN;
380  } catch (...) {
381  ok = false;
382  }
383  }
384  if (!ok) {
385  error = "Invalid departPos definition for " + element + " '" + id + "';\n must be one of (\"random\", \"random_free\", \"free\", \"base\", \"pwagSimple\", \"pwagGeneric\", \"maxSpeedGap\", or a float)";
386  }
387  return ok;
388 }
389 
390 
391 bool
392 SUMOVehicleParameter::parseDepartSpeed(const std::string& val, const std::string& element, const std::string& id,
393  SUMOReal& speed, DepartSpeedDefinition& dsd, std::string& error) {
394  bool ok = true;
395  if (val == "random") {
396  dsd = DEPART_SPEED_RANDOM;
397  } else if (val == "max") {
398  dsd = DEPART_SPEED_MAX;
399  } else {
400  try {
401  speed = TplConvert::_2SUMOReal(val.c_str());
402  dsd = DEPART_SPEED_GIVEN;
403  if (speed < 0) {
404  ok = false;
405  }
406  } catch (...) {
407  ok = false;
408  }
409  }
410  if (!ok) {
411  error = "Invalid departSpeed definition for " + element + " '" + id + "';\n must be one of (\"random\", \"max\", or a float>=0)";
412  }
413  return ok;
414 }
415 
416 
417 bool
418 SUMOVehicleParameter::parseArrivalLane(const std::string& val, const std::string& element, const std::string& id,
419  int& lane, ArrivalLaneDefinition& ald, std::string& error) {
420  bool ok = true;
421  if (val == "current") {
422  ald = ARRIVAL_LANE_CURRENT;
423  } else {
424  try {
425  lane = TplConvert::_2int(val.c_str());
426  ald = ARRIVAL_LANE_GIVEN;
427  if (lane < 0) {
428  ok = false;
429  }
430  } catch (...) {
431  ok = false;
432  }
433  }
434  if (!ok) {
435  error = "Invalid arrivalLane definition for " + element + " '" + id + "';\n must be one of (\"current\", or an int>=0)";
436  }
437  return ok;
438 }
439 
440 
441 bool
442 SUMOVehicleParameter::parseArrivalPos(const std::string& val, const std::string& element, const std::string& id,
443  SUMOReal& pos, ArrivalPosDefinition& apd, std::string& error) {
444  bool ok = true;
445  if (val == "random") {
446  apd = ARRIVAL_POS_RANDOM;
447  } else if (val == "max") {
448  apd = ARRIVAL_POS_MAX;
449  } else {
450  try {
451  pos = TplConvert::_2SUMOReal(val.c_str());
452  apd = ARRIVAL_POS_GIVEN;
453  } catch (...) {
454  ok = false;
455  }
456  }
457  if (!ok) {
458  error = "Invalid arrivalPos definition for " + element + " '" + id + "';\n must be one of (\"random\", \"max\", or a float)";
459  }
460  return ok;
461 }
462 
463 
464 bool
465 SUMOVehicleParameter::parseArrivalSpeed(const std::string& val, const std::string& element, const std::string& id,
466  SUMOReal& speed, ArrivalSpeedDefinition& asd, std::string& error) {
467  bool ok = true;
468  if (val == "current") {
469  asd = ARRIVAL_SPEED_CURRENT;
470  } else {
471  try {
472  speed = TplConvert::_2SUMOReal(val.c_str());
473  if (speed < 0) {
474  ok = false;
475  }
476  asd = ARRIVAL_SPEED_GIVEN;
477  } catch (...) {
478  ok = false;
479  }
480  }
481  if (!ok) {
482  error = "Invalid arrivalSpeed definition for " + element + " '" + id + "';\n must be one of (\"current\", or a float>=0)";
483  }
484  return ok;
485 }
486 
487 
488 SUMOReal
489 SUMOVehicleParameter::interpretEdgePos(SUMOReal pos, SUMOReal maximumValue, SumoXMLAttr attr, const std::string& id) {
490  if (pos < 0) {
491  pos = maximumValue + pos;
492  }
493  if (pos > maximumValue) {
494  WRITE_WARNING("Invalid " + toString(attr) + " " + toString(pos) + " given for " + id + ". Using edge end instead.");
495  pos = maximumValue;
496  }
497  return pos;
498 }
499 
500 
501 /****************************************************************************/
The departure is person triggered.
const int VEHPARS_TO_TAZ_SET
The current lane shall be used.
const int STOP_CONTAINER_TRIGGER_SET
No information given; use default.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:257
RGBColor color
The vehicle&#39;s color.
long long int SUMOTime
Definition: SUMOTime.h:43
The time is given.
static bool parseDepartSpeed(const std::string &val, const std::string &element, const std::string &id, SUMOReal &speed, DepartSpeedDefinition &dsd, std::string &error)
Validates a given departSpeed value.
The vehicle is discarded if emission fails (not fully implemented yet)
std::string vtypeid
The vehicle&#39;s type id.
static bool parseArrivalPos(const std::string &val, const std::string &element, const std::string &id, SUMOReal &pos, ArrivalPosDefinition &apd, std::string &error)
Validates a given arrivalPos value.
ArrivalLaneDefinition
Possible ways to choose the arrival lane.
void writeStops(OutputDevice &dev) const
Writes the enclosed stops.
static SUMOReal _2SUMOReal(const E *const data)
Definition: TplConvert.h:242
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
The speed is given.
The departure is container triggered.
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
SUMOReal departSpeed
(optional) The initial speed of the vehicle
The position is given.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
SUMOReal arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
The least occupied lane is used.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:61
SUMOReal arrivalPos
(optional) The position the vehicle shall arrive on
const int VEHPARS_ARRIVALLANE_SET
The speed is chosen randomly.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
The lane is chosen randomly.
unsigned int personNumber
The static number of persons in the vehicle when it departs (not including boarding persons) ...
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle&#39;s end speed shall be chosen.
The arrival position is given.
const std::string DEFAULT_VTYPE_ID
The least occupied lane from best lanes.
The position is chosen randomly.
Generic max-flow insertion by P.Wagner.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
The speed is given.
A gap is chosen where the maximum speed may be achieved.
std::string toTaz
The vehicle&#39;s destination zone (district)
The lane is given.
std::vector< Stop > stops
List of the stops the vehicle will make.
const int VEHPARS_ARRIVALSPEED_SET
static SUMOReal interpretEdgePos(SUMOReal pos, SUMOReal maximumValue, SumoXMLAttr attr, const std::string &id)
Interprets negative edge positions and fits them onto a given edge.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
SUMOVehicleParameter()
Constructor.
const int STOP_START_SET
bool defaultOptionOverrides(const OptionsCont &oc, const std::string &optionName) const
Returns whether the defaults shall be used.
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle&#39;s initial speed shall be chosen.
DepartLaneDefinition
Possible ways to choose a lane on depart.
OutputDevice & writeNonEmptyAttr(const SumoXMLAttr attr, const std::string &val)
writes a string attribute only if it is not the empty string and not the string "default" ...
Definition: OutputDevice.h:290
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
The least occupied lane from lanes which allow the continuation.
bool wasSet(int what) const
Returns whether the given parameter was set.
const int VEHPARS_DEPARTSPEED_SET
The current speed is used.
int arrivalLane
(optional) The lane the vehicle shall arrive on (not used yet)
SUMOTime depart
The vehicle&#39;s departure time.
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
The maximum speed is used.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:48
virtual bool ok()
returns the information whether one can write into the device
std::string fromTaz
The vehicle&#39;s origin zone (district)
No information given; use default.
const int STOP_EXPECTED_SET
static bool parseArrivalLane(const std::string &val, const std::string &element, const std::string &id, int &lane, ArrivalLaneDefinition &ald, std::string &error)
Validates a given arrivalLane value.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
const int VEHPARS_COLOR_SET
If a fixed number of random choices fails, a free position is chosen.
static bool parseDepartPos(const std::string &val, const std::string &element, const std::string &id, SUMOReal &pos, DepartPosDefinition &dpd, std::string &error)
Validates a given departPos value.
const int VEHPARS_FROM_TAZ_SET
The rightmost lane the vehicle may use.
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
std::string line
The vehicle&#39;s line (mainly for public transport)
DepartSpeedDefinition
Possible ways to choose the departure speed.
const int STOP_END_SET
const int VEHPARS_LINE_SET
static bool parseArrivalSpeed(const std::string &val, const std::string &element, const std::string &id, SUMOReal &speed, ArrivalSpeedDefinition &asd, std::string &error)
Validates a given arrivalSpeed value.
const int VEHPARS_ARRIVALPOS_SET
No information given; use default.
const int STOP_PARKING_SET
static int _2int(const E *const data)
Definition: TplConvert.h:114
const int STOP_TRIGGER_SET
const int STOP_EXPECTED_CONTAINERS_SET
A storage for options typed value containers)
Definition: OptionsCont.h:108
const int VEHPARS_DEPARTLANE_SET
No information given; use default.
The arrival lane is given.
SUMOReal departPos
(optional) The position the vehicle shall depart from
void write(OutputDevice &dev, const OptionsCont &oc) const
Writes the parameters as a beginning element.
const int VEHPARS_VTYPE_SET
No information given; use default.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71
bool closeTag()
Closes the most recently opened tag.
#define SUMOReal
Definition: config.h:214
ArrivalPosDefinition
Possible ways to choose the arrival position.
No information given; use default.
A free position is chosen.
const int VEHPARS_DEPARTPOS_SET
Simple max-flow insertion by P.Wagner.
const int VEHPARS_PERSON_NUMBER_SET
unsigned int containerNumber
The static number of containers in the vehicle when it departs.
ArrivalSpeedDefinition
Possible ways to choose the arrival speed.
DepartPosDefinition
Possible ways to choose the departure position.
const int VEHPARS_CONTAINER_NUMBER_SET
A color information.
The maximum arrival position is used.
Back-at-zero position.
DepartDefinition
Possible ways to depart.
static bool parseDepart(const std::string &val, const std::string &element, const std::string &id, SUMOTime &depart, DepartDefinition &dd, std::string &error)
Validates a given depart value.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static bool parseDepartLane(const std::string &val, const std::string &element, const std::string &id, int &lane, DepartLaneDefinition &dld, std::string &error)
Validates a given departLane value.
The arrival position is chosen randomly.