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-2015 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)) {
107 #ifdef HAVE_SUBSECOND_TIMESTEPS
108  ret->repetitionOffset = attrs.getSUMOTimeReporting(SUMO_ATTR_PERIOD, id.c_str(), ok);
109 #else
110  ret->repetitionOffset = attrs.get<SUMOReal>(SUMO_ATTR_PERIOD, id.c_str(), ok);
111 #endif
112  }
113  if (attrs.hasAttribute(SUMO_ATTR_VEHSPERHOUR)) {
115  const SUMOReal vph = attrs.get<SUMOReal>(SUMO_ATTR_VEHSPERHOUR, id.c_str(), ok);
116  if (ok && vph <= 0) {
117  delete ret;
118  throw ProcessError("Invalid repetition rate in the definition of flow '" + id + "'.");
119  }
120  if (ok && vph != 0) {
121  ret->repetitionOffset = TIME2STEPS(3600. / vph);
122  }
123  }
124  if (attrs.hasAttribute(SUMO_ATTR_PROB)) {
125  ret->repetitionProbability = attrs.get<SUMOReal>(SUMO_ATTR_PROB, id.c_str(), ok);
126  if (ok && (ret->repetitionProbability <= 0 || ret->repetitionProbability > 1)) {
127  delete ret;
128  throw ProcessError("Invalid repetition probability in the definition of flow '" + id + "'.");
129  }
130  }
131 
132  ret->depart = beginDefault;
133  if (attrs.hasAttribute(SUMO_ATTR_BEGIN)) {
134  ret->depart = attrs.getSUMOTimeReporting(SUMO_ATTR_BEGIN, id.c_str(), ok);
135  }
136  if (ok && ret->depart < 0) {
137  delete ret;
138  throw ProcessError("Negative begin time in the definition of flow '" + id + "'.");
139  }
140  SUMOTime end = endDefault;
141  if (end < 0) {
142  end = SUMOTime_MAX;
143  }
144  if (attrs.hasAttribute(SUMO_ATTR_END)) {
145  end = attrs.getSUMOTimeReporting(SUMO_ATTR_END, id.c_str(), ok);
146  }
147  if (ok && end <= ret->depart) {
148  delete ret;
149  throw ProcessError("Flow '" + id + "' ends before or at its begin time.");
150  }
151  if (attrs.hasAttribute(SUMO_ATTR_NUMBER)) {
152  ret->repetitionNumber = attrs.get<int>(SUMO_ATTR_NUMBER, id.c_str(), ok);
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 = (end - ret->depart) / ret->repetitionNumber;
163  }
164  }
165  } else {
166  // interpret repetitionNumber
167  if (ok && ret->repetitionProbability > 0) {
168  ret->repetitionNumber = INT_MAX;
169  ret->repetitionEnd = end;
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 (end == SUMOTime_MAX) {
176  ret->repetitionNumber = INT_MAX;
177  } else {
178  ret->repetitionNumber = MAX2(1, (int)(((SUMOReal)(end - ret->depart)) / ret->repetitionOffset + 0.5));
179  }
180  }
181  }
182  if (!ok) {
183  delete ret;
184  throw ProcessError();
185  }
186  return ret;
187 }
188 
189 
192  const bool optionalID, const bool skipDepart, const bool isPerson) {
193  bool ok = true;
194  std::string id, errorMsg;
195  if (optionalID) {
196  id = attrs.getOpt<std::string>(SUMO_ATTR_ID, 0, ok, "");
197  } else {
198  id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
199  }
201  ret->id = id;
202  if (isPerson) {
204  }
205  try {
206  parseCommonAttributes(attrs, ret, "vehicle");
207  if (!skipDepart) {
208  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPART, ret->id.c_str(), ok);
209  if (!ok || !SUMOVehicleParameter::parseDepart(helper, "vehicle", ret->id, ret->depart, ret->departProcedure, errorMsg)) {
210  throw ProcessError(errorMsg);
211  }
212  }
213  } catch (ProcessError&) {
214  delete ret;
215  throw;
216  }
217  return ret;
218 }
219 
220 
221 void
223  SUMOVehicleParameter* ret, std::string element) {
224  //ret->refid = attrs.getStringSecure(SUMO_ATTR_REFID, "");
225  bool ok = true;
226  // parse route information
227  if (attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
228  ret->setParameter |= VEHPARS_ROUTE_SET; // !!! needed?
229  ret->routeid = attrs.get<std::string>(SUMO_ATTR_ROUTE, ret->id.c_str(), ok);
230  }
231  // parse type information
232  if (attrs.hasAttribute(SUMO_ATTR_TYPE)) {
233  ret->setParameter |= VEHPARS_VTYPE_SET; // !!! needed?
234  ret->vtypeid = attrs.get<std::string>(SUMO_ATTR_TYPE, ret->id.c_str(), ok);
235  }
236  // parse line information
237  if (attrs.hasAttribute(SUMO_ATTR_LINE)) {
238  ret->setParameter |= VEHPARS_LINE_SET; // !!! needed?
239  ret->line = attrs.get<std::string>(SUMO_ATTR_LINE, ret->id.c_str(), ok);
240  }
241  // parse zone information
242  if (attrs.hasAttribute(SUMO_ATTR_FROM_TAZ)) {
244  ret->fromTaz = attrs.get<std::string>(SUMO_ATTR_FROM_TAZ, ret->id.c_str(), ok);
245  }
246  if (attrs.hasAttribute(SUMO_ATTR_TO_TAZ)) {
248  ret->toTaz = attrs.get<std::string>(SUMO_ATTR_TO_TAZ, ret->id.c_str(), ok);
249  }
250  // parse reroute information
251  if (attrs.getOpt<bool>(SUMO_ATTR_REROUTE, 0, ok, false)) {
253  }
254 
255  std::string error;
256  // parse depart lane information
257  if (attrs.hasAttribute(SUMO_ATTR_DEPARTLANE)) {
259  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTLANE, ret->id.c_str(), ok);
260  if (!SUMOVehicleParameter::parseDepartLane(helper, element, ret->id, ret->departLane, ret->departLaneProcedure, error)) {
261  throw ProcessError(error);
262  }
263  }
264  // parse depart position information
265  if (attrs.hasAttribute(SUMO_ATTR_DEPARTPOS)) {
267  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTPOS, ret->id.c_str(), ok);
268  if (!SUMOVehicleParameter::parseDepartPos(helper, element, ret->id, ret->departPos, ret->departPosProcedure, error)) {
269  throw ProcessError(error);
270  }
271  }
272  // parse depart speed information
273  if (attrs.hasAttribute(SUMO_ATTR_DEPARTSPEED)) {
275  std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTSPEED, ret->id.c_str(), ok);
276  if (!SUMOVehicleParameter::parseDepartSpeed(helper, element, ret->id, ret->departSpeed, ret->departSpeedProcedure, error)) {
277  throw ProcessError(error);
278  }
279  }
280 
281  // parse arrival lane information
282  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALLANE)) {
284  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALLANE, ret->id.c_str(), ok);
285  if (!SUMOVehicleParameter::parseArrivalLane(helper, element, ret->id, ret->arrivalLane, ret->arrivalLaneProcedure, error)) {
286  throw ProcessError(error);
287  }
288  }
289  // parse arrival position information
290  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
292  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, ret->id.c_str(), ok);
293  if (!SUMOVehicleParameter::parseArrivalPos(helper, element, ret->id, ret->arrivalPos, ret->arrivalPosProcedure, error)) {
294  throw ProcessError(error);
295  }
296  }
297  // parse arrival speed information
300  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALSPEED, ret->id.c_str(), ok);
301  if (!SUMOVehicleParameter::parseArrivalSpeed(helper, element, ret->id, ret->arrivalSpeed, ret->arrivalSpeedProcedure, error)) {
302  throw ProcessError(error);
303  }
304  }
305 
306  // parse color
307  if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
309  ret->color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, ret->id.c_str(), ok);
310  } else {
312  }
313  // parse person number
316  ret->personNumber = attrs.get<int>(SUMO_ATTR_PERSON_NUMBER, ret->id.c_str(), ok);
317  }
318  // parse container number
321  ret->containerNumber = attrs.get<int>(SUMO_ATTR_CONTAINER_NUMBER, ret->id.c_str(), ok);
322  }
323 }
324 
325 
327 SUMOVehicleParserHelper::beginVTypeParsing(const SUMOSAXAttributes& attrs, const std::string& file) {
328  bool ok = true;
329  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
331  if (attrs.hasAttribute(SUMO_ATTR_VCLASS)) {
332  vClass = parseVehicleClass(attrs, id);
333  }
334  SUMOVTypeParameter* vtype = new SUMOVTypeParameter(id, vClass);
335  if (attrs.hasAttribute(SUMO_ATTR_VCLASS)) {
337  }
338  if (attrs.hasAttribute(SUMO_ATTR_LENGTH)) {
339  vtype->length = attrs.get<SUMOReal>(SUMO_ATTR_LENGTH, vtype->id.c_str(), ok);
341  }
342  if (attrs.hasAttribute(SUMO_ATTR_MINGAP)) {
343  vtype->minGap = attrs.get<SUMOReal>(SUMO_ATTR_MINGAP, vtype->id.c_str(), ok);
345  }
346  if (attrs.hasAttribute(SUMO_ATTR_MAXSPEED)) {
347  vtype->maxSpeed = attrs.get<SUMOReal>(SUMO_ATTR_MAXSPEED, vtype->id.c_str(), ok);
349  }
350  if (attrs.hasAttribute(SUMO_ATTR_SPEEDFACTOR)) {
351  vtype->speedFactor = attrs.get<SUMOReal>(SUMO_ATTR_SPEEDFACTOR, vtype->id.c_str(), ok);
353  }
354  if (attrs.hasAttribute(SUMO_ATTR_SPEEDDEV)) {
355  vtype->speedDev = attrs.get<SUMOReal>(SUMO_ATTR_SPEEDDEV, vtype->id.c_str(), ok);
357  }
359  vtype->emissionClass = parseEmissionClass(attrs, vtype->id);
361  }
362  if (attrs.hasAttribute(SUMO_ATTR_IMPATIENCE)) {
363  if (attrs.get<std::string>(SUMO_ATTR_IMPATIENCE, vtype->id.c_str(), ok) == "off") {
365  } else {
366  vtype->impatience = attrs.get<SUMOReal>(SUMO_ATTR_IMPATIENCE, vtype->id.c_str(), ok);
367  }
369  }
370  if (attrs.hasAttribute(SUMO_ATTR_WIDTH)) {
371  vtype->width = attrs.get<SUMOReal>(SUMO_ATTR_WIDTH, vtype->id.c_str(), ok);
373  }
374  if (attrs.hasAttribute(SUMO_ATTR_HEIGHT)) {
375  vtype->height = attrs.get<SUMOReal>(SUMO_ATTR_HEIGHT, vtype->id.c_str(), ok);
377  }
378  if (attrs.hasAttribute(SUMO_ATTR_GUISHAPE)) {
379  vtype->shape = parseGuiShape(attrs, vtype->id);
381  }
382  if (attrs.hasAttribute(SUMO_ATTR_OSGFILE)) {
383  vtype->osgFile = attrs.get<std::string>(SUMO_ATTR_OSGFILE, vtype->id.c_str(), ok);
385  }
386  if (attrs.hasAttribute(SUMO_ATTR_IMGFILE)) {
387  vtype->imgFile = attrs.get<std::string>(SUMO_ATTR_IMGFILE, vtype->id.c_str(), ok);
388  if (vtype->imgFile != "" && !FileHelpers::isAbsolute(vtype->imgFile)) {
390  }
392  }
393  if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
394  vtype->color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, vtype->id.c_str(), ok);
396  } else {
397  vtype->color = RGBColor::YELLOW;
398  }
399  if (attrs.hasAttribute(SUMO_ATTR_PROB)) {
400  vtype->defaultProbability = attrs.get<SUMOReal>(SUMO_ATTR_PROB, vtype->id.c_str(), ok);
402  }
404  const std::string lcmS = attrs.get<std::string>(SUMO_ATTR_LANE_CHANGE_MODEL, vtype->id.c_str(), ok);
405  if (SUMOXMLDefinitions::LaneChangeModels.hasString(lcmS)) {
408  } else {
409  WRITE_ERROR("Unknown lane change model '" + lcmS + "' when parsing vtype '" + vtype->id + "'");
410  throw ProcessError();
411  }
412  }
414  vtype->personCapacity = attrs.get<int>(SUMO_ATTR_PERSON_CAPACITY, vtype->id.c_str(), ok);
416  }
418  vtype->containerCapacity = attrs.get<int>(SUMO_ATTR_CONTAINER_CAPACITY, vtype->id.c_str(), ok);
420  }
422  vtype->boardingDuration = attrs.getSUMOTimeReporting(SUMO_ATTR_BOARDING_DURATION, vtype->id.c_str(), ok);
424  }
426  vtype->loadingDuration = attrs.getSUMOTimeReporting(SUMO_ATTR_LOADING_DURATION, vtype->id.c_str(), ok);
428  }
429  try {
430  parseVTypeEmbedded(*vtype, SUMO_TAG_CF_KRAUSS, attrs, true);
431  } catch (ProcessError&) {
432  throw;
433  }
434  if (!ok) {
435  delete vtype;
436  throw ProcessError();
437  }
438  return vtype;
439 }
440 
441 
442 void
444  int element, const SUMOSAXAttributes& attrs,
445  bool fromVType) {
446  const CFAttrMap& allowedAttrs = getAllowedCFModelAttrs();
447  CFAttrMap::const_iterator cf_it;
448  for (cf_it = allowedAttrs.begin(); cf_it != allowedAttrs.end(); cf_it++) {
449  if (cf_it->first == element) {
450  break;
451  }
452  }
453  if (cf_it == allowedAttrs.end()) {
454  if (SUMOXMLDefinitions::Tags.has(element)) {
455  WRITE_ERROR("Unknown cfmodel " + toString((SumoXMLTag)element) + " when parsing vtype '" + into.id + "'");
456  } else {
457  WRITE_ERROR("Unknown cfmodel when parsing vtype '" + into.id + "'");
458  }
459  throw ProcessError();
460  return;
461  }
462  if (!fromVType) {
463  into.cfModel = cf_it->first;
464  }
465  bool ok = true;
466  for (std::set<SumoXMLAttr>::const_iterator it = cf_it->second.begin(); it != cf_it->second.end(); it++) {
467  if (attrs.hasAttribute(*it)) {
468  into.cfParameter[*it] = attrs.get<SUMOReal>(*it, into.id.c_str(), ok);
469  if (*it == SUMO_ATTR_TAU && TIME2STEPS(into.cfParameter[*it]) < DELTA_T) {
470  WRITE_WARNING("Value of tau=" + toString(into.cfParameter[*it])
471  + " in car following model '" + toString(into.cfModel) + "' lower than simulation step size may cause collisions");
472  }
473  }
474  }
475  if (!ok) {
476  throw ProcessError();
477  }
478 }
479 
480 
483  // init on first use
484  if (allowedCFModelAttrs.size() == 0) {
485  std::set<SumoXMLAttr> krausParams;
486  krausParams.insert(SUMO_ATTR_ACCEL);
487  krausParams.insert(SUMO_ATTR_DECEL);
488  krausParams.insert(SUMO_ATTR_SIGMA);
489  krausParams.insert(SUMO_ATTR_TAU);
494 
495  std::set<SumoXMLAttr> smartSKParams;
496  smartSKParams.insert(SUMO_ATTR_ACCEL);
497  smartSKParams.insert(SUMO_ATTR_DECEL);
498  smartSKParams.insert(SUMO_ATTR_SIGMA);
499  smartSKParams.insert(SUMO_ATTR_TAU);
500  smartSKParams.insert(SUMO_ATTR_TMP1);
501  smartSKParams.insert(SUMO_ATTR_TMP2);
502  smartSKParams.insert(SUMO_ATTR_TMP3);
503  smartSKParams.insert(SUMO_ATTR_TMP4);
504  smartSKParams.insert(SUMO_ATTR_TMP5);
505  allowedCFModelAttrs[SUMO_TAG_CF_SMART_SK] = smartSKParams;
506 
507  std::set<SumoXMLAttr> daniel1Params;
508  daniel1Params.insert(SUMO_ATTR_ACCEL);
509  daniel1Params.insert(SUMO_ATTR_DECEL);
510  daniel1Params.insert(SUMO_ATTR_SIGMA);
511  daniel1Params.insert(SUMO_ATTR_TAU);
512  daniel1Params.insert(SUMO_ATTR_TMP1);
513  daniel1Params.insert(SUMO_ATTR_TMP2);
514  daniel1Params.insert(SUMO_ATTR_TMP3);
515  daniel1Params.insert(SUMO_ATTR_TMP4);
516  daniel1Params.insert(SUMO_ATTR_TMP5);
517  allowedCFModelAttrs[SUMO_TAG_CF_DANIEL1] = daniel1Params;
518 
519  std::set<SumoXMLAttr> pwagParams;
520  pwagParams.insert(SUMO_ATTR_ACCEL);
521  pwagParams.insert(SUMO_ATTR_DECEL);
522  pwagParams.insert(SUMO_ATTR_SIGMA);
523  pwagParams.insert(SUMO_ATTR_TAU);
524  pwagParams.insert(SUMO_ATTR_CF_PWAGNER2009_TAULAST);
525  pwagParams.insert(SUMO_ATTR_CF_PWAGNER2009_APPROB);
527 
528  std::set<SumoXMLAttr> idmParams;
529  idmParams.insert(SUMO_ATTR_ACCEL);
530  idmParams.insert(SUMO_ATTR_DECEL);
531  idmParams.insert(SUMO_ATTR_TAU);
532  idmParams.insert(SUMO_ATTR_CF_IDM_DELTA);
533  idmParams.insert(SUMO_ATTR_CF_IDM_STEPPING);
535 
536  std::set<SumoXMLAttr> idmmParams;
537  idmmParams.insert(SUMO_ATTR_ACCEL);
538  idmmParams.insert(SUMO_ATTR_DECEL);
539  idmmParams.insert(SUMO_ATTR_TAU);
540  idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_FACTOR);
541  idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_TIME);
542  idmmParams.insert(SUMO_ATTR_CF_IDM_STEPPING);
544 
545  std::set<SumoXMLAttr> bkernerParams;
546  bkernerParams.insert(SUMO_ATTR_ACCEL);
547  bkernerParams.insert(SUMO_ATTR_DECEL);
548  bkernerParams.insert(SUMO_ATTR_TAU);
549  bkernerParams.insert(SUMO_ATTR_K);
550  bkernerParams.insert(SUMO_ATTR_CF_KERNER_PHI);
551  allowedCFModelAttrs[SUMO_TAG_CF_BKERNER] = bkernerParams;
552 
553  std::set<SumoXMLAttr> wiedemannParams;
554  wiedemannParams.insert(SUMO_ATTR_ACCEL);
555  wiedemannParams.insert(SUMO_ATTR_DECEL);
556  wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_SECURITY);
557  wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_ESTIMATION);
558  allowedCFModelAttrs[SUMO_TAG_CF_WIEDEMANN] = wiedemannParams;
559  }
560  return allowedCFModelAttrs;
561 }
562 
563 
566  const std::string& id) {
568  try {
569  bool ok = true;
570  std::string vclassS = attrs.getOpt<std::string>(SUMO_ATTR_VCLASS, id.c_str(), ok, "");
571  if (vclassS == "") {
572  return vclass;
573  }
574  const SUMOVehicleClass result = getVehicleClassID(vclassS);
575  const std::string& realName = SumoVehicleClassStrings.getString(result);
576  if (realName != vclassS) {
577  WRITE_WARNING("The vehicle class '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is deprecated, use '" + realName + "' instead.");
578  }
579  return result;
580  } catch (...) {
581  WRITE_ERROR("The class for " + attrs.getObjectType() + " '" + id + "' is not known.");
582  }
583  return vclass;
584 }
585 
586 
589  try {
590  bool ok = true;
591  std::string eClassS = attrs.getOpt<std::string>(SUMO_ATTR_EMISSIONCLASS, id.c_str(), ok, "");
592  return PollutantsInterface::getClassByName(eClassS);
593  } catch (...) {
594  WRITE_ERROR("The emission class for " + attrs.getObjectType() + " '" + id + "' is not known.");
595  return 0;
596  }
597 }
598 
599 
601 SUMOVehicleParserHelper::parseGuiShape(const SUMOSAXAttributes& attrs, const std::string& id) {
602  bool ok = true;
603  std::string vclassS = attrs.getOpt<std::string>(SUMO_ATTR_GUISHAPE, id.c_str(), ok, "");
604  if (SumoVehicleShapeStrings.hasString(vclassS)) {
605  const SUMOVehicleShape result = SumoVehicleShapeStrings.get(vclassS);
606  const std::string& realName = SumoVehicleShapeStrings.getString(result);
607  if (realName != vclassS) {
608  WRITE_WARNING("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is deprecated, use '" + realName + "' instead.");
609  }
610  return result;
611  } else {
612  WRITE_ERROR("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is not known.");
613  return SVS_UNKNOWN;
614  }
615 }
616 
617 /****************************************************************************/
618 
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
SUMOTime repetitionEnd
The time at which the flow ends (only needed when using repetitionProbability)
SUMOReal repetitionProbability
The probability for emitting a vehicle per second.
SumoXMLTag
Numbers representing SUMO-XML - element names.
SumoXMLTag cfModel
The enum-representation of the car-following model to use.
RGBColor color
The vehicle's color.
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.
int repetitionNumber
The number of times the vehicle shall be repeatedly inserted.
std::string vtypeid
The vehicle'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' 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'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:74
const int VEHPARS_ARRIVALLANE_SET
unsigned int personNumber
The number of persons in the vehicle.
SUMOReal width
This class' width.
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle's end speed shall be chosen.
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
const int VTYPEPARS_OSGFILE_SET
SUMOReal repetitionOffset
The time offset between vehicle reinsertions.
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'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's initial speed shall be chosen.
SUMOTime boardingDuration
The time a person needs to board the vehicle.
std::string routeid
The vehicle'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'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.
SUMOTime depart
The vehicle's departure time.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
unsigned int containerCapacity
The container capacity of the vehicle.
const int VEHPARS_ROUTE_SET
std::string fromTaz
The vehicle'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:53
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.
const int VEHPARS_FROM_TAZ_SET
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
std::string line
The vehicle'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:205
SUMOReal maxSpeed
The vehicle type'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'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's id.
int SUMOTime
Definition: SUMOTime.h:43
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:218
const int VTYPEPARS_WIDTH_SET
#define DELTA_T
Definition: SUMOTime.h:50
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 number of containers in the vehicle.
LaneChangeModel lcModel
The lane-change model to use.
SUMOReal height
This class' 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's id.
const int VTYPEPARS_IMPATIENCE_SET
SUMOReal minGap
This class' 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.