SUMO - Simulation of Urban MObility
SUMOVehicleParserHelper.cpp
Go to the documentation of this file.
1 /****************************************************************************/
11 // Helper methods for parsing vehicle attributes
12 /****************************************************************************/
13 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
14 // Copyright (C) 2008-2017 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 
37 #include <utils/common/ToString.h>
45 
46 
47 // ===========================================================================
48 // static members
49 // ===========================================================================
52 std::set<SumoXMLAttr> SUMOVehicleParserHelper::allowedJMAttrs;
53 
54 
55 // ===========================================================================
56 // method definitions
57 // ===========================================================================
59 SUMOVehicleParserHelper::parseFlowAttributes(const SUMOSAXAttributes& attrs, const SUMOTime beginDefault, const SUMOTime endDefault) {
60  bool ok = true;
61  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
63  throw ProcessError("At most one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
64  "' and '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
65  "' has to be given in the definition of flow '" + id + "'.");
66  }
68  throw ProcessError("At most one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
69  "' and '" + attrs.getName(SUMO_ATTR_PROB) +
70  "' has to be given in the definition of flow '" + id + "'.");
71  }
73  throw ProcessError("At most one of '" + attrs.getName(SUMO_ATTR_PROB) +
74  "' and '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
75  "' has to be given in the definition of flow '" + id + "'.");
76  }
79  throw ProcessError("If '" + attrs.getName(SUMO_ATTR_PERIOD) +
80  "', '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
81  "' or '" + attrs.getName(SUMO_ATTR_PROB) +
82  "' are given at most one of '" + attrs.getName(SUMO_ATTR_END) +
83  "' and '" + attrs.getName(SUMO_ATTR_NUMBER) +
84  "' are allowed in flow '" + id + "'.");
85  }
86  } else {
87  if (!attrs.hasAttribute(SUMO_ATTR_NUMBER)) {
88  throw ProcessError("At least one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
89  "', '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
90  "', '" + attrs.getName(SUMO_ATTR_PROB) +
91  "', and '" + attrs.getName(SUMO_ATTR_NUMBER) +
92  "' is needed in flow '" + id + "'.");
93  }
94  }
96  ret->id = id;
97  try {
98  parseCommonAttributes(attrs, ret, "flow");
99  } catch (ProcessError&) {
100  delete ret;
101  throw;
102  }
103 
104  // parse repetition information
105  if (attrs.hasAttribute(SUMO_ATTR_PERIOD)) {
106  ret->setParameter |= VEHPARS_PERIODFREQ_SET;
107  ret->repetitionOffset = attrs.getSUMOTimeReporting(SUMO_ATTR_PERIOD, id.c_str(), ok);
108  }
109  if (attrs.hasAttribute(SUMO_ATTR_VEHSPERHOUR)) {
110  ret->setParameter |= VEHPARS_PERIODFREQ_SET;
111  const double vph = attrs.get<double>(SUMO_ATTR_VEHSPERHOUR, id.c_str(), ok);
112  if (ok && vph <= 0) {
113  delete ret;
114  throw ProcessError("Invalid repetition rate in the definition of flow '" + id + "'.");
115  }
116  if (ok && vph != 0) {
117  ret->repetitionOffset = TIME2STEPS(3600. / vph);
118  }
119  }
120  if (attrs.hasAttribute(SUMO_ATTR_PROB)) {
121  ret->repetitionProbability = attrs.get<double>(SUMO_ATTR_PROB, id.c_str(), ok);
122  if (ok && (ret->repetitionProbability <= 0 || ret->repetitionProbability > 1)) {
123  delete ret;
124  throw ProcessError("Invalid repetition probability in the definition of flow '" + id + "'.");
125  }
126  }
127 
128  ret->depart = beginDefault;
129  if (attrs.hasAttribute(SUMO_ATTR_BEGIN)) {
130  ret->depart = attrs.getSUMOTimeReporting(SUMO_ATTR_BEGIN, id.c_str(), ok);
131  }
132  if (ok && ret->depart < 0) {
133  delete ret;
134  throw ProcessError("Negative begin time in the definition of flow '" + id + "'.");
135  }
136  ret->repetitionEnd = endDefault;
137  if (ret->repetitionEnd < 0) {
138  ret->repetitionEnd = SUMOTime_MAX;
139  }
140  if (attrs.hasAttribute(SUMO_ATTR_END)) {
141  ret->repetitionEnd = attrs.getSUMOTimeReporting(SUMO_ATTR_END, id.c_str(), ok);
142  } else if (endDefault >= TIME2STEPS(9223372036854773)) {
143  // see SUMOTIME_MAXSTRING (which differs slightly from SUMOTime_MAX)
144  WRITE_WARNING("Undefined end for flow '" + id + "', defaulting to 24hour duration.");
145  ret->repetitionEnd = ret->depart + TIME2STEPS(24 * 3600);
146  }
147  if (ok && ret->repetitionEnd < ret->depart) {
148  delete ret;
149  throw ProcessError("Flow '" + id + "' ends before its begin time.");
150  }
151  if (attrs.hasAttribute(SUMO_ATTR_NUMBER)) {
152  ret->repetitionNumber = attrs.get<int>(SUMO_ATTR_NUMBER, id.c_str(), ok);
153  ret->setParameter |= VEHPARS_PERIODFREQ_SET;
154  if (ret->repetitionNumber == 0) {
155  WRITE_WARNING("Flow '" + id + "' has 0 vehicles; will skip it.");
156  } else {
157  if (ok && ret->repetitionNumber < 0) {
158  delete ret;
159  throw ProcessError("Negative repetition number in the definition of flow '" + id + "'.");
160  }
161  if (ok && ret->repetitionOffset < 0) {
162  ret->repetitionOffset = (ret->repetitionEnd - ret->depart) / ret->repetitionNumber;
163  }
164  }
165  ret->repetitionEnd = ret->depart + ret->repetitionNumber * ret->repetitionOffset;
166  } else {
167  // interpret repetitionNumber
168  if (ok && ret->repetitionProbability > 0) {
169  ret->repetitionNumber = std::numeric_limits<int>::max();
170  } else {
171  if (ok && ret->repetitionOffset <= 0) {
172  delete ret;
173  throw ProcessError("Invalid repetition rate in the definition of flow '" + id + "'.");
174  }
175  if (ret->repetitionEnd == SUMOTime_MAX) {
176  ret->repetitionNumber = std::numeric_limits<int>::max();
177  } else {
178  const double repLength = (double)(ret->repetitionEnd - ret->depart);
179  ret->repetitionNumber = (int)ceil(repLength / ret->repetitionOffset);
180  }
181  }
182  }
183  if (!ok) {
184  delete ret;
185  throw ProcessError();
186  }
187  return ret;
188 }
189 
190 
193  const bool optionalID, const bool skipDepart, const bool isPerson) {
194  bool ok = true;
195  std::string id, errorMsg;
196  if (optionalID) {
197  id = attrs.getOpt<std::string>(SUMO_ATTR_ID, 0, ok, "");
198  } else {
199  id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
200  }
202  ret->id = id;
203  if (isPerson) {
204  ret->vtypeid = DEFAULT_PEDTYPE_ID;
205  }
206  try {
207  parseCommonAttributes(attrs, ret, "vehicle");
208  if (!skipDepart) {
209  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPART, ret->id.c_str(), ok);
210  if (!ok || !SUMOVehicleParameter::parseDepart(helper, "vehicle", ret->id, ret->depart, ret->departProcedure, errorMsg)) {
211  throw ProcessError(errorMsg);
212  }
213  }
214  } catch (ProcessError&) {
215  delete ret;
216  throw;
217  }
218  return ret;
219 }
220 
221 
222 void
224  SUMOVehicleParameter* ret, std::string element) {
225  //ret->refid = attrs.getStringSecure(SUMO_ATTR_REFID, "");
226  bool ok = true;
227  // parse route information
228  if (attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
229  ret->setParameter |= VEHPARS_ROUTE_SET; // !!! needed?
230  ret->routeid = attrs.get<std::string>(SUMO_ATTR_ROUTE, ret->id.c_str(), ok);
231  }
232  // parse type information
233  if (attrs.hasAttribute(SUMO_ATTR_TYPE)) {
234  ret->setParameter |= VEHPARS_VTYPE_SET; // !!! needed?
235  ret->vtypeid = attrs.get<std::string>(SUMO_ATTR_TYPE, ret->id.c_str(), ok);
236  }
237  // parse line information
238  if (attrs.hasAttribute(SUMO_ATTR_LINE)) {
239  ret->setParameter |= VEHPARS_LINE_SET; // !!! needed?
240  ret->line = attrs.get<std::string>(SUMO_ATTR_LINE, ret->id.c_str(), ok);
241  }
242  // parse zone information
243  if (attrs.hasAttribute(SUMO_ATTR_FROM_TAZ)) {
245  ret->fromTaz = attrs.get<std::string>(SUMO_ATTR_FROM_TAZ, ret->id.c_str(), ok);
246  }
247  if (attrs.hasAttribute(SUMO_ATTR_TO_TAZ)) {
249  ret->toTaz = attrs.get<std::string>(SUMO_ATTR_TO_TAZ, ret->id.c_str(), ok);
250  }
251  // parse reroute information
252  if (attrs.getOpt<bool>(SUMO_ATTR_REROUTE, 0, ok, false)) {
254  }
255 
256  std::string error;
257  // parse depart lane information
258  if (attrs.hasAttribute(SUMO_ATTR_DEPARTLANE)) {
260  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTLANE, ret->id.c_str(), ok);
261  if (!SUMOVehicleParameter::parseDepartLane(helper, element, ret->id, ret->departLane, ret->departLaneProcedure, error)) {
262  throw ProcessError(error);
263  }
264  }
265  // parse depart position information
266  if (attrs.hasAttribute(SUMO_ATTR_DEPARTPOS)) {
268  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTPOS, ret->id.c_str(), ok);
269  if (!SUMOVehicleParameter::parseDepartPos(helper, element, ret->id, ret->departPos, ret->departPosProcedure, error)) {
270  throw ProcessError(error);
271  }
272  }
273  // parse lateral depart position information
276  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTPOS_LAT, ret->id.c_str(), ok);
277  if (!SUMOVehicleParameter::parseDepartPosLat(helper, element, ret->id, ret->departPosLat, ret->departPosLatProcedure, error)) {
278  throw ProcessError(error);
279  }
280  }
281  // parse depart speed information
282  if (attrs.hasAttribute(SUMO_ATTR_DEPARTSPEED)) {
284  std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTSPEED, ret->id.c_str(), ok);
285  if (!SUMOVehicleParameter::parseDepartSpeed(helper, element, ret->id, ret->departSpeed, ret->departSpeedProcedure, error)) {
286  throw ProcessError(error);
287  }
288  }
289 
290  // parse arrival lane information
291  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALLANE)) {
293  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALLANE, ret->id.c_str(), ok);
294  if (!SUMOVehicleParameter::parseArrivalLane(helper, element, ret->id, ret->arrivalLane, ret->arrivalLaneProcedure, error)) {
295  throw ProcessError(error);
296  }
297  }
298  // parse arrival position information
299  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
301  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, ret->id.c_str(), ok);
302  if (!SUMOVehicleParameter::parseArrivalPos(helper, element, ret->id, ret->arrivalPos, ret->arrivalPosProcedure, error)) {
303  throw ProcessError(error);
304  }
305  }
306  // parse lateral arrival position information
309  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS_LAT, ret->id.c_str(), ok);
310  if (!SUMOVehicleParameter::parseArrivalPosLat(helper, element, ret->id, ret->arrivalPosLat, ret->arrivalPosLatProcedure, error)) {
311  throw ProcessError(error);
312  }
313  }
314  // parse arrival speed information
317  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALSPEED, ret->id.c_str(), ok);
318  if (!SUMOVehicleParameter::parseArrivalSpeed(helper, element, ret->id, ret->arrivalSpeed, ret->arrivalSpeedProcedure, error)) {
319  throw ProcessError(error);
320  }
321  }
322 
323  // parse color
324  if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
326  ret->color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, ret->id.c_str(), ok);
327  } else {
329  }
330  // parse person number
333  ret->personNumber = attrs.get<int>(SUMO_ATTR_PERSON_NUMBER, ret->id.c_str(), ok);
334  }
335  // parse container number
338  ret->containerNumber = attrs.get<int>(SUMO_ATTR_CONTAINER_NUMBER, ret->id.c_str(), ok);
339  }
340  /*/ parse via
341  if (attrs.hasAttribute(SUMO_ATTR_VIA)) {
342  ret->setParameter |= VEHPARS_VIA_SET;
343  SUMOSAXAttributes::parseStringVector(attrs.get<std::string>(SUMO_ATTR_VIA, ret->id.c_str(), ok), ret->via);
344  }
345  */
346 }
347 
348 
350 SUMOVehicleParserHelper::beginVTypeParsing(const SUMOSAXAttributes& attrs, const std::string& file, const SumoXMLTag defaultCFModel) {
351  bool ok = true;
352  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
354  if (attrs.hasAttribute(SUMO_ATTR_VCLASS)) {
355  vClass = parseVehicleClass(attrs, id);
356  }
357  SUMOVTypeParameter* vtype = new SUMOVTypeParameter(id, vClass);
358  if (attrs.hasAttribute(SUMO_ATTR_VCLASS)) {
360  }
361  if (attrs.hasAttribute(SUMO_ATTR_LENGTH)) {
362  vtype->length = attrs.get<double>(SUMO_ATTR_LENGTH, vtype->id.c_str(), ok);
364  }
365  if (attrs.hasAttribute(SUMO_ATTR_MINGAP)) {
366  vtype->minGap = attrs.get<double>(SUMO_ATTR_MINGAP, vtype->id.c_str(), ok);
368  }
369  if (attrs.hasAttribute(SUMO_ATTR_MAXSPEED)) {
370  vtype->maxSpeed = attrs.get<double>(SUMO_ATTR_MAXSPEED, vtype->id.c_str(), ok);
372  }
373  if (attrs.hasAttribute(SUMO_ATTR_SPEEDFACTOR)) {
374  vtype->speedFactor.parse(attrs.get<std::string>(SUMO_ATTR_SPEEDFACTOR, vtype->id.c_str(), ok));
376  }
377  if (attrs.hasAttribute(SUMO_ATTR_SPEEDDEV)) {
378  vtype->speedFactor.getParameter()[1] = attrs.get<double>(SUMO_ATTR_SPEEDDEV, vtype->id.c_str(), ok);
380  }
382  vtype->emissionClass = PollutantsInterface::getClassByName(attrs.getOpt<std::string>(SUMO_ATTR_EMISSIONCLASS, id.c_str(), ok, ""));
384  }
385  if (attrs.hasAttribute(SUMO_ATTR_IMPATIENCE)) {
386  if (attrs.get<std::string>(SUMO_ATTR_IMPATIENCE, vtype->id.c_str(), ok) == "off") {
388  } else {
389  vtype->impatience = attrs.get<double>(SUMO_ATTR_IMPATIENCE, vtype->id.c_str(), ok);
390  }
392  }
393  if (attrs.hasAttribute(SUMO_ATTR_WIDTH)) {
394  vtype->width = attrs.get<double>(SUMO_ATTR_WIDTH, vtype->id.c_str(), ok);
396  }
397  if (attrs.hasAttribute(SUMO_ATTR_HEIGHT)) {
398  vtype->height = attrs.get<double>(SUMO_ATTR_HEIGHT, vtype->id.c_str(), ok);
400  }
401  if (attrs.hasAttribute(SUMO_ATTR_GUISHAPE)) {
402  vtype->shape = parseGuiShape(attrs, vtype->id);
404  }
405  if (attrs.hasAttribute(SUMO_ATTR_OSGFILE)) {
406  vtype->osgFile = attrs.get<std::string>(SUMO_ATTR_OSGFILE, vtype->id.c_str(), ok);
408  }
409  if (attrs.hasAttribute(SUMO_ATTR_IMGFILE)) {
410  vtype->imgFile = attrs.get<std::string>(SUMO_ATTR_IMGFILE, vtype->id.c_str(), ok);
411  if (vtype->imgFile != "" && !FileHelpers::isAbsolute(vtype->imgFile)) {
413  }
415  }
416  if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
417  vtype->color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, vtype->id.c_str(), ok);
419  } else {
420  vtype->color = RGBColor::YELLOW;
421  }
422  if (attrs.hasAttribute(SUMO_ATTR_PROB)) {
423  vtype->defaultProbability = attrs.get<double>(SUMO_ATTR_PROB, vtype->id.c_str(), ok);
425  }
428  std::string lcmS = attrs.get<std::string>(SUMO_ATTR_LANE_CHANGE_MODEL, vtype->id.c_str(), ok);
429  if (lcmS == "JE2013") {
430  WRITE_WARNING("Lane change model 'JE2013' is deprecated. Using default model instead.");
431  lcmS = "default";
432  }
433  if (SUMOXMLDefinitions::LaneChangeModels.hasString(lcmS)) {
435  } else {
436  WRITE_ERROR("Unknown lane change model '" + lcmS + "' when parsing vType '" + vtype->id + "'");
437  throw ProcessError();
438  }
439  }
441  const std::string cfmS = attrs.get<std::string>(SUMO_ATTR_CAR_FOLLOW_MODEL, vtype->id.c_str(), ok);
442  if (SUMOXMLDefinitions::CarFollowModels.hasString(cfmS)) {
445  } else {
446  WRITE_ERROR("Unknown car following model '" + cfmS + "' when parsing vType '" + vtype->id + "'");
447  throw ProcessError();
448  }
449  }
451  vtype->personCapacity = attrs.get<int>(SUMO_ATTR_PERSON_CAPACITY, vtype->id.c_str(), ok);
453  }
455  vtype->containerCapacity = attrs.get<int>(SUMO_ATTR_CONTAINER_CAPACITY, vtype->id.c_str(), ok);
457  }
459  vtype->boardingDuration = attrs.getSUMOTimeReporting(SUMO_ATTR_BOARDING_DURATION, vtype->id.c_str(), ok);
461  }
463  vtype->loadingDuration = attrs.getSUMOTimeReporting(SUMO_ATTR_LOADING_DURATION, vtype->id.c_str(), ok);
465  }
467  vtype->maxSpeedLat = attrs.get<double>(SUMO_ATTR_MAXSPEED_LAT, vtype->id.c_str(), ok);
469  }
470  if (attrs.hasAttribute(SUMO_ATTR_MINGAP_LAT)) {
471  vtype->minGapLat = attrs.get<double>(SUMO_ATTR_MINGAP_LAT, vtype->id.c_str(), ok);
473  }
475  const std::string alignS = attrs.get<std::string>(SUMO_ATTR_LATALIGNMENT, vtype->id.c_str(), ok);
476  if (SUMOXMLDefinitions::LateralAlignments.hasString(alignS)) {
479  } else {
480  WRITE_ERROR("Unknown lateral alignment '" + alignS + "' when parsing vType '" + vtype->id + "'");
481  throw ProcessError();
482  }
483  }
484  parseVTypeEmbedded(*vtype, vtype->wasSet(VTYPEPARS_CAR_FOLLOW_MODEL) ? vtype->cfModel : defaultCFModel, attrs, true);
485  parseLCParams(*vtype, vtype->lcModel, attrs);
486  parseJMParams(*vtype, attrs);
487  if (!ok) {
488  delete vtype;
489  throw ProcessError();
490  }
491  return vtype;
492 }
493 
494 
495 void
497  const SumoXMLTag element, const SUMOSAXAttributes& attrs,
498  const bool fromVType) {
499  const CFAttrMap& allowedAttrs = getAllowedCFModelAttrs();
500  CFAttrMap::const_iterator cf_it = allowedAttrs.find(element);
501  if (cf_it == allowedAttrs.end()) {
502  if (SUMOXMLDefinitions::Tags.has((int)element)) {
503  WRITE_ERROR("Unknown car following model " + toString(element) + " when parsing vType '" + into.id + "'");
504  } else {
505  WRITE_ERROR("Unknown car following model when parsing vType '" + into.id + "'");
506  }
507  throw ProcessError();
508  return;
509  }
510  if (!fromVType) {
511  into.cfModel = cf_it->first;
513  }
514  bool ok = true;
515  for (std::set<SumoXMLAttr>::const_iterator it = cf_it->second.begin(); it != cf_it->second.end(); ++it) {
516  if (attrs.hasAttribute(*it)) {
517  into.cfParameter[*it] = attrs.get<std::string>(*it, into.id.c_str(), ok);
518  if (*it == SUMO_ATTR_TAU && string2time(into.cfParameter[*it]) < DELTA_T && element != SUMO_TAG_NOTHING) {
519  WRITE_WARNING("Value of tau=" + toString(into.cfParameter[*it])
520  + " in car following model '" + toString(into.cfModel) + "' lower than simulation step size may cause collisions");
521  }
522  }
523  }
524  if (!ok) {
525  throw ProcessError();
526  }
527 }
528 
529 
532  // init on first use
533  if (allowedCFModelAttrs.size() == 0) {
534  std::set<SumoXMLAttr> kraussParams;
535  kraussParams.insert(SUMO_ATTR_ACCEL);
536  kraussParams.insert(SUMO_ATTR_DECEL);
537  kraussParams.insert(SUMO_ATTR_APPARENTDECEL);
538  kraussParams.insert(SUMO_ATTR_EMERGENCYDECEL);
539  kraussParams.insert(SUMO_ATTR_SIGMA);
540  kraussParams.insert(SUMO_ATTR_TAU);
541  allowedCFModelAttrs[SUMO_TAG_CF_KRAUSS] = kraussParams;
544  std::set<SumoXMLAttr> allParams(kraussParams);
545 
546  std::set<SumoXMLAttr> kraussXParams(kraussParams);
547  kraussXParams.insert(SUMO_ATTR_TMP1);
548  kraussXParams.insert(SUMO_ATTR_TMP2);
549  kraussXParams.insert(SUMO_ATTR_TMP3);
550  kraussXParams.insert(SUMO_ATTR_TMP4);
551  kraussXParams.insert(SUMO_ATTR_TMP5);
552  allowedCFModelAttrs[SUMO_TAG_CF_KRAUSSX] = kraussXParams;
553  allParams.insert(kraussXParams.begin(), kraussXParams.end());
554 
555  std::set<SumoXMLAttr> smartSKParams;
556  smartSKParams.insert(SUMO_ATTR_ACCEL);
557  smartSKParams.insert(SUMO_ATTR_DECEL);
558  smartSKParams.insert(SUMO_ATTR_EMERGENCYDECEL);
559  smartSKParams.insert(SUMO_ATTR_SIGMA);
560  smartSKParams.insert(SUMO_ATTR_TAU);
561  smartSKParams.insert(SUMO_ATTR_TMP1);
562  smartSKParams.insert(SUMO_ATTR_TMP2);
563  smartSKParams.insert(SUMO_ATTR_TMP3);
564  smartSKParams.insert(SUMO_ATTR_TMP4);
565  smartSKParams.insert(SUMO_ATTR_TMP5);
566  allowedCFModelAttrs[SUMO_TAG_CF_SMART_SK] = smartSKParams;
567  allParams.insert(smartSKParams.begin(), smartSKParams.end());
568 
569  std::set<SumoXMLAttr> daniel1Params;
570  daniel1Params.insert(SUMO_ATTR_ACCEL);
571  daniel1Params.insert(SUMO_ATTR_DECEL);
572  daniel1Params.insert(SUMO_ATTR_EMERGENCYDECEL);
573  daniel1Params.insert(SUMO_ATTR_SIGMA);
574  daniel1Params.insert(SUMO_ATTR_TAU);
575  daniel1Params.insert(SUMO_ATTR_TMP1);
576  daniel1Params.insert(SUMO_ATTR_TMP2);
577  daniel1Params.insert(SUMO_ATTR_TMP3);
578  daniel1Params.insert(SUMO_ATTR_TMP4);
579  daniel1Params.insert(SUMO_ATTR_TMP5);
580  allowedCFModelAttrs[SUMO_TAG_CF_DANIEL1] = daniel1Params;
581  allParams.insert(daniel1Params.begin(), daniel1Params.end());
582 
583  std::set<SumoXMLAttr> pwagParams;
584  pwagParams.insert(SUMO_ATTR_ACCEL);
585  pwagParams.insert(SUMO_ATTR_DECEL);
586  pwagParams.insert(SUMO_ATTR_EMERGENCYDECEL);
587  pwagParams.insert(SUMO_ATTR_SIGMA);
588  pwagParams.insert(SUMO_ATTR_TAU);
589  pwagParams.insert(SUMO_ATTR_CF_PWAGNER2009_TAULAST);
590  pwagParams.insert(SUMO_ATTR_CF_PWAGNER2009_APPROB);
592  allParams.insert(pwagParams.begin(), pwagParams.end());
593 
594  std::set<SumoXMLAttr> idmParams;
595  idmParams.insert(SUMO_ATTR_ACCEL);
596  idmParams.insert(SUMO_ATTR_DECEL);
597  idmParams.insert(SUMO_ATTR_EMERGENCYDECEL);
598  idmParams.insert(SUMO_ATTR_TAU);
599  idmParams.insert(SUMO_ATTR_CF_IDM_DELTA);
600  idmParams.insert(SUMO_ATTR_CF_IDM_STEPPING);
602  allParams.insert(idmParams.begin(), idmParams.end());
603 
604  std::set<SumoXMLAttr> idmmParams;
605  idmmParams.insert(SUMO_ATTR_ACCEL);
606  idmmParams.insert(SUMO_ATTR_DECEL);
607  idmmParams.insert(SUMO_ATTR_EMERGENCYDECEL);
608  idmmParams.insert(SUMO_ATTR_TAU);
609  idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_FACTOR);
610  idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_TIME);
611  idmmParams.insert(SUMO_ATTR_CF_IDM_STEPPING);
613  allParams.insert(idmmParams.begin(), idmmParams.end());
614 
615  std::set<SumoXMLAttr> bkernerParams;
616  bkernerParams.insert(SUMO_ATTR_ACCEL);
617  bkernerParams.insert(SUMO_ATTR_DECEL);
618  bkernerParams.insert(SUMO_ATTR_EMERGENCYDECEL);
619  bkernerParams.insert(SUMO_ATTR_TAU);
620  bkernerParams.insert(SUMO_ATTR_K);
621  bkernerParams.insert(SUMO_ATTR_CF_KERNER_PHI);
622  allowedCFModelAttrs[SUMO_TAG_CF_BKERNER] = bkernerParams;
623  allParams.insert(bkernerParams.begin(), bkernerParams.end());
624 
625  std::set<SumoXMLAttr> wiedemannParams;
626  wiedemannParams.insert(SUMO_ATTR_ACCEL);
627  wiedemannParams.insert(SUMO_ATTR_DECEL);
628  wiedemannParams.insert(SUMO_ATTR_EMERGENCYDECEL);
629  wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_SECURITY);
630  wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_ESTIMATION);
631  allowedCFModelAttrs[SUMO_TAG_CF_WIEDEMANN] = wiedemannParams;
632  allParams.insert(wiedemannParams.begin(), wiedemannParams.end());
633 
634  std::set<SumoXMLAttr> railParams;
635  railParams.insert(SUMO_ATTR_TRAIN_TYPE);
637  allParams.insert(railParams.begin(), railParams.end());
638 
640  }
641  return allowedCFModelAttrs;
642 }
643 
644 
645 void
647  if (allowedLCModelAttrs.size() == 0) {
648  // init static map
649  std::set<SumoXMLAttr> lc2013Params;
650  lc2013Params.insert(SUMO_ATTR_LCA_STRATEGIC_PARAM);
651  lc2013Params.insert(SUMO_ATTR_LCA_COOPERATIVE_PARAM);
652  lc2013Params.insert(SUMO_ATTR_LCA_SPEEDGAIN_PARAM);
653  lc2013Params.insert(SUMO_ATTR_LCA_KEEPRIGHT_PARAM);
654  lc2013Params.insert(SUMO_ATTR_LCA_EXPERIMENTAL1);
655  allowedLCModelAttrs[LCM_LC2013] = lc2013Params;
656 
657  std::set<SumoXMLAttr> sl2015Params = lc2013Params;
658  sl2015Params.insert(SUMO_ATTR_LCA_PUSHY);
659  sl2015Params.insert(SUMO_ATTR_LCA_SUBLANE_PARAM);
660  sl2015Params.insert(SUMO_ATTR_LCA_ASSERTIVE);
661  sl2015Params.insert(SUMO_ATTR_LCA_IMPATIENCE);
662  sl2015Params.insert(SUMO_ATTR_LCA_TIME_TO_IMPATIENCE);
663  sl2015Params.insert(SUMO_ATTR_LCA_ACCEL_LAT);
664  allowedLCModelAttrs[LCM_SL2015] = sl2015Params;
665 
666  std::set<SumoXMLAttr> noParams;
667  allowedLCModelAttrs[LCM_DK2008] = noParams;
668 
669  // default model may be either LC2013 or SL2013
670  // we allow both sets (sl2015 is a superset of lc2013Params)
671  allowedLCModelAttrs[LCM_DEFAULT] = sl2015Params;
672  }
673  bool ok = true;
674  std::set<SumoXMLAttr> allowed = allowedLCModelAttrs[model];
675  for (std::set<SumoXMLAttr>::const_iterator it = allowed.begin(); it != allowed.end(); it++) {
676  if (attrs.hasAttribute(*it)) {
677  into.lcParameter[*it] = attrs.get<std::string>(*it, into.id.c_str(), ok);
678  }
679  }
680  if (!ok) {
681  throw ProcessError();
682  }
683 }
684 
685 
686 void
688  if (allowedJMAttrs.size() == 0) {
689  // init static set (there is only one model)
696  }
697  bool ok = true;
698  for (std::set<SumoXMLAttr>::const_iterator it = allowedJMAttrs.begin(); it != allowedJMAttrs.end(); it++) {
699  if (attrs.hasAttribute(*it)) {
700  into.jmParameter[*it] = attrs.get<std::string>(*it, into.id.c_str(), ok);
701  }
702  }
703  if (!ok) {
704  throw ProcessError();
705  }
706 }
707 
708 
711  const std::string& id) {
713  try {
714  bool ok = true;
715  std::string vclassS = attrs.getOpt<std::string>(SUMO_ATTR_VCLASS, id.c_str(), ok, "");
716  if (vclassS == "") {
717  return vclass;
718  }
719  const SUMOVehicleClass result = getVehicleClassID(vclassS);
720  const std::string& realName = SumoVehicleClassStrings.getString(result);
721  if (realName != vclassS) {
722  WRITE_WARNING("The vehicle class '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is deprecated, use '" + realName + "' instead.");
723  }
724  return result;
725  } catch (...) {
726  WRITE_ERROR("The class for " + attrs.getObjectType() + " '" + id + "' is not known.");
727  }
728  return vclass;
729 }
730 
731 
733 SUMOVehicleParserHelper::parseGuiShape(const SUMOSAXAttributes& attrs, const std::string& id) {
734  bool ok = true;
735  std::string vclassS = attrs.getOpt<std::string>(SUMO_ATTR_GUISHAPE, id.c_str(), ok, "");
736  if (SumoVehicleShapeStrings.hasString(vclassS)) {
737  const SUMOVehicleShape result = SumoVehicleShapeStrings.get(vclassS);
738  const std::string& realName = SumoVehicleShapeStrings.getString(result);
739  if (realName != vclassS) {
740  WRITE_WARNING("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is deprecated, use '" + realName + "' instead.");
741  }
742  return result;
743  } else {
744  WRITE_ERROR("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is not known.");
745  return SVS_UNKNOWN;
746  }
747 }
748 
749 
750 double
751 SUMOVehicleParserHelper::parseWalkPos(SumoXMLAttr attr, const std::string& id, double maxPos, const std::string& val, std::mt19937* rng) {
752  double result;
753  std::string error;
755  // only supports 'random' and 'max'
756  if (!SUMOVehicleParameter::parseArrivalPos(val, toString(SUMO_TAG_WALK), id, result, proc, error)) {
757  throw ProcessError(error);
758  }
759  if (proc == ARRIVAL_POS_RANDOM) {
760  result = RandHelper::rand(maxPos, rng);
761  } else if (proc == ARRIVAL_POS_MAX) {
762  result = maxPos;
763  }
764  return SUMOVehicleParameter::interpretEdgePos(result, maxPos, attr, id);
765 }
766 
767 
768 
769 /****************************************************************************/
770 
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
const int VTYPEPARS_MAXSPEED_SET
const int VEHPARS_TO_TAZ_SET
const int VTYPEPARS_MINGAP_SET
static StringBijection< SumoXMLTag > CarFollowModels
car following models
SumoXMLTag
Numbers representing SUMO-XML - element names.
SumoXMLTag cfModel
The enum-representation of the car-following model to use.
RGBColor color
The vehicle&#39;s color, TraCI may change this.
const int VTYPEPARS_LATALIGNMENT_SET
static SUMOVTypeParameter * beginVTypeParsing(const SUMOSAXAttributes &attrs, const std::string &file, const SumoXMLTag defaultCFModel)
Starts to parse a vehicle type.
const int VEHPARS_FORCE_REROUTE
static std::string getConfigurationRelative(const std::string &configPath, const std::string &path)
Returns the second path as a relative path to the first file.
Definition: FileHelpers.cpp:82
static bool parseArrivalPosLat(const std::string &val, const std::string &element, const std::string &id, double &pos, ArrivalPosLatDefinition &apd, std::string &error)
Validates a given arrivalPosLat value.
double impatience
The vehicle&#39;s impatience (willingness to obstruct others)
std::string vtypeid
The vehicle&#39;s type id.
static std::set< SumoXMLAttr > allowedJMAttrs
static SUMOVehicleShape parseGuiShape(const SUMOSAXAttributes &attrs, const std::string &id)
Parses the vehicle class.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
StringBijection< SUMOVehicleShape > SumoVehicleShapeStrings(sumoVehicleShapeStringInitializer, SVS_UNKNOWN, false)
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
SUMOVehicleShape shape
This class&#39; shape.
Structure representing possible vehicle parameter.
const int VTYPEPARS_MINGAP_LAT_SET
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
double defaultProbability
The probability when being added to a distribution without an explicit probability.
std::vector< double > & getParameter()
Returns the parameters of this distribution.
static SUMOVehicleParameter * parseVehicleAttributes(const SUMOSAXAttributes &attrs, const bool optionalID=false, const bool skipDepart=false, const bool isPerson=false)
Parses a vehicle&#39;s attributes.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
Definition: RandHelper.h:65
static void parseVTypeEmbedded(SUMOVTypeParameter &into, const SumoXMLTag element, const SUMOSAXAttributes &attrs, const bool fromVType=false)
Parses an element embedded in vtype definition.
int containerCapacity
The container capacity of the vehicle.
const int VTYPEPARS_BOARDING_DURATION
ArrivalPosLatDefinition arrivalPosLatProcedure
Information how the vehicle shall choose the lateral arrival position.
weights: time range begin
double arrivalPosLat
(optional) The lateral position the vehicle shall arrive on
SUMOTime DELTA_T
Definition: SUMOTime.cpp:40
const int VEHPARS_ARRIVALLANE_SET
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle&#39;s end speed shall be chosen.
const int VTYPEPARS_CAR_FOLLOW_MODEL
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
const int VTYPEPARS_OSGFILE_SET
const int VTYPEPARS_MAXSPEED_LAT_SET
const int VTYPEPARS_PROBABILITY_SET
static double parseWalkPos(SumoXMLAttr attr, const std::string &id, double maxPos, const std::string &val, std::mt19937 *rng=0)
parse departPos or arrivalPos for a walk
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
void parse(const std::string &description)
Overwrite by parsable distribution description.
static SUMOVehicleClass parseVehicleClass(const SUMOSAXAttributes &attrs, const std::string &id)
Parses the vehicle class.
static void parseLCParams(SUMOVTypeParameter &into, LaneChangeModel model, const SUMOSAXAttributes &attrs)
Parses lane change model attributes.
const std::string & getObjectType() const
return the objecttype to which these attributes belong
double height
This class&#39; height.
std::string toTaz
The vehicle&#39;s destination zone (district)
const int VTYPEPARS_LANE_CHANGE_MODEL_SET
const int VEHPARS_ARRIVALSPEED_SET
static double interpretEdgePos(double pos, double maximumValue, SumoXMLAttr attr, const std::string &id)
Interprets negative edge positions and fits them onto a given edge.
double departSpeed
(optional) The initial speed of the vehicle
static const CFAttrMap & getAllowedCFModelAttrs()
LaneChangeModel
#define max(a, b)
Definition: polyfonts.c:65
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle&#39;s initial speed shall be chosen.
double maxSpeed
The vehicle type&#39;s maximum speed [m/s].
double width
This class&#39; width.
SUMOTime boardingDuration
The time a person needs to board the vehicle.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
std::string routeid
The vehicle&#39;s route id.
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
Encapsulated SAX-Attributes.
static SUMOVehicleParameter * parseFlowAttributes(const SUMOSAXAttributes &attrs, const SUMOTime beginDefault, const SUMOTime endDefault)
Parses a flow&#39;s attributes.
const int VEHPARS_DEPARTSPEED_SET
static bool isAbsolute(const std::string &path)
Returns the information whether the given path is absolute.
Definition: FileHelpers.cpp:97
std::string osgFile
3D model file for this class
#define SUMOTime_MAX
Definition: TraCIDefs.h:53
static void parseCommonAttributes(const SUMOSAXAttributes &attrs, SUMOVehicleParameter *ret, std::string element)
Parses attributes common to vehicles and flows.
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:192
not defined
std::map< SumoXMLTag, std::set< SumoXMLAttr > > CFAttrMap
virtual std::string getName(int attr) const =0
Converts the given attribute id into a man readable string.
int arrivalLane
(optional) The lane the vehicle shall arrive on (not used yet)
std::string imgFile
Image file for this class.
const int VEHPARS_DEPARTPOSLAT_SET
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:47
const int VEHPARS_ROUTE_SET
std::string fromTaz
The vehicle&#39;s origin zone (district)
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.
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
const int VTYPEPARS_LOADING_DURATION
SUMOTime getSUMOTimeReporting(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
const int VTYPEPARS_CONTAINER_CAPACITY
const int VEHPARS_COLOR_SET
int personNumber
The static number of persons in the vehicle when it departs (not including boarding persons) ...
vehicle is a passenger car (a "normal" car)
const int VEHPARS_FROM_TAZ_SET
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)
const int VTYPEPARS_SPEEDFACTOR_SET
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
double arrivalPos
(optional) The position the vehicle shall arrive on
double maxSpeedLat
The vehicle type&#39;s maximum lateral speed [m/s].
const int VEHPARS_ARRIVALPOSLAT_SET
double departPosLat
(optional) The lateral position the vehicle shall depart from
const int VEHPARS_LINE_SET
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
const int VEHPARS_ARRIVALPOS_SET
int personCapacity
The person capacity of the vehicle.
int setParameter
Information for the router which parameter were set.
static StringBijection< LateralAlignment > LateralAlignments
lateral alignments
double departPos
(optional) The position the vehicle shall depart from
double minGapLat
The vehicle type&#39;s minimum lateral gap [m].
static const RGBColor YELLOW
Definition: RGBColor.h:182
Structure representing possible vehicle parameter.
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
const int VEHPARS_PERIODFREQ_SET
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
bool wasSet(int what) const
Returns whether the given parameter was set.
const std::string DEFAULT_PEDTYPE_ID
int setParameter
Information for the router which parameter were set, TraCI may modify this (whe changing color) ...
static bool parseDepartPos(const std::string &val, const std::string &element, const std::string &id, double &pos, DepartPosDefinition &dpd, std::string &error)
Validates a given departPos value.
static void parseJMParams(SUMOVTypeParameter &into, const SUMOSAXAttributes &attrs)
Parses junction model attributes.
weights: time range end
SubParams jmParameter
Junction-model parameter.
const int VTYPEPARS_IMGFILE_SET
static bool parseDepartPosLat(const std::string &val, const std::string &element, const std::string &id, double &pos, DepartPosLatDefinition &dpd, std::string &error)
Validates a given departPosLat value.
static bool parseArrivalSpeed(const std::string &val, const std::string &element, const std::string &id, double &speed, ArrivalSpeedDefinition &asd, std::string &error)
Validates a given arrivalSpeed value.
SubParams cfParameter
Car-following parameter.
SUMOTime loadingDuration
The time a container needs to get loaded on the vehicle.
RGBColor color
The color.
const int VEHPARS_DEPARTLANE_SET
static bool parseArrivalPos(const std::string &val, const std::string &element, const std::string &id, double &pos, ArrivalPosDefinition &apd, std::string &error)
Validates a given arrivalPos value.
int containerNumber
The static number of containers in the vehicle when it departs.
std::string id
The vehicle type&#39;s id.
static bool parseDepartSpeed(const std::string &val, const std::string &element, const std::string &id, double &speed, DepartSpeedDefinition &dsd, std::string &error)
Validates a given departSpeed value.
const int VTYPEPARS_PERSON_CAPACITY
LateralAlignment latAlignment
The vehicles desired lateral alignment.
T get(const std::string &str) const
const int VEHPARS_VTYPE_SET
double minGap
This class&#39; free space in front of the vehicle itself.
const int VTYPEPARS_HEIGHT_SET
ArrivalPosDefinition
Possible ways to choose the arrival position.
long long int SUMOTime
Definition: TraCIDefs.h:52
double arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
const int VTYPEPARS_WIDTH_SET
static StringBijection< int > Tags
The names of SUMO-XML elements for use in netbuild.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
const int VEHPARS_DEPARTPOS_SET
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
const int VEHPARS_PERSON_NUMBER_SET
LaneChangeModel lcModel
The lane-change model to use.
const int VTYPEPARS_LENGTH_SET
const int VTYPEPARS_VEHICLECLASS_SET
const int VEHPARS_CONTAINER_NUMBER_SET
A color information.
const int VTYPEPARS_EMISSIONCLASS_SET
The maximum arrival position is used.
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.
SubParams lcParameter
Lane-changing parameter.
static StringBijection< LaneChangeModel > LaneChangeModels
lane change models
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.
SUMOEmissionClass emissionClass
The emission class of this vehicle.
vehicles ignoring classes
std::map< LaneChangeModel, std::set< SumoXMLAttr > > LCAttrMap
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
std::string id
The vehicle&#39;s id.
const int VTYPEPARS_IMPATIENCE_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.
DepartPosLatDefinition departPosLatProcedure
Information how the vehicle shall choose the lateral departure position.