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 
35 #include <utils/common/ToString.h>
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // static members
51 // ===========================================================================
54 
55 
56 // ===========================================================================
57 // method definitions
58 // ===========================================================================
60 SUMOVehicleParserHelper::parseFlowAttributes(const SUMOSAXAttributes& attrs, const SUMOTime beginDefault, const SUMOTime endDefault) {
61  bool ok = true;
62  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
64  throw ProcessError("At most one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
65  "' and '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
66  "' has to be given in the definition of flow '" + id + "'.");
67  }
69  throw ProcessError("At most one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
70  "' and '" + attrs.getName(SUMO_ATTR_PROB) +
71  "' has to be given in the definition of flow '" + id + "'.");
72  }
74  throw ProcessError("At most one of '" + attrs.getName(SUMO_ATTR_PROB) +
75  "' and '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
76  "' has to be given in the definition of flow '" + id + "'.");
77  }
80  throw ProcessError("If '" + attrs.getName(SUMO_ATTR_PERIOD) +
81  "', '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
82  "' or '" + attrs.getName(SUMO_ATTR_PROB) +
83  "' are given at most one of '" + attrs.getName(SUMO_ATTR_END) +
84  "' and '" + attrs.getName(SUMO_ATTR_NUMBER) +
85  "' are allowed in flow '" + id + "'.");
86  }
87  } else {
88  if (!attrs.hasAttribute(SUMO_ATTR_NUMBER)) {
89  throw ProcessError("At least one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
90  "', '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
91  "', '" + attrs.getName(SUMO_ATTR_PROB) +
92  "', and '" + attrs.getName(SUMO_ATTR_NUMBER) +
93  "' is needed in flow '" + id + "'.");
94  }
95  }
97  ret->id = id;
98  try {
99  parseCommonAttributes(attrs, ret, "flow");
100  } catch (ProcessError&) {
101  delete ret;
102  throw;
103  }
104 
105  // parse repetition information
106  if (attrs.hasAttribute(SUMO_ATTR_PERIOD)) {
107  ret->setParameter |= VEHPARS_PERIODFREQ_SET;
108  ret->repetitionOffset = attrs.getSUMOTimeReporting(SUMO_ATTR_PERIOD, id.c_str(), ok);
109  }
110  if (attrs.hasAttribute(SUMO_ATTR_VEHSPERHOUR)) {
111  ret->setParameter |= VEHPARS_PERIODFREQ_SET;
112  const SUMOReal vph = attrs.get<SUMOReal>(SUMO_ATTR_VEHSPERHOUR, id.c_str(), ok);
113  if (ok && vph <= 0) {
114  delete ret;
115  throw ProcessError("Invalid repetition rate in the definition of flow '" + id + "'.");
116  }
117  if (ok && vph != 0) {
118  ret->repetitionOffset = TIME2STEPS(3600. / vph);
119  }
120  }
121  if (attrs.hasAttribute(SUMO_ATTR_PROB)) {
122  ret->repetitionProbability = attrs.get<SUMOReal>(SUMO_ATTR_PROB, id.c_str(), ok);
123  if (ok && (ret->repetitionProbability <= 0 || ret->repetitionProbability > 1)) {
124  delete ret;
125  throw ProcessError("Invalid repetition probability in the definition of flow '" + id + "'.");
126  }
127  }
128 
129  ret->depart = beginDefault;
130  if (attrs.hasAttribute(SUMO_ATTR_BEGIN)) {
131  ret->depart = attrs.getSUMOTimeReporting(SUMO_ATTR_BEGIN, id.c_str(), ok);
132  }
133  if (ok && ret->depart < 0) {
134  delete ret;
135  throw ProcessError("Negative begin time in the definition of flow '" + id + "'.");
136  }
137  ret->repetitionEnd = endDefault;
138  if (ret->repetitionEnd < 0) {
139  ret->repetitionEnd = SUMOTime_MAX;
140  }
141  if (attrs.hasAttribute(SUMO_ATTR_END)) {
142  ret->repetitionEnd = attrs.getSUMOTimeReporting(SUMO_ATTR_END, id.c_str(), ok);
143  }
144  if (ok && ret->repetitionEnd < ret->depart) {
145  delete ret;
146  throw ProcessError("Flow '" + id + "' ends before its begin time.");
147  }
148  if (attrs.hasAttribute(SUMO_ATTR_NUMBER)) {
149  ret->repetitionNumber = attrs.get<int>(SUMO_ATTR_NUMBER, id.c_str(), ok);
150  ret->setParameter |= VEHPARS_PERIODFREQ_SET;
151  if (ret->repetitionNumber == 0) {
152  WRITE_WARNING("Flow '" + id + "' has 0 vehicles; will skip it.");
153  } else {
154  if (ok && ret->repetitionNumber < 0) {
155  delete ret;
156  throw ProcessError("Negative repetition number in the definition of flow '" + id + "'.");
157  }
158  if (ok && ret->repetitionOffset < 0) {
159  ret->repetitionOffset = (ret->repetitionEnd - ret->depart) / ret->repetitionNumber;
160  }
161  }
162  ret->repetitionEnd = ret->depart + ret->repetitionNumber * ret->repetitionOffset;
163  } else {
164  // interpret repetitionNumber
165  if (ok && ret->repetitionProbability > 0) {
166  ret->repetitionNumber = std::numeric_limits<int>::max();
167  } else {
168  if (ok && ret->repetitionOffset <= 0) {
169  delete ret;
170  throw ProcessError("Invalid repetition rate in the definition of flow '" + id + "'.");
171  }
172  if (ret->repetitionEnd == SUMOTime_MAX) {
173  ret->repetitionNumber = std::numeric_limits<int>::max();
174  } else {
175  const SUMOReal repLength = (SUMOReal)(ret->repetitionEnd - ret->depart);
176  ret->repetitionNumber = (int)ceil(repLength / ret->repetitionOffset);
177  }
178  }
179  }
180  if (!ok) {
181  delete ret;
182  throw ProcessError();
183  }
184  return ret;
185 }
186 
187 
190  const bool optionalID, const bool skipDepart, const bool isPerson) {
191  bool ok = true;
192  std::string id, errorMsg;
193  if (optionalID) {
194  id = attrs.getOpt<std::string>(SUMO_ATTR_ID, 0, ok, "");
195  } else {
196  id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
197  }
199  ret->id = id;
200  if (isPerson) {
201  ret->vtypeid = DEFAULT_PEDTYPE_ID;
202  }
203  try {
204  parseCommonAttributes(attrs, ret, "vehicle");
205  if (!skipDepart) {
206  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPART, ret->id.c_str(), ok);
207  if (!ok || !SUMOVehicleParameter::parseDepart(helper, "vehicle", ret->id, ret->depart, ret->departProcedure, errorMsg)) {
208  throw ProcessError(errorMsg);
209  }
210  }
211  } catch (ProcessError&) {
212  delete ret;
213  throw;
214  }
215  return ret;
216 }
217 
218 
219 void
221  SUMOVehicleParameter* ret, std::string element) {
222  //ret->refid = attrs.getStringSecure(SUMO_ATTR_REFID, "");
223  bool ok = true;
224  // parse route information
225  if (attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
226  ret->setParameter |= VEHPARS_ROUTE_SET; // !!! needed?
227  ret->routeid = attrs.get<std::string>(SUMO_ATTR_ROUTE, ret->id.c_str(), ok);
228  }
229  // parse type information
230  if (attrs.hasAttribute(SUMO_ATTR_TYPE)) {
231  ret->setParameter |= VEHPARS_VTYPE_SET; // !!! needed?
232  ret->vtypeid = attrs.get<std::string>(SUMO_ATTR_TYPE, ret->id.c_str(), ok);
233  }
234  // parse line information
235  if (attrs.hasAttribute(SUMO_ATTR_LINE)) {
236  ret->setParameter |= VEHPARS_LINE_SET; // !!! needed?
237  ret->line = attrs.get<std::string>(SUMO_ATTR_LINE, ret->id.c_str(), ok);
238  }
239  // parse zone information
240  if (attrs.hasAttribute(SUMO_ATTR_FROM_TAZ)) {
242  ret->fromTaz = attrs.get<std::string>(SUMO_ATTR_FROM_TAZ, ret->id.c_str(), ok);
243  }
244  if (attrs.hasAttribute(SUMO_ATTR_TO_TAZ)) {
246  ret->toTaz = attrs.get<std::string>(SUMO_ATTR_TO_TAZ, ret->id.c_str(), ok);
247  }
248  // parse reroute information
249  if (attrs.getOpt<bool>(SUMO_ATTR_REROUTE, 0, ok, false)) {
251  }
252 
253  std::string error;
254  // parse depart lane information
255  if (attrs.hasAttribute(SUMO_ATTR_DEPARTLANE)) {
257  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTLANE, ret->id.c_str(), ok);
258  if (!SUMOVehicleParameter::parseDepartLane(helper, element, ret->id, ret->departLane, ret->departLaneProcedure, error)) {
259  throw ProcessError(error);
260  }
261  }
262  // parse depart position information
263  if (attrs.hasAttribute(SUMO_ATTR_DEPARTPOS)) {
265  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTPOS, ret->id.c_str(), ok);
266  if (!SUMOVehicleParameter::parseDepartPos(helper, element, ret->id, ret->departPos, ret->departPosProcedure, error)) {
267  throw ProcessError(error);
268  }
269  }
270  // parse lateral depart position information
273  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTPOS_LAT, ret->id.c_str(), ok);
274  if (!SUMOVehicleParameter::parseDepartPosLat(helper, element, ret->id, ret->departPosLat, ret->departPosLatProcedure, error)) {
275  throw ProcessError(error);
276  }
277  }
278  // parse depart speed information
279  if (attrs.hasAttribute(SUMO_ATTR_DEPARTSPEED)) {
281  std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTSPEED, ret->id.c_str(), ok);
282  if (!SUMOVehicleParameter::parseDepartSpeed(helper, element, ret->id, ret->departSpeed, ret->departSpeedProcedure, error)) {
283  throw ProcessError(error);
284  }
285  }
286 
287  // parse arrival lane information
288  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALLANE)) {
290  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALLANE, ret->id.c_str(), ok);
291  if (!SUMOVehicleParameter::parseArrivalLane(helper, element, ret->id, ret->arrivalLane, ret->arrivalLaneProcedure, error)) {
292  throw ProcessError(error);
293  }
294  }
295  // parse arrival position information
296  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
298  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, ret->id.c_str(), ok);
299  if (!SUMOVehicleParameter::parseArrivalPos(helper, element, ret->id, ret->arrivalPos, ret->arrivalPosProcedure, error)) {
300  throw ProcessError(error);
301  }
302  }
303  // parse lateral arrival position information
306  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS_LAT, ret->id.c_str(), ok);
307  if (!SUMOVehicleParameter::parseArrivalPosLat(helper, element, ret->id, ret->arrivalPosLat, ret->arrivalPosLatProcedure, error)) {
308  throw ProcessError(error);
309  }
310  }
311  // parse arrival speed information
314  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALSPEED, ret->id.c_str(), ok);
315  if (!SUMOVehicleParameter::parseArrivalSpeed(helper, element, ret->id, ret->arrivalSpeed, ret->arrivalSpeedProcedure, error)) {
316  throw ProcessError(error);
317  }
318  }
319 
320  // parse color
321  if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
323  ret->color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, ret->id.c_str(), ok);
324  } else {
326  }
327  // parse person number
330  ret->personNumber = attrs.get<int>(SUMO_ATTR_PERSON_NUMBER, ret->id.c_str(), ok);
331  }
332  // parse container number
335  ret->containerNumber = attrs.get<int>(SUMO_ATTR_CONTAINER_NUMBER, ret->id.c_str(), ok);
336  }
337 }
338 
339 
341 SUMOVehicleParserHelper::beginVTypeParsing(const SUMOSAXAttributes& attrs, const std::string& file) {
342  bool ok = true;
343  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
345  if (attrs.hasAttribute(SUMO_ATTR_VCLASS)) {
346  vClass = parseVehicleClass(attrs, id);
347  }
348  SUMOVTypeParameter* vtype = new SUMOVTypeParameter(id, vClass);
349  if (attrs.hasAttribute(SUMO_ATTR_VCLASS)) {
351  }
352  if (attrs.hasAttribute(SUMO_ATTR_LENGTH)) {
353  vtype->length = attrs.get<SUMOReal>(SUMO_ATTR_LENGTH, vtype->id.c_str(), ok);
355  }
356  if (attrs.hasAttribute(SUMO_ATTR_MINGAP)) {
357  vtype->minGap = attrs.get<SUMOReal>(SUMO_ATTR_MINGAP, vtype->id.c_str(), ok);
359  }
360  if (attrs.hasAttribute(SUMO_ATTR_MAXSPEED)) {
361  vtype->maxSpeed = attrs.get<SUMOReal>(SUMO_ATTR_MAXSPEED, vtype->id.c_str(), ok);
363  }
364  if (attrs.hasAttribute(SUMO_ATTR_SPEEDFACTOR)) {
365  vtype->speedFactor = attrs.get<SUMOReal>(SUMO_ATTR_SPEEDFACTOR, vtype->id.c_str(), ok);
367  }
368  if (attrs.hasAttribute(SUMO_ATTR_SPEEDDEV)) {
369  vtype->speedDev = attrs.get<SUMOReal>(SUMO_ATTR_SPEEDDEV, vtype->id.c_str(), ok);
371  }
373  vtype->emissionClass = parseEmissionClass(attrs, vtype->id);
375  }
376  if (attrs.hasAttribute(SUMO_ATTR_IMPATIENCE)) {
377  if (attrs.get<std::string>(SUMO_ATTR_IMPATIENCE, vtype->id.c_str(), ok) == "off") {
379  } else {
380  vtype->impatience = attrs.get<SUMOReal>(SUMO_ATTR_IMPATIENCE, vtype->id.c_str(), ok);
381  }
383  }
384  if (attrs.hasAttribute(SUMO_ATTR_WIDTH)) {
385  vtype->width = attrs.get<SUMOReal>(SUMO_ATTR_WIDTH, vtype->id.c_str(), ok);
387  }
388  if (attrs.hasAttribute(SUMO_ATTR_HEIGHT)) {
389  vtype->height = attrs.get<SUMOReal>(SUMO_ATTR_HEIGHT, vtype->id.c_str(), ok);
391  }
392  if (attrs.hasAttribute(SUMO_ATTR_GUISHAPE)) {
393  vtype->shape = parseGuiShape(attrs, vtype->id);
395  }
396  if (attrs.hasAttribute(SUMO_ATTR_OSGFILE)) {
397  vtype->osgFile = attrs.get<std::string>(SUMO_ATTR_OSGFILE, vtype->id.c_str(), ok);
399  }
400  if (attrs.hasAttribute(SUMO_ATTR_IMGFILE)) {
401  vtype->imgFile = attrs.get<std::string>(SUMO_ATTR_IMGFILE, vtype->id.c_str(), ok);
402  if (vtype->imgFile != "" && !FileHelpers::isAbsolute(vtype->imgFile)) {
404  }
406  }
407  if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
408  vtype->color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, vtype->id.c_str(), ok);
410  } else {
411  vtype->color = RGBColor::YELLOW;
412  }
413  if (attrs.hasAttribute(SUMO_ATTR_PROB)) {
414  vtype->defaultProbability = attrs.get<SUMOReal>(SUMO_ATTR_PROB, vtype->id.c_str(), ok);
416  }
418  std::string lcmS = attrs.get<std::string>(SUMO_ATTR_LANE_CHANGE_MODEL, vtype->id.c_str(), ok);
419  if (lcmS == "JE2013") {
420  WRITE_WARNING("Lane change model 'JE2013' is deprecated. Using default model instead.");
421  lcmS = "default";
422  }
423  if (SUMOXMLDefinitions::LaneChangeModels.hasString(lcmS)) {
425  } else {
426  WRITE_ERROR("Unknown lane change model '" + lcmS + "' when parsing vtype '" + vtype->id + "'");
427  throw ProcessError();
428  }
429  }
431  const std::string cfmS = attrs.get<std::string>(SUMO_ATTR_CAR_FOLLOW_MODEL, vtype->id.c_str(), ok);
432  if (SUMOXMLDefinitions::CarFollowModels.hasString(cfmS)) {
435  } else {
436  WRITE_ERROR("Unknown car following model '" + cfmS + "' when parsing vtype '" + vtype->id + "'");
437  throw ProcessError();
438  }
439  }
441  vtype->personCapacity = attrs.get<int>(SUMO_ATTR_PERSON_CAPACITY, vtype->id.c_str(), ok);
443  }
445  vtype->containerCapacity = attrs.get<int>(SUMO_ATTR_CONTAINER_CAPACITY, vtype->id.c_str(), ok);
447  }
449  vtype->boardingDuration = attrs.getSUMOTimeReporting(SUMO_ATTR_BOARDING_DURATION, vtype->id.c_str(), ok);
451  }
453  vtype->loadingDuration = attrs.getSUMOTimeReporting(SUMO_ATTR_LOADING_DURATION, vtype->id.c_str(), ok);
455  }
457  vtype->maxSpeedLat = attrs.get<SUMOReal>(SUMO_ATTR_MAXSPEED_LAT, vtype->id.c_str(), ok);
459  }
460  if (attrs.hasAttribute(SUMO_ATTR_MINGAP_LAT)) {
461  vtype->minGapLat = attrs.get<SUMOReal>(SUMO_ATTR_MINGAP_LAT, vtype->id.c_str(), ok);
463  }
465  const std::string alignS = attrs.get<std::string>(SUMO_ATTR_LATALIGNMENT, vtype->id.c_str(), ok);
466  if (SUMOXMLDefinitions::LateralAlignments.hasString(alignS)) {
469  } else {
470  WRITE_ERROR("Unknown lateral alignment '" + alignS + "' when parsing vtype '" + vtype->id + "'");
471  throw ProcessError();
472  }
473  }
474  parseVTypeEmbedded(*vtype, vtype->cfModel, attrs, true);
475  parseLCParams(*vtype, vtype->lcModel, attrs);
476  if (!ok) {
477  delete vtype;
478  throw ProcessError();
479  }
480  return vtype;
481 }
482 
483 
484 void
486  int element, const SUMOSAXAttributes& attrs,
487  bool fromVType) {
488  const CFAttrMap& allowedAttrs = getAllowedCFModelAttrs();
489  CFAttrMap::const_iterator cf_it;
490  for (cf_it = allowedAttrs.begin(); cf_it != allowedAttrs.end(); cf_it++) {
491  if (cf_it->first == element) {
492  break;
493  }
494  }
495  if (cf_it == allowedAttrs.end()) {
496  if (SUMOXMLDefinitions::Tags.has(element)) {
497  WRITE_ERROR("Unknown cfmodel " + toString((SumoXMLTag)element) + " when parsing vtype '" + into.id + "'");
498  } else {
499  WRITE_ERROR("Unknown cfmodel when parsing vtype '" + into.id + "'");
500  }
501  throw ProcessError();
502  return;
503  }
504  if (!fromVType) {
505  into.cfModel = cf_it->first;
507  }
508  bool ok = true;
509  for (std::set<SumoXMLAttr>::const_iterator it = cf_it->second.begin(); it != cf_it->second.end(); it++) {
510  if (attrs.hasAttribute(*it)) {
511  into.cfParameter[*it] = attrs.get<SUMOReal>(*it, into.id.c_str(), ok);
512  if (*it == SUMO_ATTR_TAU && TIME2STEPS(into.cfParameter[*it]) < DELTA_T) {
513  WRITE_WARNING("Value of tau=" + toString(into.cfParameter[*it])
514  + " in car following model '" + toString(into.cfModel) + "' lower than simulation step size may cause collisions");
515  }
516  }
517  }
518  if (!ok) {
519  throw ProcessError();
520  }
521 }
522 
523 
526  // init on first use
527  if (allowedCFModelAttrs.size() == 0) {
528  std::set<SumoXMLAttr> krausParams;
529  krausParams.insert(SUMO_ATTR_ACCEL);
530  krausParams.insert(SUMO_ATTR_DECEL);
531  krausParams.insert(SUMO_ATTR_SIGMA);
532  krausParams.insert(SUMO_ATTR_TAU);
536 
537  std::set<SumoXMLAttr> smartSKParams;
538  smartSKParams.insert(SUMO_ATTR_ACCEL);
539  smartSKParams.insert(SUMO_ATTR_DECEL);
540  smartSKParams.insert(SUMO_ATTR_SIGMA);
541  smartSKParams.insert(SUMO_ATTR_TAU);
542  smartSKParams.insert(SUMO_ATTR_TMP1);
543  smartSKParams.insert(SUMO_ATTR_TMP2);
544  smartSKParams.insert(SUMO_ATTR_TMP3);
545  smartSKParams.insert(SUMO_ATTR_TMP4);
546  smartSKParams.insert(SUMO_ATTR_TMP5);
547  allowedCFModelAttrs[SUMO_TAG_CF_SMART_SK] = smartSKParams;
548 
549  std::set<SumoXMLAttr> daniel1Params;
550  daniel1Params.insert(SUMO_ATTR_ACCEL);
551  daniel1Params.insert(SUMO_ATTR_DECEL);
552  daniel1Params.insert(SUMO_ATTR_SIGMA);
553  daniel1Params.insert(SUMO_ATTR_TAU);
554  daniel1Params.insert(SUMO_ATTR_TMP1);
555  daniel1Params.insert(SUMO_ATTR_TMP2);
556  daniel1Params.insert(SUMO_ATTR_TMP3);
557  daniel1Params.insert(SUMO_ATTR_TMP4);
558  daniel1Params.insert(SUMO_ATTR_TMP5);
559  allowedCFModelAttrs[SUMO_TAG_CF_DANIEL1] = daniel1Params;
560 
561  std::set<SumoXMLAttr> pwagParams;
562  pwagParams.insert(SUMO_ATTR_ACCEL);
563  pwagParams.insert(SUMO_ATTR_DECEL);
564  pwagParams.insert(SUMO_ATTR_SIGMA);
565  pwagParams.insert(SUMO_ATTR_TAU);
566  pwagParams.insert(SUMO_ATTR_CF_PWAGNER2009_TAULAST);
567  pwagParams.insert(SUMO_ATTR_CF_PWAGNER2009_APPROB);
569 
570  std::set<SumoXMLAttr> idmParams;
571  idmParams.insert(SUMO_ATTR_ACCEL);
572  idmParams.insert(SUMO_ATTR_DECEL);
573  idmParams.insert(SUMO_ATTR_TAU);
574  idmParams.insert(SUMO_ATTR_CF_IDM_DELTA);
575  idmParams.insert(SUMO_ATTR_CF_IDM_STEPPING);
577 
578  std::set<SumoXMLAttr> idmmParams;
579  idmmParams.insert(SUMO_ATTR_ACCEL);
580  idmmParams.insert(SUMO_ATTR_DECEL);
581  idmmParams.insert(SUMO_ATTR_TAU);
582  idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_FACTOR);
583  idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_TIME);
584  idmmParams.insert(SUMO_ATTR_CF_IDM_STEPPING);
586 
587  std::set<SumoXMLAttr> bkernerParams;
588  bkernerParams.insert(SUMO_ATTR_ACCEL);
589  bkernerParams.insert(SUMO_ATTR_DECEL);
590  bkernerParams.insert(SUMO_ATTR_TAU);
591  bkernerParams.insert(SUMO_ATTR_K);
592  bkernerParams.insert(SUMO_ATTR_CF_KERNER_PHI);
593  allowedCFModelAttrs[SUMO_TAG_CF_BKERNER] = bkernerParams;
594 
595  std::set<SumoXMLAttr> wiedemannParams;
596  wiedemannParams.insert(SUMO_ATTR_ACCEL);
597  wiedemannParams.insert(SUMO_ATTR_DECEL);
598  wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_SECURITY);
599  wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_ESTIMATION);
600  allowedCFModelAttrs[SUMO_TAG_CF_WIEDEMANN] = wiedemannParams;
601  }
602  return allowedCFModelAttrs;
603 }
604 
605 
606 void
608  if (allowedLCModelAttrs.size() == 0) {
609  // init static map
610  std::set<SumoXMLAttr> lc2013Params;
611  lc2013Params.insert(SUMO_ATTR_LCA_STRATEGIC_PARAM);
612  lc2013Params.insert(SUMO_ATTR_LCA_COOPERATIVE_PARAM);
613  lc2013Params.insert(SUMO_ATTR_LCA_SPEEDGAIN_PARAM);
614  lc2013Params.insert(SUMO_ATTR_LCA_KEEPRIGHT_PARAM);
615  allowedLCModelAttrs[LCM_LC2013] = lc2013Params;
616 
617  std::set<SumoXMLAttr> sl2015Params = lc2013Params;
618  sl2015Params.insert(SUMO_ATTR_LCA_PUSHY);
619  sl2015Params.insert(SUMO_ATTR_LCA_SUBLANE_PARAM);
620  sl2015Params.insert(SUMO_ATTR_LCA_ASSERTIVE);
621  allowedLCModelAttrs[LCM_SL2015] = sl2015Params;
622 
623  std::set<SumoXMLAttr> noParams;
624  allowedLCModelAttrs[LCM_DK2008] = noParams;
625 
626  // default model may be either LC2013 or SL2013
627  // we allow both sets (sl2015 is a superset of lc2013Params)
628  allowedLCModelAttrs[LCM_DEFAULT] = sl2015Params;
629  }
630  bool ok = true;
631  std::set<SumoXMLAttr> allowed = allowedLCModelAttrs[model];
632  for (std::set<SumoXMLAttr>::const_iterator it = allowed.begin(); it != allowed.end(); it++) {
633  if (attrs.hasAttribute(*it)) {
634  into.lcParameter[*it] = attrs.get<SUMOReal>(*it, into.id.c_str(), ok);
635  }
636  }
637  if (!ok) {
638  throw ProcessError();
639  }
640 }
641 
642 
645  const std::string& id) {
647  try {
648  bool ok = true;
649  std::string vclassS = attrs.getOpt<std::string>(SUMO_ATTR_VCLASS, id.c_str(), ok, "");
650  if (vclassS == "") {
651  return vclass;
652  }
653  const SUMOVehicleClass result = getVehicleClassID(vclassS);
654  const std::string& realName = SumoVehicleClassStrings.getString(result);
655  if (realName != vclassS) {
656  WRITE_WARNING("The vehicle class '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is deprecated, use '" + realName + "' instead.");
657  }
658  return result;
659  } catch (...) {
660  WRITE_ERROR("The class for " + attrs.getObjectType() + " '" + id + "' is not known.");
661  }
662  return vclass;
663 }
664 
665 
668  try {
669  bool ok = true;
670  std::string eClassS = attrs.getOpt<std::string>(SUMO_ATTR_EMISSIONCLASS, id.c_str(), ok, "");
671  return PollutantsInterface::getClassByName(eClassS);
672  } catch (...) {
673  WRITE_ERROR("The emission class for " + attrs.getObjectType() + " '" + id + "' is not known.");
674  return 0;
675  }
676 }
677 
678 
680 SUMOVehicleParserHelper::parseGuiShape(const SUMOSAXAttributes& attrs, const std::string& id) {
681  bool ok = true;
682  std::string vclassS = attrs.getOpt<std::string>(SUMO_ATTR_GUISHAPE, id.c_str(), ok, "");
683  if (SumoVehicleShapeStrings.hasString(vclassS)) {
684  const SUMOVehicleShape result = SumoVehicleShapeStrings.get(vclassS);
685  const std::string& realName = SumoVehicleShapeStrings.getString(result);
686  if (realName != vclassS) {
687  WRITE_WARNING("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is deprecated, use '" + realName + "' instead.");
688  }
689  return result;
690  } else {
691  WRITE_ERROR("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is not known.");
692  return SVS_UNKNOWN;
693  }
694 }
695 
696 /****************************************************************************/
697 
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
long long int SUMOTime
Definition: SUMOTime.h:43
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:86
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.
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.
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)
static void parseVTypeEmbedded(SUMOVTypeParameter &into, int element, const SUMOSAXAttributes &attrs, bool fromVType=false)
Parses an element embedded in vtype definition.
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.
SUMOReal departSpeed
(optional) The initial speed of the vehicle
SUMOReal speedDev
The standard deviation for speed variations.
static SUMOVehicleParameter * parseVehicleAttributes(const SUMOSAXAttributes &attrs, const bool optionalID=false, const bool skipDepart=false, const bool isPerson=false)
Parses a vehicle&#39;s attributes.
SUMOReal arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
int containerCapacity
The container capacity of the vehicle.
SUMOReal length
The physical vehicle length.
const int VTYPEPARS_BOARDING_DURATION
ArrivalPosLatDefinition arrivalPosLatProcedure
Information how the vehicle shall choose the lateral arrival position.
weights: time range begin
SUMOReal arrivalPos
(optional) The position the vehicle shall arrive on
SUMOTime DELTA_T
Definition: SUMOTime.cpp:40
const int VEHPARS_ARRIVALLANE_SET
SUMOReal width
This class&#39; width.
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
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
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
std::string toTaz
The vehicle&#39;s destination zone (district)
const int VEHPARS_ARRIVALSPEED_SET
static const CFAttrMap & getAllowedCFModelAttrs()
LaneChangeModel
SUMOReal speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street...
#define max(a, b)
Definition: polyfonts.c:65
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle&#39;s initial speed shall be chosen.
SUMOTime boardingDuration
The time a person needs to board the vehicle.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
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.
std::string osgFile
3D model file for this class
int SUMOEmissionClass
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:200
not defined
SUMOReal maxSpeedLat
The vehicle type&#39;s maximum lateral speed [m/s].
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
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_SPEEDDEVIATION_SET
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) ...
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.
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...
const int VEHPARS_ARRIVALPOSLAT_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.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
SUMOReal maxSpeed
The vehicle type&#39;s maximum speed [m/s].
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
static const RGBColor YELLOW
Definition: RGBColor.h:192
Structure representing possible vehicle parameter.
SUMOReal impatience
The vehicle&#39;s impatience (willingness to obstruct others)
SUMOReal minGapLat
The vehicle type&#39;s minimum lateral gap [m].
#define SUMOTime_MAX
Definition: SUMOTime.h:44
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.
const std::string DEFAULT_PEDTYPE_ID
int setParameter
Information for the router which parameter were set, TraCI may modify this (whe changing color) ...
weights: time range end
SUMOReal defaultProbability
The probability when being added to a distribution without an explicit probability.
const int VTYPEPARS_IMGFILE_SET
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
int containerNumber
The static number of containers in the vehicle when it departs.
std::string id
The vehicle type&#39;s id.
SUMOReal departPos
(optional) The position the vehicle shall depart from
const int VTYPEPARS_PERSON_CAPACITY
static bool parseDepartPosLat(const std::string &val, const std::string &element, const std::string &id, SUMOReal &pos, DepartPosLatDefinition &dpd, std::string &error)
Validates a given departPosLat value.
LateralAlignment latAlignment
The vehicles desired lateral alignment.
static bool parseArrivalPosLat(const std::string &val, const std::string &element, const std::string &id, SUMOReal &pos, ArrivalPosLatDefinition &apd, std::string &error)
Validates a given arrivalPosLat value.
T get(const std::string &str) const
const int VEHPARS_VTYPE_SET
const int VTYPEPARS_HEIGHT_SET
static SUMOEmissionClass parseEmissionClass(const SUMOSAXAttributes &attrs, const std::string &id)
Parses the vehicle emission class.
#define SUMOReal
Definition: config.h:208
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.
SUMOReal arrivalPosLat
(optional) The lateral position the vehicle shall arrive on
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.
SUMOReal height
This class&#39; height.
const int VTYPEPARS_LENGTH_SET
const int VTYPEPARS_VEHICLECLASS_SET
static SUMOVTypeParameter * beginVTypeParsing(const SUMOSAXAttributes &attrs, const std::string &file)
Starts to parse a vehicle type.
const int VEHPARS_CONTAINER_NUMBER_SET
SUMOReal departPosLat
(optional) The lateral position the vehicle shall depart from
A color information.
const int VTYPEPARS_EMISSIONCLASS_SET
const int VTYPEPARS_COLOR_SET
const int VTYPEPARS_SHAPE_SET
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
SUMOReal minGap
This class&#39; free space in front of the vehicle itself.
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.
DepartPosLatDefinition departPosLatProcedure
Information how the vehicle shall choose the lateral departure position.