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 
45 // ===========================================================================
46 // static members
47 // ===========================================================================
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
56 SUMOVehicleParserHelper::parseFlowAttributes(const SUMOSAXAttributes& attrs, const SUMOTime beginDefault, const SUMOTime endDefault) {
57  bool ok = true;
58  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
60  throw ProcessError("At most one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
61  "' and '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
62  "' has to be given in the definition of flow '" + id + "'.");
63  }
65  throw ProcessError("At most one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
66  "' and '" + attrs.getName(SUMO_ATTR_PROB) +
67  "' has to be given in the definition of flow '" + id + "'.");
68  }
70  throw ProcessError("At most one of '" + attrs.getName(SUMO_ATTR_PROB) +
71  "' and '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
72  "' has to be given in the definition of flow '" + id + "'.");
73  }
76  throw ProcessError("If '" + attrs.getName(SUMO_ATTR_PERIOD) +
77  "', '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
78  "' or '" + attrs.getName(SUMO_ATTR_PROB) +
79  "' are given at most one of '" + attrs.getName(SUMO_ATTR_END) +
80  "' and '" + attrs.getName(SUMO_ATTR_NUMBER) +
81  "' are allowed in flow '" + id + "'.");
82  }
83  } else {
84  if (!attrs.hasAttribute(SUMO_ATTR_NUMBER)) {
85  throw ProcessError("At least one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
86  "', '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
87  "', '" + attrs.getName(SUMO_ATTR_PROB) +
88  "', and '" + attrs.getName(SUMO_ATTR_NUMBER) +
89  "' is needed in flow '" + id + "'.");
90  }
91  }
93  ret->id = id;
94  try {
95  parseCommonAttributes(attrs, ret, "flow");
96  } catch (ProcessError&) {
97  delete ret;
98  throw;
99  }
100 
101  // parse repetition information
102  if (attrs.hasAttribute(SUMO_ATTR_PERIOD)) {
103  ret->setParameter |= VEHPARS_PERIODFREQ_SET;
104  ret->repetitionOffset = attrs.getSUMOTimeReporting(SUMO_ATTR_PERIOD, id.c_str(), ok);
105  }
106  if (attrs.hasAttribute(SUMO_ATTR_VEHSPERHOUR)) {
107  ret->setParameter |= VEHPARS_PERIODFREQ_SET;
108  const double vph = attrs.get<double>(SUMO_ATTR_VEHSPERHOUR, id.c_str(), ok);
109  if (ok && vph <= 0) {
110  delete ret;
111  throw ProcessError("Invalid repetition rate in the definition of flow '" + id + "'.");
112  }
113  if (ok && vph != 0) {
114  ret->repetitionOffset = TIME2STEPS(3600. / vph);
115  }
116  }
117  if (attrs.hasAttribute(SUMO_ATTR_PROB)) {
118  ret->repetitionProbability = attrs.get<double>(SUMO_ATTR_PROB, id.c_str(), ok);
119  if (ok && (ret->repetitionProbability <= 0 || ret->repetitionProbability > 1)) {
120  delete ret;
121  throw ProcessError("Invalid repetition probability in the definition of flow '" + id + "'.");
122  }
123  }
124 
125  ret->depart = beginDefault;
126  if (attrs.hasAttribute(SUMO_ATTR_BEGIN)) {
127  ret->depart = attrs.getSUMOTimeReporting(SUMO_ATTR_BEGIN, id.c_str(), ok);
128  }
129  if (ok && ret->depart < 0) {
130  delete ret;
131  throw ProcessError("Negative begin time in the definition of flow '" + id + "'.");
132  }
133  ret->repetitionEnd = endDefault;
134  if (ret->repetitionEnd < 0) {
135  ret->repetitionEnd = SUMOTime_MAX;
136  }
137  if (attrs.hasAttribute(SUMO_ATTR_END)) {
138  ret->repetitionEnd = attrs.getSUMOTimeReporting(SUMO_ATTR_END, id.c_str(), ok);
139  }
140  if (ok && ret->repetitionEnd < ret->depart) {
141  delete ret;
142  throw ProcessError("Flow '" + id + "' ends before its begin time.");
143  }
144  if (attrs.hasAttribute(SUMO_ATTR_NUMBER)) {
145  ret->repetitionNumber = attrs.get<int>(SUMO_ATTR_NUMBER, id.c_str(), ok);
146  ret->setParameter |= VEHPARS_PERIODFREQ_SET;
147  if (ret->repetitionNumber == 0) {
148  WRITE_WARNING("Flow '" + id + "' has 0 vehicles; will skip it.");
149  } else {
150  if (ok && ret->repetitionNumber < 0) {
151  delete ret;
152  throw ProcessError("Negative repetition number in the definition of flow '" + id + "'.");
153  }
154  if (ok && ret->repetitionOffset < 0) {
155  ret->repetitionOffset = (ret->repetitionEnd - ret->depart) / ret->repetitionNumber;
156  }
157  }
158  ret->repetitionEnd = ret->depart + ret->repetitionNumber * ret->repetitionOffset;
159  } else {
160  // interpret repetitionNumber
161  if (ok && ret->repetitionProbability > 0) {
162  ret->repetitionNumber = std::numeric_limits<int>::max();
163  } else {
164  if (ok && ret->repetitionOffset <= 0) {
165  delete ret;
166  throw ProcessError("Invalid repetition rate in the definition of flow '" + id + "'.");
167  }
168  if (ret->repetitionEnd == SUMOTime_MAX) {
169  ret->repetitionNumber = std::numeric_limits<int>::max();
170  } else {
171  const double repLength = (double)(ret->repetitionEnd - ret->depart);
172  ret->repetitionNumber = (int)ceil(repLength / ret->repetitionOffset);
173  }
174  }
175  }
176  if (!ok) {
177  delete ret;
178  throw ProcessError();
179  }
180  return ret;
181 }
182 
183 
186  const bool optionalID, const bool skipDepart, const bool isPerson) {
187  bool ok = true;
188  std::string id, errorMsg;
189  if (optionalID) {
190  id = attrs.getOpt<std::string>(SUMO_ATTR_ID, 0, ok, "");
191  } else {
192  id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
193  }
195  ret->id = id;
196  if (isPerson) {
197  ret->vtypeid = DEFAULT_PEDTYPE_ID;
198  }
199  try {
200  parseCommonAttributes(attrs, ret, "vehicle");
201  if (!skipDepart) {
202  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPART, ret->id.c_str(), ok);
203  if (!ok || !SUMOVehicleParameter::parseDepart(helper, "vehicle", ret->id, ret->depart, ret->departProcedure, errorMsg)) {
204  throw ProcessError(errorMsg);
205  }
206  }
207  } catch (ProcessError&) {
208  delete ret;
209  throw;
210  }
211  return ret;
212 }
213 
214 
215 void
217  SUMOVehicleParameter* ret, std::string element) {
218  //ret->refid = attrs.getStringSecure(SUMO_ATTR_REFID, "");
219  bool ok = true;
220  // parse route information
221  if (attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
222  ret->setParameter |= VEHPARS_ROUTE_SET; // !!! needed?
223  ret->routeid = attrs.get<std::string>(SUMO_ATTR_ROUTE, ret->id.c_str(), ok);
224  }
225  // parse type information
226  if (attrs.hasAttribute(SUMO_ATTR_TYPE)) {
227  ret->setParameter |= VEHPARS_VTYPE_SET; // !!! needed?
228  ret->vtypeid = attrs.get<std::string>(SUMO_ATTR_TYPE, ret->id.c_str(), ok);
229  }
230  // parse line information
231  if (attrs.hasAttribute(SUMO_ATTR_LINE)) {
232  ret->setParameter |= VEHPARS_LINE_SET; // !!! needed?
233  ret->line = attrs.get<std::string>(SUMO_ATTR_LINE, ret->id.c_str(), ok);
234  }
235  // parse zone information
236  if (attrs.hasAttribute(SUMO_ATTR_FROM_TAZ)) {
238  ret->fromTaz = attrs.get<std::string>(SUMO_ATTR_FROM_TAZ, ret->id.c_str(), ok);
239  }
240  if (attrs.hasAttribute(SUMO_ATTR_TO_TAZ)) {
242  ret->toTaz = attrs.get<std::string>(SUMO_ATTR_TO_TAZ, ret->id.c_str(), ok);
243  }
244  // parse reroute information
245  if (attrs.getOpt<bool>(SUMO_ATTR_REROUTE, 0, ok, false)) {
247  }
248 
249  std::string error;
250  // parse depart lane information
251  if (attrs.hasAttribute(SUMO_ATTR_DEPARTLANE)) {
253  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTLANE, ret->id.c_str(), ok);
254  if (!SUMOVehicleParameter::parseDepartLane(helper, element, ret->id, ret->departLane, ret->departLaneProcedure, error)) {
255  throw ProcessError(error);
256  }
257  }
258  // parse depart position information
259  if (attrs.hasAttribute(SUMO_ATTR_DEPARTPOS)) {
261  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTPOS, ret->id.c_str(), ok);
262  if (!SUMOVehicleParameter::parseDepartPos(helper, element, ret->id, ret->departPos, ret->departPosProcedure, error)) {
263  throw ProcessError(error);
264  }
265  }
266  // parse lateral depart position information
269  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTPOS_LAT, ret->id.c_str(), ok);
270  if (!SUMOVehicleParameter::parseDepartPosLat(helper, element, ret->id, ret->departPosLat, ret->departPosLatProcedure, error)) {
271  throw ProcessError(error);
272  }
273  }
274  // parse depart speed information
275  if (attrs.hasAttribute(SUMO_ATTR_DEPARTSPEED)) {
277  std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTSPEED, ret->id.c_str(), ok);
278  if (!SUMOVehicleParameter::parseDepartSpeed(helper, element, ret->id, ret->departSpeed, ret->departSpeedProcedure, error)) {
279  throw ProcessError(error);
280  }
281  }
282 
283  // parse arrival lane information
284  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALLANE)) {
286  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALLANE, ret->id.c_str(), ok);
287  if (!SUMOVehicleParameter::parseArrivalLane(helper, element, ret->id, ret->arrivalLane, ret->arrivalLaneProcedure, error)) {
288  throw ProcessError(error);
289  }
290  }
291  // parse arrival position information
292  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
294  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, ret->id.c_str(), ok);
295  if (!SUMOVehicleParameter::parseArrivalPos(helper, element, ret->id, ret->arrivalPos, ret->arrivalPosProcedure, error)) {
296  throw ProcessError(error);
297  }
298  }
299  // parse lateral arrival position information
302  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS_LAT, ret->id.c_str(), ok);
303  if (!SUMOVehicleParameter::parseArrivalPosLat(helper, element, ret->id, ret->arrivalPosLat, ret->arrivalPosLatProcedure, error)) {
304  throw ProcessError(error);
305  }
306  }
307  // parse arrival speed information
310  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALSPEED, ret->id.c_str(), ok);
311  if (!SUMOVehicleParameter::parseArrivalSpeed(helper, element, ret->id, ret->arrivalSpeed, ret->arrivalSpeedProcedure, error)) {
312  throw ProcessError(error);
313  }
314  }
315 
316  // parse color
317  if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
319  ret->color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, ret->id.c_str(), ok);
320  } else {
322  }
323  // parse person number
326  ret->personNumber = attrs.get<int>(SUMO_ATTR_PERSON_NUMBER, ret->id.c_str(), ok);
327  }
328  // parse container number
331  ret->containerNumber = attrs.get<int>(SUMO_ATTR_CONTAINER_NUMBER, ret->id.c_str(), ok);
332  }
333 }
334 
335 
337 SUMOVehicleParserHelper::beginVTypeParsing(const SUMOSAXAttributes& attrs, const std::string& file) {
338  bool ok = true;
339  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
341  if (attrs.hasAttribute(SUMO_ATTR_VCLASS)) {
342  vClass = parseVehicleClass(attrs, id);
343  }
344  SUMOVTypeParameter* vtype = new SUMOVTypeParameter(id, vClass);
345  if (attrs.hasAttribute(SUMO_ATTR_VCLASS)) {
347  }
348  if (attrs.hasAttribute(SUMO_ATTR_LENGTH)) {
349  vtype->length = attrs.get<double>(SUMO_ATTR_LENGTH, vtype->id.c_str(), ok);
351  }
352  if (attrs.hasAttribute(SUMO_ATTR_MINGAP)) {
353  vtype->minGap = attrs.get<double>(SUMO_ATTR_MINGAP, vtype->id.c_str(), ok);
355  }
356  if (attrs.hasAttribute(SUMO_ATTR_MAXSPEED)) {
357  vtype->maxSpeed = attrs.get<double>(SUMO_ATTR_MAXSPEED, vtype->id.c_str(), ok);
359  }
360  if (attrs.hasAttribute(SUMO_ATTR_SPEEDFACTOR)) {
361  vtype->speedFactor = Distribution_Parameterized(attrs.get<std::string>(SUMO_ATTR_SPEEDFACTOR, vtype->id.c_str(), ok));
363  }
364  if (attrs.hasAttribute(SUMO_ATTR_SPEEDDEV)) {
365  vtype->speedFactor.getParameter()[1] = attrs.get<double>(SUMO_ATTR_SPEEDDEV, vtype->id.c_str(), ok);
367  }
369  vtype->emissionClass = parseEmissionClass(attrs, vtype->id);
371  }
372  if (attrs.hasAttribute(SUMO_ATTR_IMPATIENCE)) {
373  if (attrs.get<std::string>(SUMO_ATTR_IMPATIENCE, vtype->id.c_str(), ok) == "off") {
375  } else {
376  vtype->impatience = attrs.get<double>(SUMO_ATTR_IMPATIENCE, vtype->id.c_str(), ok);
377  }
379  }
380  if (attrs.hasAttribute(SUMO_ATTR_WIDTH)) {
381  vtype->width = attrs.get<double>(SUMO_ATTR_WIDTH, vtype->id.c_str(), ok);
383  }
384  if (attrs.hasAttribute(SUMO_ATTR_HEIGHT)) {
385  vtype->height = attrs.get<double>(SUMO_ATTR_HEIGHT, vtype->id.c_str(), ok);
387  }
388  if (attrs.hasAttribute(SUMO_ATTR_GUISHAPE)) {
389  vtype->shape = parseGuiShape(attrs, vtype->id);
391  }
392  if (attrs.hasAttribute(SUMO_ATTR_OSGFILE)) {
393  vtype->osgFile = attrs.get<std::string>(SUMO_ATTR_OSGFILE, vtype->id.c_str(), ok);
395  }
396  if (attrs.hasAttribute(SUMO_ATTR_IMGFILE)) {
397  vtype->imgFile = attrs.get<std::string>(SUMO_ATTR_IMGFILE, vtype->id.c_str(), ok);
398  if (vtype->imgFile != "" && !FileHelpers::isAbsolute(vtype->imgFile)) {
400  }
402  }
403  if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
404  vtype->color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, vtype->id.c_str(), ok);
406  } else {
407  vtype->color = RGBColor::YELLOW;
408  }
409  if (attrs.hasAttribute(SUMO_ATTR_PROB)) {
410  vtype->defaultProbability = attrs.get<double>(SUMO_ATTR_PROB, vtype->id.c_str(), ok);
412  }
415  std::string lcmS = attrs.get<std::string>(SUMO_ATTR_LANE_CHANGE_MODEL, vtype->id.c_str(), ok);
416  if (lcmS == "JE2013") {
417  WRITE_WARNING("Lane change model 'JE2013' is deprecated. Using default model instead.");
418  lcmS = "default";
419  }
420  if (SUMOXMLDefinitions::LaneChangeModels.hasString(lcmS)) {
422  } else {
423  WRITE_ERROR("Unknown lane change model '" + lcmS + "' when parsing vtype '" + vtype->id + "'");
424  throw ProcessError();
425  }
426  }
428  const std::string cfmS = attrs.get<std::string>(SUMO_ATTR_CAR_FOLLOW_MODEL, vtype->id.c_str(), ok);
429  if (SUMOXMLDefinitions::CarFollowModels.hasString(cfmS)) {
432  } else {
433  WRITE_ERROR("Unknown car following model '" + cfmS + "' when parsing vtype '" + vtype->id + "'");
434  throw ProcessError();
435  }
436  }
438  vtype->personCapacity = attrs.get<int>(SUMO_ATTR_PERSON_CAPACITY, vtype->id.c_str(), ok);
440  }
442  vtype->containerCapacity = attrs.get<int>(SUMO_ATTR_CONTAINER_CAPACITY, vtype->id.c_str(), ok);
444  }
446  vtype->boardingDuration = attrs.getSUMOTimeReporting(SUMO_ATTR_BOARDING_DURATION, vtype->id.c_str(), ok);
448  }
450  vtype->loadingDuration = attrs.getSUMOTimeReporting(SUMO_ATTR_LOADING_DURATION, vtype->id.c_str(), ok);
452  }
454  vtype->maxSpeedLat = attrs.get<double>(SUMO_ATTR_MAXSPEED_LAT, vtype->id.c_str(), ok);
456  }
457  if (attrs.hasAttribute(SUMO_ATTR_MINGAP_LAT)) {
458  vtype->minGapLat = attrs.get<double>(SUMO_ATTR_MINGAP_LAT, vtype->id.c_str(), ok);
460  }
462  const std::string alignS = attrs.get<std::string>(SUMO_ATTR_LATALIGNMENT, vtype->id.c_str(), ok);
463  if (SUMOXMLDefinitions::LateralAlignments.hasString(alignS)) {
466  } else {
467  WRITE_ERROR("Unknown lateral alignment '" + alignS + "' when parsing vtype '" + vtype->id + "'");
468  throw ProcessError();
469  }
470  }
471  parseVTypeEmbedded(*vtype, vtype->cfModel, attrs, true);
472  parseLCParams(*vtype, vtype->lcModel, attrs);
473  if (!ok) {
474  delete vtype;
475  throw ProcessError();
476  }
477  return vtype;
478 }
479 
480 
481 void
483  int element, const SUMOSAXAttributes& attrs,
484  bool fromVType) {
485  const CFAttrMap& allowedAttrs = getAllowedCFModelAttrs();
486  CFAttrMap::const_iterator cf_it;
487  for (cf_it = allowedAttrs.begin(); cf_it != allowedAttrs.end(); cf_it++) {
488  if (cf_it->first == element) {
489  break;
490  }
491  }
492  if (cf_it == allowedAttrs.end()) {
493  if (SUMOXMLDefinitions::Tags.has(element)) {
494  WRITE_ERROR("Unknown cfmodel " + toString((SumoXMLTag)element) + " when parsing vtype '" + into.id + "'");
495  } else {
496  WRITE_ERROR("Unknown cfmodel when parsing vtype '" + into.id + "'");
497  }
498  throw ProcessError();
499  return;
500  }
501  if (!fromVType) {
502  into.cfModel = cf_it->first;
504  }
505  bool ok = true;
506  for (std::set<SumoXMLAttr>::const_iterator it = cf_it->second.begin(); it != cf_it->second.end(); it++) {
507  if (attrs.hasAttribute(*it)) {
508  into.cfParameter[*it] = attrs.get<std::string>(*it, into.id.c_str(), ok);
509  if (*it == SUMO_ATTR_TAU && string2time(into.cfParameter[*it]) < DELTA_T) {
510  WRITE_WARNING("Value of tau=" + toString(into.cfParameter[*it])
511  + " in car following model '" + toString(into.cfModel) + "' lower than simulation step size may cause collisions");
512  }
513  }
514  }
515  if (!ok) {
516  throw ProcessError();
517  }
518 }
519 
520 
523  // init on first use
524  if (allowedCFModelAttrs.size() == 0) {
525  std::set<SumoXMLAttr> krausParams;
526  krausParams.insert(SUMO_ATTR_ACCEL);
527  krausParams.insert(SUMO_ATTR_DECEL);
528  krausParams.insert(SUMO_ATTR_APPARENTDECEL);
529  krausParams.insert(SUMO_ATTR_EMERGENCYDECEL);
530  krausParams.insert(SUMO_ATTR_SIGMA);
531  krausParams.insert(SUMO_ATTR_TAU);
535 
542 
543  std::set<SumoXMLAttr> smartSKParams;
544  smartSKParams.insert(SUMO_ATTR_ACCEL);
545  smartSKParams.insert(SUMO_ATTR_DECEL);
546  smartSKParams.insert(SUMO_ATTR_EMERGENCYDECEL);
547  smartSKParams.insert(SUMO_ATTR_SIGMA);
548  smartSKParams.insert(SUMO_ATTR_TAU);
549  smartSKParams.insert(SUMO_ATTR_TMP1);
550  smartSKParams.insert(SUMO_ATTR_TMP2);
551  smartSKParams.insert(SUMO_ATTR_TMP3);
552  smartSKParams.insert(SUMO_ATTR_TMP4);
553  smartSKParams.insert(SUMO_ATTR_TMP5);
554  allowedCFModelAttrs[SUMO_TAG_CF_SMART_SK] = smartSKParams;
555 
556  std::set<SumoXMLAttr> daniel1Params;
557  daniel1Params.insert(SUMO_ATTR_ACCEL);
558  daniel1Params.insert(SUMO_ATTR_DECEL);
559  daniel1Params.insert(SUMO_ATTR_EMERGENCYDECEL);
560  daniel1Params.insert(SUMO_ATTR_SIGMA);
561  daniel1Params.insert(SUMO_ATTR_TAU);
562  daniel1Params.insert(SUMO_ATTR_TMP1);
563  daniel1Params.insert(SUMO_ATTR_TMP2);
564  daniel1Params.insert(SUMO_ATTR_TMP3);
565  daniel1Params.insert(SUMO_ATTR_TMP4);
566  daniel1Params.insert(SUMO_ATTR_TMP5);
567  allowedCFModelAttrs[SUMO_TAG_CF_DANIEL1] = daniel1Params;
568 
569  std::set<SumoXMLAttr> pwagParams;
570  pwagParams.insert(SUMO_ATTR_ACCEL);
571  pwagParams.insert(SUMO_ATTR_DECEL);
572  pwagParams.insert(SUMO_ATTR_EMERGENCYDECEL);
573  pwagParams.insert(SUMO_ATTR_SIGMA);
574  pwagParams.insert(SUMO_ATTR_TAU);
575  pwagParams.insert(SUMO_ATTR_CF_PWAGNER2009_TAULAST);
576  pwagParams.insert(SUMO_ATTR_CF_PWAGNER2009_APPROB);
578 
579  std::set<SumoXMLAttr> idmParams;
580  idmParams.insert(SUMO_ATTR_ACCEL);
581  idmParams.insert(SUMO_ATTR_DECEL);
582  idmParams.insert(SUMO_ATTR_EMERGENCYDECEL);
583  idmParams.insert(SUMO_ATTR_TAU);
584  idmParams.insert(SUMO_ATTR_CF_IDM_DELTA);
585  idmParams.insert(SUMO_ATTR_CF_IDM_STEPPING);
587 
588  std::set<SumoXMLAttr> idmmParams;
589  idmmParams.insert(SUMO_ATTR_ACCEL);
590  idmmParams.insert(SUMO_ATTR_DECEL);
591  idmmParams.insert(SUMO_ATTR_EMERGENCYDECEL);
592  idmmParams.insert(SUMO_ATTR_TAU);
593  idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_FACTOR);
594  idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_TIME);
595  idmmParams.insert(SUMO_ATTR_CF_IDM_STEPPING);
597 
598  std::set<SumoXMLAttr> bkernerParams;
599  bkernerParams.insert(SUMO_ATTR_ACCEL);
600  bkernerParams.insert(SUMO_ATTR_DECEL);
601  bkernerParams.insert(SUMO_ATTR_EMERGENCYDECEL);
602  bkernerParams.insert(SUMO_ATTR_TAU);
603  bkernerParams.insert(SUMO_ATTR_K);
604  bkernerParams.insert(SUMO_ATTR_CF_KERNER_PHI);
605  allowedCFModelAttrs[SUMO_TAG_CF_BKERNER] = bkernerParams;
606 
607  std::set<SumoXMLAttr> wiedemannParams;
608  wiedemannParams.insert(SUMO_ATTR_ACCEL);
609  wiedemannParams.insert(SUMO_ATTR_DECEL);
610  wiedemannParams.insert(SUMO_ATTR_EMERGENCYDECEL);
611  wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_SECURITY);
612  wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_ESTIMATION);
613  allowedCFModelAttrs[SUMO_TAG_CF_WIEDEMANN] = wiedemannParams;
614 
615  std::set<SumoXMLAttr> railParamms;
616  railParamms.insert(SUMO_ATTR_TRAIN_TYPE);
617  allowedCFModelAttrs[SUMO_TAG_CF_RAIL] = railParamms;
618  }
619  return allowedCFModelAttrs;
620 }
621 
622 
623 void
625  if (allowedLCModelAttrs.size() == 0) {
626  // init static map
627  std::set<SumoXMLAttr> lc2013Params;
628  lc2013Params.insert(SUMO_ATTR_LCA_STRATEGIC_PARAM);
629  lc2013Params.insert(SUMO_ATTR_LCA_COOPERATIVE_PARAM);
630  lc2013Params.insert(SUMO_ATTR_LCA_SPEEDGAIN_PARAM);
631  lc2013Params.insert(SUMO_ATTR_LCA_KEEPRIGHT_PARAM);
632  lc2013Params.insert(SUMO_ATTR_LCA_EXPERIMENTAL1);
633  allowedLCModelAttrs[LCM_LC2013] = lc2013Params;
634 
635  std::set<SumoXMLAttr> sl2015Params = lc2013Params;
636  sl2015Params.insert(SUMO_ATTR_LCA_PUSHY);
637  sl2015Params.insert(SUMO_ATTR_LCA_SUBLANE_PARAM);
638  sl2015Params.insert(SUMO_ATTR_LCA_ASSERTIVE);
639  allowedLCModelAttrs[LCM_SL2015] = sl2015Params;
640 
641  std::set<SumoXMLAttr> noParams;
642  allowedLCModelAttrs[LCM_DK2008] = noParams;
643 
644  // default model may be either LC2013 or SL2013
645  // we allow both sets (sl2015 is a superset of lc2013Params)
646  allowedLCModelAttrs[LCM_DEFAULT] = sl2015Params;
647  }
648  bool ok = true;
649  std::set<SumoXMLAttr> allowed = allowedLCModelAttrs[model];
650  for (std::set<SumoXMLAttr>::const_iterator it = allowed.begin(); it != allowed.end(); it++) {
651  if (attrs.hasAttribute(*it)) {
652  into.lcParameter[*it] = attrs.get<std::string>(*it, into.id.c_str(), ok);
653  }
654  }
655  if (!ok) {
656  throw ProcessError();
657  }
658 }
659 
660 
663  const std::string& id) {
665  try {
666  bool ok = true;
667  std::string vclassS = attrs.getOpt<std::string>(SUMO_ATTR_VCLASS, id.c_str(), ok, "");
668  if (vclassS == "") {
669  return vclass;
670  }
671  const SUMOVehicleClass result = getVehicleClassID(vclassS);
672  const std::string& realName = SumoVehicleClassStrings.getString(result);
673  if (realName != vclassS) {
674  WRITE_WARNING("The vehicle class '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is deprecated, use '" + realName + "' instead.");
675  }
676  return result;
677  } catch (...) {
678  WRITE_ERROR("The class for " + attrs.getObjectType() + " '" + id + "' is not known.");
679  }
680  return vclass;
681 }
682 
683 
686  try {
687  bool ok = true;
688  std::string eClassS = attrs.getOpt<std::string>(SUMO_ATTR_EMISSIONCLASS, id.c_str(), ok, "");
689  return PollutantsInterface::getClassByName(eClassS);
690  } catch (...) {
691  WRITE_ERROR("The emission class for " + attrs.getObjectType() + " '" + id + "' is not known.");
692  return 0;
693  }
694 }
695 
696 
698 SUMOVehicleParserHelper::parseGuiShape(const SUMOSAXAttributes& attrs, const std::string& id) {
699  bool ok = true;
700  std::string vclassS = attrs.getOpt<std::string>(SUMO_ATTR_GUISHAPE, id.c_str(), ok, "");
701  if (SumoVehicleShapeStrings.hasString(vclassS)) {
702  const SUMOVehicleShape result = SumoVehicleShapeStrings.get(vclassS);
703  const std::string& realName = SumoVehicleShapeStrings.getString(result);
704  if (realName != vclassS) {
705  WRITE_WARNING("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is deprecated, use '" + realName + "' instead.");
706  }
707  return result;
708  } else {
709  WRITE_ERROR("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is not known.");
710  return SVS_UNKNOWN;
711  }
712 }
713 
714 /****************************************************************************/
715 
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
const int VEHPARS_FORCE_REROUTE
static std::string getConfigurationRelative(const std::string &configPath, const std::string &path)
Returns the second path as a relative path to the first file.
Definition: FileHelpers.cpp:82
static bool parseArrivalPosLat(const std::string &val, const std::string &element, const std::string &id, double &pos, ArrivalPosLatDefinition &apd, std::string &error)
Validates a given arrivalPosLat value.
double impatience
The vehicle&#39;s impatience (willingness to obstruct others)
std::string vtypeid
The vehicle&#39;s type id.
static 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.
const int VTYPEPARS_MINGAP_LAT_SET
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
double defaultProbability
The probability when being added to a distribution without an explicit probability.
std::vector< double > & getParameter()
Returns the parameters of this distribution.
static SUMOVehicleParameter * parseVehicleAttributes(const SUMOSAXAttributes &attrs, const bool optionalID=false, const bool skipDepart=false, const bool isPerson=false)
Parses a vehicle&#39;s attributes.
int containerCapacity
The container capacity of the vehicle.
const int VTYPEPARS_BOARDING_DURATION
ArrivalPosLatDefinition arrivalPosLatProcedure
Information how the vehicle shall choose the lateral arrival position.
weights: time range begin
double arrivalPosLat
(optional) The lateral position the vehicle shall arrive on
SUMOTime DELTA_T
Definition: SUMOTime.cpp:40
const int VEHPARS_ARRIVALLANE_SET
const std::string & getObjectType() const
return the objecttype to which these attributes belong
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
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
SUMOTime getSUMOTimeReporting(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
#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.
double height
This class&#39; height.
std::string toTaz
The vehicle&#39;s destination zone (district)
const int VTYPEPARS_LANE_CHANGE_MODEL_SET
const int VEHPARS_ARRIVALSPEED_SET
double departSpeed
(optional) The initial speed of the vehicle
static const CFAttrMap & getAllowedCFModelAttrs()
LaneChangeModel
#define max(a, b)
Definition: polyfonts.c:65
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle&#39;s initial speed shall be chosen.
double maxSpeed
The vehicle type&#39;s maximum speed [m/s].
double width
This class&#39; width.
SUMOTime boardingDuration
The time a person needs to board the vehicle.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
std::string routeid
The vehicle&#39;s route id.
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
Encapsulated SAX-Attributes.
static SUMOVehicleParameter * parseFlowAttributes(const SUMOSAXAttributes &attrs, const SUMOTime beginDefault, const SUMOTime endDefault)
Parses a flow&#39;s attributes.
const int VEHPARS_DEPARTSPEED_SET
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
static bool isAbsolute(const std::string &path)
Returns the information whether the given path is absolute.
Definition: FileHelpers.cpp:97
std::string osgFile
3D model file for this class
#define SUMOTime_MAX
Definition: TraCIDefs.h:53
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
T get(const std::string &str) const
int arrivalLane
(optional) The lane the vehicle shall arrive on (not used yet)
std::string imgFile
Image file for this class.
const int VEHPARS_DEPARTPOSLAT_SET
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:47
const int VEHPARS_ROUTE_SET
std::string fromTaz
The vehicle&#39;s origin zone (district)
static bool parseArrivalLane(const std::string &val, const std::string &element, const std::string &id, int &lane, ArrivalLaneDefinition &ald, std::string &error)
Validates a given arrivalLane value.
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
const int VTYPEPARS_LOADING_DURATION
const int VTYPEPARS_CONTAINER_CAPACITY
const int VEHPARS_COLOR_SET
int personNumber
The static number of persons in the vehicle when it departs (not including boarding persons) ...
vehicle is a passenger car (a "normal" car)
const int VEHPARS_FROM_TAZ_SET
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
std::string line
The vehicle&#39;s line (mainly for public transport)
const int VTYPEPARS_SPEEDFACTOR_SET
double arrivalPos
(optional) The position the vehicle shall arrive on
double maxSpeedLat
The vehicle type&#39;s maximum lateral speed [m/s].
const int VEHPARS_ARRIVALPOSLAT_SET
double departPosLat
(optional) The lateral position the vehicle shall depart from
const int VEHPARS_LINE_SET
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
const int VEHPARS_ARRIVALPOS_SET
int personCapacity
The person capacity of the vehicle.
int setParameter
Information for the router which parameter were set.
static StringBijection< LateralAlignment > LateralAlignments
lateral alignments
double departPos
(optional) The position the vehicle shall depart from
double minGapLat
The vehicle type&#39;s minimum lateral gap [m].
static const RGBColor YELLOW
Definition: RGBColor.h:192
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.
Structure representing possible vehicle parameter.
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
const int VEHPARS_PERIODFREQ_SET
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
const std::string DEFAULT_PEDTYPE_ID
int setParameter
Information for the router which parameter were set, TraCI may modify this (whe changing color) ...
static bool parseDepartPos(const std::string &val, const std::string &element, const std::string &id, double &pos, DepartPosDefinition &dpd, std::string &error)
Validates a given departPos value.
weights: time range end
const int VTYPEPARS_IMGFILE_SET
static bool parseDepartPosLat(const std::string &val, const std::string &element, const std::string &id, double &pos, DepartPosLatDefinition &dpd, std::string &error)
Validates a given departPosLat value.
static bool parseArrivalSpeed(const std::string &val, const std::string &element, const std::string &id, double &speed, ArrivalSpeedDefinition &asd, std::string &error)
Validates a given arrivalSpeed value.
SubParams cfParameter
Car-following parameter.
SUMOTime loadingDuration
The time a container needs to get loaded on the vehicle.
RGBColor color
The color.
const int VEHPARS_DEPARTLANE_SET
static bool parseArrivalPos(const std::string &val, const std::string &element, const std::string &id, double &pos, ArrivalPosDefinition &apd, std::string &error)
Validates a given arrivalPos value.
int containerNumber
The static number of containers in the vehicle when it departs.
std::string id
The vehicle type&#39;s id.
static bool parseDepartSpeed(const std::string &val, const std::string &element, const std::string &id, double &speed, DepartSpeedDefinition &dsd, std::string &error)
Validates a given departSpeed value.
const int VTYPEPARS_PERSON_CAPACITY
LateralAlignment latAlignment
The vehicles desired lateral alignment.
const int VEHPARS_VTYPE_SET
double minGap
This class&#39; free space in front of the vehicle itself.
const int VTYPEPARS_HEIGHT_SET
static SUMOEmissionClass parseEmissionClass(const SUMOSAXAttributes &attrs, const std::string &id)
Parses the vehicle emission class.
long long int SUMOTime
Definition: TraCIDefs.h:52
double arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
const int VTYPEPARS_WIDTH_SET
static StringBijection< int > Tags
The names of SUMO-XML elements for use in netbuild.
const int VEHPARS_DEPARTPOS_SET
const int VEHPARS_PERSON_NUMBER_SET
LaneChangeModel lcModel
The lane-change model to use.
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
Distribution_Parameterized speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street...
const int VTYPEPARS_SHAPE_SET
double length
The physical vehicle length.
SubParams lcParameter
Lane-changing parameter.
static StringBijection< LaneChangeModel > LaneChangeModels
lane change models
static bool parseDepart(const std::string &val, const std::string &element, const std::string &id, SUMOTime &depart, DepartDefinition &dd, std::string &error)
Validates a given depart value.
SUMOEmissionClass emissionClass
The emission class of this vehicle.
vehicles ignoring classes
std::map< LaneChangeModel, std::set< SumoXMLAttr > > LCAttrMap
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
std::string id
The vehicle&#39;s id.
const int VTYPEPARS_IMPATIENCE_SET
static bool parseDepartLane(const std::string &val, const std::string &element, const std::string &id, int &lane, DepartLaneDefinition &dld, std::string &error)
Validates a given departLane value.
DepartPosLatDefinition departPosLatProcedure
Information how the vehicle shall choose the lateral departure position.