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-2016 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 // ===========================================================================
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 SUMOReal vph = attrs.get<SUMOReal>(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<SUMOReal>(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  }
143  if (ok && ret->repetitionEnd <= ret->depart) {
144  delete ret;
145  throw ProcessError("Flow '" + id + "' ends before or at its begin time.");
146  }
147  if (attrs.hasAttribute(SUMO_ATTR_NUMBER)) {
148  ret->repetitionNumber = attrs.get<int>(SUMO_ATTR_NUMBER, id.c_str(), ok);
149  ret->setParameter |= VEHPARS_PERIODFREQ_SET;
150  if (ret->repetitionNumber == 0) {
151  WRITE_WARNING("Flow '" + id + "' has 0 vehicles; will skip it.");
152  } else {
153  if (ok && ret->repetitionNumber < 0) {
154  delete ret;
155  throw ProcessError("Negative repetition number in the definition of flow '" + id + "'.");
156  }
157  if (ok && ret->repetitionOffset < 0) {
158  ret->repetitionOffset = (ret->repetitionEnd - ret->depart) / ret->repetitionNumber;
159  }
160  }
161  ret->repetitionEnd = ret->depart + ret->repetitionNumber * ret->repetitionOffset;
162  } else {
163  // interpret repetitionNumber
164  if (ok && ret->repetitionProbability > 0) {
165  ret->repetitionNumber = std::numeric_limits<int>::max();
166  } else {
167  if (ok && ret->repetitionOffset <= 0) {
168  delete ret;
169  throw ProcessError("Invalid repetition rate in the definition of flow '" + id + "'.");
170  }
171  if (ret->repetitionEnd == SUMOTime_MAX) {
172  ret->repetitionNumber = std::numeric_limits<int>::max();
173  } else {
174  ret->repetitionNumber = MAX2(1, (int)(((SUMOReal)(ret->repetitionEnd - ret->depart)) / ret->repetitionOffset + 0.5));
175  }
176  }
177  }
178  if (!ok) {
179  delete ret;
180  throw ProcessError();
181  }
182  return ret;
183 }
184 
185 
188  const bool optionalID, const bool skipDepart, const bool isPerson) {
189  bool ok = true;
190  std::string id, errorMsg;
191  if (optionalID) {
192  id = attrs.getOpt<std::string>(SUMO_ATTR_ID, 0, ok, "");
193  } else {
194  id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
195  }
197  ret->id = id;
198  if (isPerson) {
199  ret->vtypeid = DEFAULT_PEDTYPE_ID;
200  }
201  try {
202  parseCommonAttributes(attrs, ret, "vehicle");
203  if (!skipDepart) {
204  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPART, ret->id.c_str(), ok);
205  if (!ok || !SUMOVehicleParameter::parseDepart(helper, "vehicle", ret->id, ret->depart, ret->departProcedure, errorMsg)) {
206  throw ProcessError(errorMsg);
207  }
208  }
209  } catch (ProcessError&) {
210  delete ret;
211  throw;
212  }
213  return ret;
214 }
215 
216 
217 void
219  SUMOVehicleParameter* ret, std::string element) {
220  //ret->refid = attrs.getStringSecure(SUMO_ATTR_REFID, "");
221  bool ok = true;
222  // parse route information
223  if (attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
224  ret->setParameter |= VEHPARS_ROUTE_SET; // !!! needed?
225  ret->routeid = attrs.get<std::string>(SUMO_ATTR_ROUTE, ret->id.c_str(), ok);
226  }
227  // parse type information
228  if (attrs.hasAttribute(SUMO_ATTR_TYPE)) {
229  ret->setParameter |= VEHPARS_VTYPE_SET; // !!! needed?
230  ret->vtypeid = attrs.get<std::string>(SUMO_ATTR_TYPE, ret->id.c_str(), ok);
231  }
232  // parse line information
233  if (attrs.hasAttribute(SUMO_ATTR_LINE)) {
234  ret->setParameter |= VEHPARS_LINE_SET; // !!! needed?
235  ret->line = attrs.get<std::string>(SUMO_ATTR_LINE, ret->id.c_str(), ok);
236  }
237  // parse zone information
238  if (attrs.hasAttribute(SUMO_ATTR_FROM_TAZ)) {
240  ret->fromTaz = attrs.get<std::string>(SUMO_ATTR_FROM_TAZ, ret->id.c_str(), ok);
241  }
242  if (attrs.hasAttribute(SUMO_ATTR_TO_TAZ)) {
244  ret->toTaz = attrs.get<std::string>(SUMO_ATTR_TO_TAZ, ret->id.c_str(), ok);
245  }
246  // parse reroute information
247  if (attrs.getOpt<bool>(SUMO_ATTR_REROUTE, 0, ok, false)) {
249  }
250 
251  std::string error;
252  // parse depart lane information
253  if (attrs.hasAttribute(SUMO_ATTR_DEPARTLANE)) {
255  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTLANE, ret->id.c_str(), ok);
256  if (!SUMOVehicleParameter::parseDepartLane(helper, element, ret->id, ret->departLane, ret->departLaneProcedure, error)) {
257  throw ProcessError(error);
258  }
259  }
260  // parse depart position information
261  if (attrs.hasAttribute(SUMO_ATTR_DEPARTPOS)) {
263  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTPOS, ret->id.c_str(), ok);
264  if (!SUMOVehicleParameter::parseDepartPos(helper, element, ret->id, ret->departPos, ret->departPosProcedure, error)) {
265  throw ProcessError(error);
266  }
267  }
268  // parse depart speed information
269  if (attrs.hasAttribute(SUMO_ATTR_DEPARTSPEED)) {
271  std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTSPEED, ret->id.c_str(), ok);
272  if (!SUMOVehicleParameter::parseDepartSpeed(helper, element, ret->id, ret->departSpeed, ret->departSpeedProcedure, error)) {
273  throw ProcessError(error);
274  }
275  }
276 
277  // parse arrival lane information
278  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALLANE)) {
280  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALLANE, ret->id.c_str(), ok);
281  if (!SUMOVehicleParameter::parseArrivalLane(helper, element, ret->id, ret->arrivalLane, ret->arrivalLaneProcedure, error)) {
282  throw ProcessError(error);
283  }
284  }
285  // parse arrival position information
286  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
288  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, ret->id.c_str(), ok);
289  if (!SUMOVehicleParameter::parseArrivalPos(helper, element, ret->id, ret->arrivalPos, ret->arrivalPosProcedure, error)) {
290  throw ProcessError(error);
291  }
292  }
293  // parse arrival speed information
296  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALSPEED, ret->id.c_str(), ok);
297  if (!SUMOVehicleParameter::parseArrivalSpeed(helper, element, ret->id, ret->arrivalSpeed, ret->arrivalSpeedProcedure, error)) {
298  throw ProcessError(error);
299  }
300  }
301 
302  // parse color
303  if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
305  ret->color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, ret->id.c_str(), ok);
306  } else {
308  }
309  // parse person number
312  ret->personNumber = attrs.get<int>(SUMO_ATTR_PERSON_NUMBER, ret->id.c_str(), ok);
313  }
314  // parse container number
317  ret->containerNumber = attrs.get<int>(SUMO_ATTR_CONTAINER_NUMBER, ret->id.c_str(), ok);
318  }
319 }
320 
321 
323 SUMOVehicleParserHelper::beginVTypeParsing(const SUMOSAXAttributes& attrs, const std::string& file) {
324  bool ok = true;
325  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
327  if (attrs.hasAttribute(SUMO_ATTR_VCLASS)) {
328  vClass = parseVehicleClass(attrs, id);
329  }
330  SUMOVTypeParameter* vtype = new SUMOVTypeParameter(id, vClass);
331  if (attrs.hasAttribute(SUMO_ATTR_VCLASS)) {
333  }
334  if (attrs.hasAttribute(SUMO_ATTR_LENGTH)) {
335  vtype->length = attrs.get<SUMOReal>(SUMO_ATTR_LENGTH, vtype->id.c_str(), ok);
337  }
338  if (attrs.hasAttribute(SUMO_ATTR_MINGAP)) {
339  vtype->minGap = attrs.get<SUMOReal>(SUMO_ATTR_MINGAP, vtype->id.c_str(), ok);
341  }
342  if (attrs.hasAttribute(SUMO_ATTR_MAXSPEED)) {
343  vtype->maxSpeed = attrs.get<SUMOReal>(SUMO_ATTR_MAXSPEED, vtype->id.c_str(), ok);
345  }
346  if (attrs.hasAttribute(SUMO_ATTR_SPEEDFACTOR)) {
347  vtype->speedFactor = attrs.get<SUMOReal>(SUMO_ATTR_SPEEDFACTOR, vtype->id.c_str(), ok);
349  }
350  if (attrs.hasAttribute(SUMO_ATTR_SPEEDDEV)) {
351  vtype->speedDev = attrs.get<SUMOReal>(SUMO_ATTR_SPEEDDEV, vtype->id.c_str(), ok);
353  }
355  vtype->emissionClass = parseEmissionClass(attrs, vtype->id);
357  }
358  if (attrs.hasAttribute(SUMO_ATTR_IMPATIENCE)) {
359  if (attrs.get<std::string>(SUMO_ATTR_IMPATIENCE, vtype->id.c_str(), ok) == "off") {
361  } else {
362  vtype->impatience = attrs.get<SUMOReal>(SUMO_ATTR_IMPATIENCE, vtype->id.c_str(), ok);
363  }
365  }
366  if (attrs.hasAttribute(SUMO_ATTR_WIDTH)) {
367  vtype->width = attrs.get<SUMOReal>(SUMO_ATTR_WIDTH, vtype->id.c_str(), ok);
369  }
370  if (attrs.hasAttribute(SUMO_ATTR_HEIGHT)) {
371  vtype->height = attrs.get<SUMOReal>(SUMO_ATTR_HEIGHT, vtype->id.c_str(), ok);
373  }
374  if (attrs.hasAttribute(SUMO_ATTR_GUISHAPE)) {
375  vtype->shape = parseGuiShape(attrs, vtype->id);
377  }
378  if (attrs.hasAttribute(SUMO_ATTR_OSGFILE)) {
379  vtype->osgFile = attrs.get<std::string>(SUMO_ATTR_OSGFILE, vtype->id.c_str(), ok);
381  }
382  if (attrs.hasAttribute(SUMO_ATTR_IMGFILE)) {
383  vtype->imgFile = attrs.get<std::string>(SUMO_ATTR_IMGFILE, vtype->id.c_str(), ok);
384  if (vtype->imgFile != "" && !FileHelpers::isAbsolute(vtype->imgFile)) {
386  }
388  }
389  if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
390  vtype->color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, vtype->id.c_str(), ok);
392  } else {
393  vtype->color = RGBColor::YELLOW;
394  }
395  if (attrs.hasAttribute(SUMO_ATTR_PROB)) {
396  vtype->defaultProbability = attrs.get<SUMOReal>(SUMO_ATTR_PROB, vtype->id.c_str(), ok);
398  }
400  const std::string lcmS = attrs.get<std::string>(SUMO_ATTR_LANE_CHANGE_MODEL, vtype->id.c_str(), ok);
401  if (SUMOXMLDefinitions::LaneChangeModels.hasString(lcmS)) {
404  } else {
405  WRITE_ERROR("Unknown lane change model '" + lcmS + "' when parsing vtype '" + vtype->id + "'");
406  throw ProcessError();
407  }
408  }
410  const std::string cfmS = attrs.get<std::string>(SUMO_ATTR_CAR_FOLLOW_MODEL, vtype->id.c_str(), ok);
411  if (SUMOXMLDefinitions::CarFollowModels.hasString(cfmS)) {
414  } else {
415  WRITE_ERROR("Unknown car following model '" + cfmS + "' when parsing vtype '" + vtype->id + "'");
416  throw ProcessError();
417  }
418  }
420  vtype->personCapacity = attrs.get<int>(SUMO_ATTR_PERSON_CAPACITY, vtype->id.c_str(), ok);
422  }
424  vtype->containerCapacity = attrs.get<int>(SUMO_ATTR_CONTAINER_CAPACITY, vtype->id.c_str(), ok);
426  }
428  vtype->boardingDuration = attrs.getSUMOTimeReporting(SUMO_ATTR_BOARDING_DURATION, vtype->id.c_str(), ok);
430  }
432  vtype->loadingDuration = attrs.getSUMOTimeReporting(SUMO_ATTR_LOADING_DURATION, vtype->id.c_str(), ok);
434  }
435  parseVTypeEmbedded(*vtype, vtype->cfModel, attrs, true);
436  if (!ok) {
437  delete vtype;
438  throw ProcessError();
439  }
440  return vtype;
441 }
442 
443 
444 void
446  int element, const SUMOSAXAttributes& attrs,
447  bool fromVType) {
448  const CFAttrMap& allowedAttrs = getAllowedCFModelAttrs();
449  CFAttrMap::const_iterator cf_it;
450  for (cf_it = allowedAttrs.begin(); cf_it != allowedAttrs.end(); cf_it++) {
451  if (cf_it->first == element) {
452  break;
453  }
454  }
455  if (cf_it == allowedAttrs.end()) {
456  if (SUMOXMLDefinitions::Tags.has(element)) {
457  WRITE_ERROR("Unknown cfmodel " + toString((SumoXMLTag)element) + " when parsing vtype '" + into.id + "'");
458  } else {
459  WRITE_ERROR("Unknown cfmodel when parsing vtype '" + into.id + "'");
460  }
461  throw ProcessError();
462  return;
463  }
464  if (!fromVType) {
465  into.cfModel = cf_it->first;
467  }
468  bool ok = true;
469  for (std::set<SumoXMLAttr>::const_iterator it = cf_it->second.begin(); it != cf_it->second.end(); it++) {
470  if (attrs.hasAttribute(*it)) {
471  into.cfParameter[*it] = attrs.get<SUMOReal>(*it, into.id.c_str(), ok);
472  if (*it == SUMO_ATTR_TAU && TIME2STEPS(into.cfParameter[*it]) < DELTA_T) {
473  WRITE_WARNING("Value of tau=" + toString(into.cfParameter[*it])
474  + " in car following model '" + toString(into.cfModel) + "' lower than simulation step size may cause collisions");
475  }
476  }
477  }
478  if (!ok) {
479  throw ProcessError();
480  }
481 }
482 
483 
486  // init on first use
487  if (allowedCFModelAttrs.size() == 0) {
488  std::set<SumoXMLAttr> krausParams;
489  krausParams.insert(SUMO_ATTR_ACCEL);
490  krausParams.insert(SUMO_ATTR_DECEL);
491  krausParams.insert(SUMO_ATTR_SIGMA);
492  krausParams.insert(SUMO_ATTR_TAU);
496 
497  std::set<SumoXMLAttr> smartSKParams;
498  smartSKParams.insert(SUMO_ATTR_ACCEL);
499  smartSKParams.insert(SUMO_ATTR_DECEL);
500  smartSKParams.insert(SUMO_ATTR_SIGMA);
501  smartSKParams.insert(SUMO_ATTR_TAU);
502  smartSKParams.insert(SUMO_ATTR_TMP1);
503  smartSKParams.insert(SUMO_ATTR_TMP2);
504  smartSKParams.insert(SUMO_ATTR_TMP3);
505  smartSKParams.insert(SUMO_ATTR_TMP4);
506  smartSKParams.insert(SUMO_ATTR_TMP5);
507  allowedCFModelAttrs[SUMO_TAG_CF_SMART_SK] = smartSKParams;
508 
509  std::set<SumoXMLAttr> daniel1Params;
510  daniel1Params.insert(SUMO_ATTR_ACCEL);
511  daniel1Params.insert(SUMO_ATTR_DECEL);
512  daniel1Params.insert(SUMO_ATTR_SIGMA);
513  daniel1Params.insert(SUMO_ATTR_TAU);
514  daniel1Params.insert(SUMO_ATTR_TMP1);
515  daniel1Params.insert(SUMO_ATTR_TMP2);
516  daniel1Params.insert(SUMO_ATTR_TMP3);
517  daniel1Params.insert(SUMO_ATTR_TMP4);
518  daniel1Params.insert(SUMO_ATTR_TMP5);
519  allowedCFModelAttrs[SUMO_TAG_CF_DANIEL1] = daniel1Params;
520 
521  std::set<SumoXMLAttr> pwagParams;
522  pwagParams.insert(SUMO_ATTR_ACCEL);
523  pwagParams.insert(SUMO_ATTR_DECEL);
524  pwagParams.insert(SUMO_ATTR_SIGMA);
525  pwagParams.insert(SUMO_ATTR_TAU);
526  pwagParams.insert(SUMO_ATTR_CF_PWAGNER2009_TAULAST);
527  pwagParams.insert(SUMO_ATTR_CF_PWAGNER2009_APPROB);
529 
530  std::set<SumoXMLAttr> idmParams;
531  idmParams.insert(SUMO_ATTR_ACCEL);
532  idmParams.insert(SUMO_ATTR_DECEL);
533  idmParams.insert(SUMO_ATTR_TAU);
534  idmParams.insert(SUMO_ATTR_CF_IDM_DELTA);
535  idmParams.insert(SUMO_ATTR_CF_IDM_STEPPING);
537 
538  std::set<SumoXMLAttr> idmmParams;
539  idmmParams.insert(SUMO_ATTR_ACCEL);
540  idmmParams.insert(SUMO_ATTR_DECEL);
541  idmmParams.insert(SUMO_ATTR_TAU);
542  idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_FACTOR);
543  idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_TIME);
544  idmmParams.insert(SUMO_ATTR_CF_IDM_STEPPING);
546 
547  std::set<SumoXMLAttr> bkernerParams;
548  bkernerParams.insert(SUMO_ATTR_ACCEL);
549  bkernerParams.insert(SUMO_ATTR_DECEL);
550  bkernerParams.insert(SUMO_ATTR_TAU);
551  bkernerParams.insert(SUMO_ATTR_K);
552  bkernerParams.insert(SUMO_ATTR_CF_KERNER_PHI);
553  allowedCFModelAttrs[SUMO_TAG_CF_BKERNER] = bkernerParams;
554 
555  std::set<SumoXMLAttr> wiedemannParams;
556  wiedemannParams.insert(SUMO_ATTR_ACCEL);
557  wiedemannParams.insert(SUMO_ATTR_DECEL);
558  wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_SECURITY);
559  wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_ESTIMATION);
560  allowedCFModelAttrs[SUMO_TAG_CF_WIEDEMANN] = wiedemannParams;
561  }
562  return allowedCFModelAttrs;
563 }
564 
565 
568  const std::string& id) {
570  try {
571  bool ok = true;
572  std::string vclassS = attrs.getOpt<std::string>(SUMO_ATTR_VCLASS, id.c_str(), ok, "");
573  if (vclassS == "") {
574  return vclass;
575  }
576  const SUMOVehicleClass result = getVehicleClassID(vclassS);
577  const std::string& realName = SumoVehicleClassStrings.getString(result);
578  if (realName != vclassS) {
579  WRITE_WARNING("The vehicle class '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is deprecated, use '" + realName + "' instead.");
580  }
581  return result;
582  } catch (...) {
583  WRITE_ERROR("The class for " + attrs.getObjectType() + " '" + id + "' is not known.");
584  }
585  return vclass;
586 }
587 
588 
591  try {
592  bool ok = true;
593  std::string eClassS = attrs.getOpt<std::string>(SUMO_ATTR_EMISSIONCLASS, id.c_str(), ok, "");
594  return PollutantsInterface::getClassByName(eClassS);
595  } catch (...) {
596  WRITE_ERROR("The emission class for " + attrs.getObjectType() + " '" + id + "' is not known.");
597  return 0;
598  }
599 }
600 
601 
603 SUMOVehicleParserHelper::parseGuiShape(const SUMOSAXAttributes& attrs, const std::string& id) {
604  bool ok = true;
605  std::string vclassS = attrs.getOpt<std::string>(SUMO_ATTR_GUISHAPE, id.c_str(), ok, "");
606  if (SumoVehicleShapeStrings.hasString(vclassS)) {
607  const SUMOVehicleShape result = SumoVehicleShapeStrings.get(vclassS);
608  const std::string& realName = SumoVehicleShapeStrings.getString(result);
609  if (realName != vclassS) {
610  WRITE_WARNING("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is deprecated, use '" + realName + "' instead.");
611  }
612  return result;
613  } else {
614  WRITE_ERROR("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is not known.");
615  return SVS_UNKNOWN;
616  }
617 }
618 
619 /****************************************************************************/
620 
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
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.
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.
virtual std::string getName(int attr) const =0
Converts the given attribute id into a man readable string.
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
SUMOVehicleShape shape
This class&#39; shape.
Structure representing possible vehicle parameter.
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)
SUMOReal length
The physical vehicle length.
const int VTYPEPARS_BOARDING_DURATION
SUMOReal arrivalPos
(optional) The position the vehicle shall arrive on
T MAX2(T a, T b)
Definition: StdDefs.h:75
SUMOTime DELTA_T
Definition: SUMOTime.cpp:39
const int VEHPARS_ARRIVALLANE_SET
unsigned int personNumber
The static number of persons in the vehicle when it departs (not including boarding persons) ...
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_PROBABILITY_SET
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static SUMOVehicleClass parseVehicleClass(const SUMOSAXAttributes &attrs, const std::string &id)
Parses the vehicle class.
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 VTYPEPARS_LANE_CHANGE_MODEL_SET
const int VEHPARS_ARRIVALSPEED_SET
static const CFAttrMap & getAllowedCFModelAttrs()
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 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
std::map< SumoXMLTag, std::set< SumoXMLAttr > > CFAttrMap
int arrivalLane
(optional) The lane the vehicle shall arrive on (not used yet)
std::string imgFile
Image file for this class.
unsigned int containerCapacity
The container capacity of the vehicle.
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
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:54
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
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
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 setParameter
Information for the router which parameter were set.
static const RGBColor YELLOW
Definition: RGBColor.h:192
Structure representing possible vehicle parameter.
SUMOReal impatience
The vehicle&#39;s impatience (willingness to obstruct others)
#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.
unsigned int personCapacity
The person capacity of the vehicle.
SUMOReal defaultProbability
The probability when being added to a distribution without an explicit probability.
const int VTYPEPARS_IMGFILE_SET
SUMOTime loadingDuration
The time a container needs to get loaded on the vehicle.
RGBColor color
The color.
const int VEHPARS_DEPARTLANE_SET
std::string id
The vehicle type&#39;s id.
SUMOReal departPos
(optional) The position the vehicle shall depart from
const int VTYPEPARS_PERSON_CAPACITY
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:213
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
unsigned int containerNumber
The static number of containers in the vehicle when it departs.
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
A color information.
const int VTYPEPARS_EMISSIONCLASS_SET
const int VTYPEPARS_COLOR_SET
const int VTYPEPARS_SHAPE_SET
static StringBijection< LaneChangeModel > LaneChangeModels
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
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.