Eclipse SUMO - Simulation of Urban MObility
SUMOVehicleParserHelper.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2008-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
22 // Helper methods for parsing vehicle attributes
23 /****************************************************************************/
24 #include <config.h>
25 
31 #include <utils/common/ToString.h>
37 
39 
40 
41 // ===========================================================================
42 // static members
43 // ===========================================================================
44 
47 std::set<SumoXMLAttr> SUMOVehicleParserHelper::allowedJMAttrs;
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
53 
55 SUMOVehicleParserHelper::parseFlowAttributes(SumoXMLTag tag, const SUMOSAXAttributes& attrs, const bool hardFail, const SUMOTime beginDefault, const SUMOTime endDefault, bool isPerson) {
56  bool ok = true;
57  bool abortCreation = true;
58  // first parse ID
59  std::string id = parseID(attrs, SUMO_TAG_FLOW);
60  // check if ID is valid
61  if (!id.empty()) {
63  return handleError(hardFail, abortCreation, "Invalid flow id '" + id + "'.");
64  }
65  // declare flags
66  const bool hasPeriod = attrs.hasAttribute(SUMO_ATTR_PERIOD);
67  const bool hasVPH = attrs.hasAttribute(SUMO_ATTR_VEHSPERHOUR);
68  const bool hasPPH = attrs.hasAttribute(SUMO_ATTR_PERSONSPERHOUR);
69  const bool hasXPH = hasVPH || hasPPH;
70  const bool hasProb = attrs.hasAttribute(SUMO_ATTR_PROB);
71  const bool hasNumber = attrs.hasAttribute(SUMO_ATTR_NUMBER);
72  const bool hasBegin = attrs.hasAttribute(SUMO_ATTR_BEGIN);
73  const bool hasEnd = attrs.hasAttribute(SUMO_ATTR_END);
74  if (hasPeriod && hasXPH) {
75  return handleError(hardFail, abortCreation,
76  "At most one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
77  "' and '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
78  "' has to be given in the definition of flow '" + id + "'.");
79  }
80  if (hasPeriod && hasProb) {
81  return handleError(hardFail, abortCreation,
82  "At most one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
83  "' and '" + attrs.getName(SUMO_ATTR_PROB) +
84  "' has to be given in the definition of flow '" + id + "'.");
85  }
86  if (hasProb && hasXPH) {
87  return handleError(hardFail, abortCreation,
88  "At most one of '" + attrs.getName(SUMO_ATTR_PROB) +
89  "' and '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
90  "' has to be given in the definition of flow '" + id + "'.");
91  }
92  if (hasPeriod || hasXPH || hasProb) {
93  if (hasEnd && hasNumber) {
94  return handleError(hardFail, abortCreation,
95  "If '" + attrs.getName(SUMO_ATTR_PERIOD) +
96  "', '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
97  "' or '" + attrs.getName(SUMO_ATTR_PROB) +
98  "' are given at most one of '" + attrs.getName(SUMO_ATTR_END) +
99  "' and '" + attrs.getName(SUMO_ATTR_NUMBER) +
100  "' are allowed in flow '" + id + "'.");
101  }
102  } else {
103  if (!hasNumber) {
104  return handleError(hardFail, abortCreation,
105  "At least one of '" + attrs.getName(SUMO_ATTR_PERIOD) +
106  "', '" + attrs.getName(SUMO_ATTR_VEHSPERHOUR) +
107  "', '" + attrs.getName(SUMO_ATTR_PROB) +
108  "', and '" + attrs.getName(SUMO_ATTR_NUMBER) +
109  "' is needed in flow '" + id + "'.");
110  }
111  }
113  // set tag
114  ret->tag = tag;
115  // set id
116  ret->id = id;
117  if (isPerson) {
119  }
120  try {
121  parseCommonAttributes(attrs, hardFail, ret, "flow");
122  } catch (ProcessError&) {
123  delete ret;
124  throw;
125  }
126  // parse repetition information
127  if (hasPeriod) {
129  ret->repetitionOffset = attrs.getSUMOTimeReporting(SUMO_ATTR_PERIOD, id.c_str(), ok);
130  }
131  if (hasXPH) {
133  const double vph = attrs.get<double>(hasVPH ? SUMO_ATTR_VEHSPERHOUR : SUMO_ATTR_PERSONSPERHOUR, id.c_str(), ok);
134  if (ok && vph <= 0) {
135  delete ret;
136  return handleError(hardFail, abortCreation,
137  "Invalid repetition rate in the definition of "
138  + std::string(hasVPH ? "flow" : "personFlow") + " '" + id + "'.");
139  }
140  if (ok && vph != 0) {
141  ret->repetitionOffset = TIME2STEPS(3600. / vph);
142  }
143  }
144  if (hasProb) {
146  ret->repetitionProbability = attrs.get<double>(SUMO_ATTR_PROB, id.c_str(), ok);
147  if (ok && (ret->repetitionProbability <= 0 || ret->repetitionProbability > 1)) {
148  delete ret;
149  return handleError(hardFail, abortCreation, "Invalid repetition probability in the definition of flow '" + id + "'.");
150  }
151  }
152  ret->depart = beginDefault;
153  if (hasBegin) {
154  ret->depart = attrs.getSUMOTimeReporting(SUMO_ATTR_BEGIN, id.c_str(), ok);
155  }
156  if (ok && ret->depart < 0) {
157  delete ret;
158  return handleError(hardFail, abortCreation, "Negative begin time in the definition of flow '" + id + "'.");
159  }
160  ret->repetitionEnd = endDefault;
161  if (ret->repetitionEnd < 0) {
163  }
164  if (hasEnd) {
165  ret->repetitionEnd = attrs.getSUMOTimeReporting(SUMO_ATTR_END, id.c_str(), ok);
167  } else if ((endDefault >= TIME2STEPS(9223372036854773) || endDefault < 0)
168  // see SUMOTIME_MAXSTRING (which differs slightly from SUMOTime_MAX)
169  && (!hasNumber || (!hasProb && !hasPeriod && !hasXPH))) {
170  WRITE_WARNING("Undefined end for flow '" + id + "', defaulting to 24hour duration.");
171  ret->repetitionEnd = ret->depart + TIME2STEPS(24 * 3600);
172  }
173  if (ok && ret->repetitionEnd < ret->depart) {
174  delete ret;
175  return handleError(hardFail, abortCreation, "Flow '" + id + "' ends before its begin time.");
176  }
177  if (hasNumber) {
178  ret->repetitionNumber = attrs.get<int>(SUMO_ATTR_NUMBER, id.c_str(), ok);
180  if (ret->repetitionNumber == 0) {
181  WRITE_WARNING("Flow '" + id + "' has 0 vehicles; will skip it.");
182  } else {
183  if (ok && ret->repetitionNumber < 0) {
184  delete ret;
185  return handleError(hardFail, abortCreation, "Negative repetition number in the definition of flow '" + id + "'.");
186  }
187  if (ok && ret->repetitionOffset < 0) {
188  ret->repetitionOffset = (ret->repetitionEnd - ret->depart) / ret->repetitionNumber;
189  }
190  }
191  ret->repetitionEnd = ret->depart + ret->repetitionNumber * ret->repetitionOffset;
192  } else {
193  // interpret repetitionNumber
194  if (ok && ret->repetitionProbability > 0) {
195  ret->repetitionNumber = std::numeric_limits<int>::max();
196  } else {
197  if (ok && ret->repetitionOffset <= 0) {
198  delete ret;
199  return handleError(hardFail, abortCreation, "Invalid repetition rate in the definition of flow '" + id + "'.");
200  }
201  if (ret->repetitionEnd == SUMOTime_MAX) {
202  ret->repetitionNumber = std::numeric_limits<int>::max();
203  } else {
204  const double repLength = (double)(ret->repetitionEnd - ret->depart);
205  ret->repetitionNumber = (int)ceil(repLength / ret->repetitionOffset);
206  }
207  }
208  }
209  if (!ok) {
210  delete ret;
211  return handleError(hardFail, abortCreation, "Flow cannot be created");
212  }
213  return ret;
214  } else {
215  if (hardFail) {
216  throw ProcessError("Flow cannot be created");
217  } else {
218  return nullptr;
219  }
220  }
221 }
222 
223 
225 SUMOVehicleParserHelper::parseVehicleAttributes(int element, const SUMOSAXAttributes& attrs, const bool hardFail, const bool optionalID, const bool skipDepart) {
226  bool ok = true;
227  std::string id, errorMsg;
228  // for certain vehicles, ID can be optional
229  if (optionalID) {
230  id = attrs.getOpt<std::string>(SUMO_ATTR_ID, nullptr, ok, "");
231  } else {
232  // parse ID
233  id = parseID(attrs, (SumoXMLTag)element);
234  }
235  // only continue if id is valid, or if is optional
236  if (optionalID || !id.empty()) {
238  ret->id = id;
239  if (element == SUMO_TAG_PERSON) {
241  } else if (element == SUMO_TAG_CONTAINER) {
243  }
244  try {
245  parseCommonAttributes(attrs, hardFail, ret, "vehicle");
246  if (!skipDepart) {
247  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPART, ret->id.c_str(), ok);
248  if (!ok || !SUMOVehicleParameter::parseDepart(helper, "vehicle", ret->id, ret->depart, ret->departProcedure, errorMsg)) {
249  throw ProcessError(errorMsg);
250  }
251  }
252  } catch (ProcessError&) {
253  delete ret;
254  if (hardFail) {
255  throw;
256  } else {
257  WRITE_ERROR(errorMsg);
258  return nullptr;
259  }
260  }
261  // set tag
262  ret->tag = (SumoXMLTag)element;
263  return ret;
264  } else {
265  std::string error = toString((SumoXMLTag)element) + " cannot be created";
266  if (hardFail) {
267  throw ProcessError(error);
268  } else {
269  WRITE_ERROR(error);
270  return nullptr;
271  }
272  }
273 }
274 
275 std::string
277  bool ok = true;
278  std::string id;
279  // first check if attrs contain an ID
280  if (attrs.hasAttribute(SUMO_ATTR_ID)) {
281  id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
283  return id;
284  } else if (id.empty()) {
285  // add extra information for empty IDs
286  WRITE_ERROR("Invalid " + toString(element) + " id '" + id + "'.");
287  } else {
288  WRITE_ERROR("Invalid " + toString(element) + " id '" + id + "'. Contains invalid characters.");
289  }
290  } else {
291  WRITE_ERROR("Attribute '" + toString(SUMO_ATTR_ID) + "' is missing in definition of " + toString(element));
292  }
293  // return empty (invalid) ID
294  return "";
295 }
296 
297 
298 void
299 SUMOVehicleParserHelper::parseCommonAttributes(const SUMOSAXAttributes& attrs, const bool hardFail, SUMOVehicleParameter* ret, std::string element) {
300  //ret->refid = attrs.getStringSecure(SUMO_ATTR_REFID, "");
301  bool ok = true;
302  bool abortCreation = true;
303  // parse route information
304  if (attrs.hasAttribute(SUMO_ATTR_ROUTE)) {
305  ret->parametersSet |= VEHPARS_ROUTE_SET; // !!! needed?
306  ret->routeid = attrs.get<std::string>(SUMO_ATTR_ROUTE, ret->id.c_str(), ok);
307  }
308  // parse type information
309  if (attrs.hasAttribute(SUMO_ATTR_TYPE)) {
310  ret->parametersSet |= VEHPARS_VTYPE_SET; // !!! needed?
311  ret->vtypeid = attrs.get<std::string>(SUMO_ATTR_TYPE, ret->id.c_str(), ok);
312  }
313  // parse line information
314  if (attrs.hasAttribute(SUMO_ATTR_LINE)) {
315  ret->parametersSet |= VEHPARS_LINE_SET; // !!! needed?
316  ret->line = attrs.get<std::string>(SUMO_ATTR_LINE, ret->id.c_str(), ok);
317  }
318  // parse zone information
319  if (attrs.hasAttribute(SUMO_ATTR_FROM_TAZ)) {
321  ret->fromTaz = attrs.get<std::string>(SUMO_ATTR_FROM_TAZ, ret->id.c_str(), ok);
322  }
323  if (attrs.hasAttribute(SUMO_ATTR_TO_TAZ)) {
325  ret->toTaz = attrs.get<std::string>(SUMO_ATTR_TO_TAZ, ret->id.c_str(), ok);
326  }
327  // parse reroute information
328  if (attrs.getOpt<bool>(SUMO_ATTR_REROUTE, nullptr, ok, false)) {
330  }
331 
332  std::string error;
333  // parse depart lane information
334  if (attrs.hasAttribute(SUMO_ATTR_DEPARTLANE)) {
335  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTLANE, ret->id.c_str(), ok);
336  int lane;
338  if (SUMOVehicleParameter::parseDepartLane(helper, element, ret->id, lane, dld, error)) {
340  ret->departLane = lane;
341  ret->departLaneProcedure = dld;
342  } else {
343  handleError(hardFail, abortCreation, error);
344  }
345  }
346  // parse depart position information
347  if (attrs.hasAttribute(SUMO_ATTR_DEPARTPOS)) {
348  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTPOS, ret->id.c_str(), ok);
349  double pos;
351  if (SUMOVehicleParameter::parseDepartPos(helper, element, ret->id, pos, dpd, error)) {
353  ret->departPos = pos;
354  ret->departPosProcedure = dpd;
355  } else {
356  handleError(hardFail, abortCreation, error);
357  }
358  }
359  // parse lateral depart position information
361  const std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTPOS_LAT, ret->id.c_str(), ok);
362  double pos;
364  if (SUMOVehicleParameter::parseDepartPosLat(helper, element, ret->id, pos, dpd, error)) {
366  ret->departPosLat = pos;
367  ret->departPosLatProcedure = dpd;
368  } else {
369  handleError(hardFail, abortCreation, error);
370  }
371  }
372  // parse depart speed information
373  if (attrs.hasAttribute(SUMO_ATTR_DEPARTSPEED)) {
374  std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTSPEED, ret->id.c_str(), ok);
375  double speed;
377  if (SUMOVehicleParameter::parseDepartSpeed(helper, element, ret->id, speed, dsd, error)) {
379  ret->departSpeed = speed;
380  ret->departSpeedProcedure = dsd;
381  } else {
382  handleError(hardFail, abortCreation, error);
383  }
384  }
385  // parse depart edge information
386  if (attrs.hasAttribute(SUMO_ATTR_DEPARTEDGE)) {
387  std::string helper = attrs.get<std::string>(SUMO_ATTR_DEPARTEDGE, ret->id.c_str(), ok);
388  int edgeIndex;
390  if (SUMOVehicleParameter::parseDepartEdge(helper, element, ret->id, edgeIndex, ded, error)) {
392  ret->departEdge = edgeIndex;
393  ret->departEdgeProcedure = ded;
394  } else {
395  handleError(hardFail, abortCreation, error);
396  }
397  }
398  // parse arrival lane information
399  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALLANE)) {
400  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALLANE, ret->id.c_str(), ok);
401  int lane;
403  if (SUMOVehicleParameter::parseArrivalLane(helper, element, ret->id, lane, ald, error)) {
405  ret->arrivalLane = lane;
406  ret->arrivalLaneProcedure = ald;
407  } else {
408  handleError(hardFail, abortCreation, error);
409  }
410  }
411  // parse arrival position information
412  if (attrs.hasAttribute(SUMO_ATTR_ARRIVALPOS)) {
413  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS, ret->id.c_str(), ok);
414  double pos;
416  if (SUMOVehicleParameter::parseArrivalPos(helper, element, ret->id, pos, apd, error)) {
418  ret->arrivalPos = pos;
419  ret->arrivalPosProcedure = apd;
420  } else {
421  handleError(hardFail, abortCreation, error);
422  }
423  }
424  // parse lateral arrival position information
426  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALPOS_LAT, ret->id.c_str(), ok);
427  double pos;
429  if (SUMOVehicleParameter::parseArrivalPosLat(helper, element, ret->id, pos, apd, error)) {
431  ret->arrivalPosLat = pos;
432  ret->arrivalPosLatProcedure = apd;
433  } else {
434  handleError(hardFail, abortCreation, error);
435  }
436  }
437  // parse arrival speed information
439  std::string helper = attrs.get<std::string>(SUMO_ATTR_ARRIVALSPEED, ret->id.c_str(), ok);
440  double speed;
442  if (SUMOVehicleParameter::parseArrivalSpeed(helper, element, ret->id, speed, asd, error)) {
444  ret->arrivalSpeed = speed;
445  ret->arrivalSpeedProcedure = asd;
446  } else {
447  handleError(hardFail, abortCreation, error);
448  }
449  }
450  // parse color
451  if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
453  ret->color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, ret->id.c_str(), ok);
454  } else {
456  }
457  // parse person number
459  int personNumber = attrs.get<int>(SUMO_ATTR_PERSON_NUMBER, ret->id.c_str(), ok);
460  if (personNumber >= 0) {
462  ret->personNumber = personNumber;
463  } else {
464  handleError(hardFail, abortCreation, toString(SUMO_ATTR_PERSON_NUMBER) + " cannot be negative");
465  }
466  }
467  // parse container number
469  int containerNumber = attrs.get<int>(SUMO_ATTR_CONTAINER_NUMBER, ret->id.c_str(), ok);
470  if (containerNumber >= 0) {
472  ret->containerNumber = containerNumber;
473  } else {
474  handleError(hardFail, abortCreation, toString(SUMO_ATTR_CONTAINER_NUMBER) + " cannot be negative");
475  }
476  }
477  // parse individual speedFactor
478  if (attrs.hasAttribute(SUMO_ATTR_SPEEDFACTOR)) {
479  double speedFactor = attrs.get<double>(SUMO_ATTR_SPEEDFACTOR, ret->id.c_str(), ok);
480  if (speedFactor > 0) {
482  ret->speedFactor = speedFactor;
483  } else {
484  handleError(hardFail, abortCreation, toString(SUMO_ATTR_SPEEDFACTOR) + " must be positive");
485  }
486  }
487  /*/ parse via
488  if (attrs.hasAttribute(SUMO_ATTR_VIA)) {
489  ret->setParameter |= VEHPARS_VIA_SET;
490  SUMOSAXAttributes::parseStringVector(attrs.get<std::string>(SUMO_ATTR_VIA, ret->id.c_str(), ok), ret->via);
491  }
492  */
493 }
494 
495 
497 SUMOVehicleParserHelper::beginVTypeParsing(const SUMOSAXAttributes& attrs, const bool hardFail, const std::string& file) {
498  bool abortCreation = true;
499  // first obtain ID
500  std::string id = parseID(attrs, SUMO_TAG_VTYPE);
501  // check if ID is valid
502  if (!id.empty()) {
504  if (attrs.hasAttribute(SUMO_ATTR_VCLASS)) {
505  vClass = parseVehicleClass(attrs, id);
506  }
507  SUMOVTypeParameter* vtype = new SUMOVTypeParameter(id, vClass);
508  try {
509  if (attrs.hasAttribute(SUMO_ATTR_VCLASS)) {
511  }
512  if (attrs.hasAttribute(SUMO_ATTR_LENGTH)) {
513  bool ok = true;
514  double length = attrs.get<double>(SUMO_ATTR_LENGTH, vtype->id.c_str(), ok);
515  if (ok) {
516  if (length <= 0) {
517  handleError(hardFail, abortCreation, toString(SUMO_ATTR_LENGTH) + " must be greater than 0");
518  } else {
519  vtype->length = length;
521  }
522  }
523  }
524  if (attrs.hasAttribute(SUMO_ATTR_MINGAP)) {
525  bool ok = true;
526  double minGap = attrs.get<double>(SUMO_ATTR_MINGAP, vtype->id.c_str(), ok);
527  if (ok) {
528  if (minGap < 0) {
529  handleError(hardFail, abortCreation, toString(SUMO_ATTR_MINGAP) + " must be equal or greater than 0");
530  } else {
531  vtype->minGap = minGap;
533  }
534  }
535  }
536  if (attrs.hasAttribute(SUMO_ATTR_MAXSPEED)) {
537  bool ok = true;
538  double maxSpeed = attrs.get<double>(SUMO_ATTR_MAXSPEED, vtype->id.c_str(), ok);
539  if (ok) {
540  if (maxSpeed <= 0) {
541  handleError(hardFail, abortCreation, toString(SUMO_ATTR_MAXSPEED) + " must be greater than 0");
542  } else {
543  vtype->maxSpeed = maxSpeed;
545  }
546  }
547  }
548  if (attrs.hasAttribute(SUMO_ATTR_SPEEDFACTOR)) {
549  bool ok = true;
550  vtype->speedFactor.parse(attrs.get<std::string>(SUMO_ATTR_SPEEDFACTOR, vtype->id.c_str(), ok), hardFail);
551  if (ok) {
553  }
554  }
555  if (attrs.hasAttribute(SUMO_ATTR_SPEEDDEV)) {
556  bool ok = true;
557  double speedDev = attrs.get<double>(SUMO_ATTR_SPEEDDEV, vtype->id.c_str(), ok);
558  if (ok) {
559  if (speedDev < 0) {
560  handleError(hardFail, abortCreation, toString(SUMO_ATTR_SPEEDDEV) + " must be equal or greater than 0");
561  } else {
562  vtype->speedFactor.getParameter()[1] = speedDev;
564  }
565  }
566  }
567  // validate speed distribution
568  std::string error;
569  if (!vtype->speedFactor.isValid(error)) {
570  handleError(hardFail, abortCreation, "Invalid speed distribution when parsing vType '" + vtype->id + "' (" + error + ")");
571  }
573  bool ok = true;
574  double actionStepLengthSecs = attrs.get<double>(SUMO_ATTR_ACTIONSTEPLENGTH, vtype->id.c_str(), ok);
575  // processActionStepLength(...) function includes warnings
576  vtype->actionStepLength = processActionStepLength(actionStepLengthSecs);
578  }
580  bool ok = true;
581  std::string parsedEmissionClass = attrs.getOpt<std::string>(SUMO_ATTR_EMISSIONCLASS, id.c_str(), ok, "");
582  // check if emission class is correct
583  try {
584  vtype->emissionClass = PollutantsInterface::getClassByName(parsedEmissionClass);
586  } catch (...) {
587  if (hardFail) {
588  throw InvalidArgument(toString(SUMO_ATTR_EMISSIONCLASS) + " with name '" + parsedEmissionClass + "' doesn't exist.");
589  } else {
590  WRITE_ERROR(toString(SUMO_ATTR_EMISSIONCLASS) + " with name '" + parsedEmissionClass + "' doesn't exist.");
591  }
592  }
593  }
594  if (attrs.hasAttribute(SUMO_ATTR_IMPATIENCE)) {
595  bool okString = true;
596  if (attrs.get<std::string>(SUMO_ATTR_IMPATIENCE, vtype->id.c_str(), okString) == "off") {
597  vtype->impatience = -std::numeric_limits<double>::max();
598  } else {
599  bool okDouble = true;
600  const double impatience = attrs.get<double>(SUMO_ATTR_IMPATIENCE, vtype->id.c_str(), okDouble);
601  if (okDouble) {
602  vtype->impatience = impatience;
604  }
605  }
606  }
607  if (attrs.hasAttribute(SUMO_ATTR_WIDTH)) {
608  bool ok = true;
609  double width = attrs.get<double>(SUMO_ATTR_WIDTH, vtype->id.c_str(), ok);
610  if (ok) {
611  if (width <= 0) {
612  handleError(hardFail, abortCreation, toString(SUMO_ATTR_WIDTH) + " must be greater than 0");
613  } else {
614  vtype->width = width;
616  }
617  }
618  }
619  if (attrs.hasAttribute(SUMO_ATTR_HEIGHT)) {
620  bool ok = true;
621  double height = attrs.get<double>(SUMO_ATTR_HEIGHT, vtype->id.c_str(), ok);
622  if (ok) {
623  if (height < 0) {
624  handleError(hardFail, abortCreation, toString(SUMO_ATTR_HEIGHT) + " must be equal or greater than 0");
625  } else {
626  vtype->height = height;
628  }
629  }
630  }
631  if (attrs.hasAttribute(SUMO_ATTR_GUISHAPE)) {
632  vtype->shape = parseGuiShape(attrs, vtype->id);
633  if (vtype->shape != SVS_UNKNOWN) {
635  }
636  }
637  if (attrs.hasAttribute(SUMO_ATTR_OSGFILE)) {
638  bool ok = true;
639  std::string osgFile = attrs.get<std::string>(SUMO_ATTR_OSGFILE, vtype->id.c_str(), ok);
640  if (ok) {
641  vtype->osgFile = osgFile;
643  }
644  }
645  if (attrs.hasAttribute(SUMO_ATTR_IMGFILE)) {
646  bool ok = true;
647  std::string imgFile = attrs.get<std::string>(SUMO_ATTR_IMGFILE, vtype->id.c_str(), ok);
648  if (ok) {
649  // check relative path
650  if ((imgFile != "") && !FileHelpers::isAbsolute(imgFile)) {
651  imgFile = FileHelpers::getConfigurationRelative(file, imgFile);
652  }
653  vtype->imgFile = imgFile;
655  }
656  }
657  if (attrs.hasAttribute(SUMO_ATTR_COLOR)) {
658  bool ok = true;
659  RGBColor color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, vtype->id.c_str(), ok);
660  if (ok) {
661  vtype->color = color;
663  }
664  } else {
665  vtype->color = RGBColor::YELLOW;
666  }
667  if (attrs.hasAttribute(SUMO_ATTR_PROB)) {
668  bool ok = true;
669  double defaultProbability = attrs.get<double>(SUMO_ATTR_PROB, vtype->id.c_str(), ok);
670  if (ok) {
671  if (defaultProbability < 0) {
672  handleError(hardFail, abortCreation, toString(SUMO_ATTR_PROB) + " must be equal or greater than 0");
673  } else {
674  vtype->defaultProbability = defaultProbability;
676  }
677  }
678  }
680  bool ok = true;
681  std::string lcmS = attrs.get<std::string>(SUMO_ATTR_LANE_CHANGE_MODEL, vtype->id.c_str(), ok);
682  if (lcmS == "JE2013") {
683  WRITE_WARNING("Lane change model 'JE2013' is deprecated. Using default model instead.");
684  lcmS = "default";
685  }
686  if (SUMOXMLDefinitions::LaneChangeModels.hasString(lcmS)) {
689  } else {
690  handleError(hardFail, abortCreation, "Unknown lane change model '" + lcmS + "' when parsing vType '" + vtype->id + "'");
691  }
692  }
694  bool ok = true;
695  const std::string cfmValue = attrs.get<std::string>(SUMO_ATTR_CAR_FOLLOW_MODEL, vtype->id.c_str(), ok);
696  if (ok && SUMOXMLDefinitions::CarFollowModels.hasString(cfmValue)) {
699  } else {
700  handleError(hardFail, abortCreation, "Unknown car following model '" + cfmValue + "' when parsing vType '" + vtype->id + "'");
701  }
702  }
704  bool ok = true;
705  int personCapacity = attrs.get<int>(SUMO_ATTR_PERSON_CAPACITY, vtype->id.c_str(), ok);
706  if (ok) {
707  if (personCapacity < 0) {
708  handleError(hardFail, abortCreation, toString(SUMO_ATTR_PERSON_CAPACITY) + " must be equal or greater than 0");
709  } else {
710  vtype->personCapacity = personCapacity;
712  }
713  }
714  }
716  bool ok = true;
717  int containerCapacity = attrs.get<int>(SUMO_ATTR_CONTAINER_CAPACITY, vtype->id.c_str(), ok);
718  if (ok) {
719  if (containerCapacity < 0) {
720  handleError(hardFail, abortCreation, toString(SUMO_ATTR_CONTAINER_CAPACITY) + " must be equal or greater than 0");
721  } else {
722  vtype->containerCapacity = containerCapacity;
724  }
725  }
726  }
728  bool ok = true;
729  SUMOTime boardingDuration = attrs.getSUMOTimeReporting(SUMO_ATTR_BOARDING_DURATION, vtype->id.c_str(), ok);
730  if (ok) {
731  if (boardingDuration < 0) {
732  handleError(hardFail, abortCreation, toString(SUMO_ATTR_BOARDING_DURATION) + " must be equal or greater than 0");
733  } else {
734  vtype->boardingDuration = boardingDuration;
736  }
737  }
738  }
740  bool ok = true;
741  SUMOTime loadingDuration = attrs.getSUMOTimeReporting(SUMO_ATTR_LOADING_DURATION, vtype->id.c_str(), ok);
742  if (ok) {
743  if (loadingDuration < 0) {
744  handleError(hardFail, abortCreation, toString(SUMO_ATTR_LOADING_DURATION) + " must be equal or greater than 0");
745  } else {
746  vtype->loadingDuration = loadingDuration;
748  }
749  }
750  }
752  bool ok = true;
753  double maxSpeedLat = attrs.get<double>(SUMO_ATTR_MAXSPEED_LAT, vtype->id.c_str(), ok);
754  if (ok) {
755  if (maxSpeedLat <= 0) {
756  handleError(hardFail, abortCreation, toString(SUMO_ATTR_MAXSPEED_LAT) + " must be greater than 0");
757  } else {
758  vtype->maxSpeedLat = maxSpeedLat;
760  }
761  }
762  }
763  if (attrs.hasAttribute(SUMO_ATTR_MINGAP_LAT)) {
764  bool ok = true;
765  double minGapLat = attrs.get<double>(SUMO_ATTR_MINGAP_LAT, vtype->id.c_str(), ok);
766  if (ok) {
767  if (minGapLat < 0) {
768  handleError(hardFail, abortCreation, toString(SUMO_ATTR_MINGAP_LAT) + " must be equal or greater than 0");
769  } else {
770  vtype->minGapLat = minGapLat;
772  }
773  }
774  }
776  bool ok = true;
777  const std::string alignS = attrs.get<std::string>(SUMO_ATTR_LATALIGNMENT, vtype->id.c_str(), ok);
778  if (ok && SUMOXMLDefinitions::LateralAlignments.hasString(alignS)) {
781  } else {
782  handleError(hardFail, abortCreation, "Unknown lateral alignment '" + alignS + "' when parsing vType '" + vtype->id + "'");
783  }
784  }
786  bool ok = true;
787  const std::string angleTimesS = attrs.get<std::string>(SUMO_ATTR_MANEUVER_ANGLE_TIMES, vtype->id.c_str(), ok);
788  if (ok && parseAngleTimesMap(*vtype, angleTimesS, hardFail)) {
790  } else {
791  handleError(hardFail, abortCreation, "Invalid manoeuver angle times map for vType '" + vtype->id + "'");
792  }
793  }
794 
795  // try to parse embedded vType
796  if (!parseVTypeEmbedded(*vtype, vtype->cfModel, attrs, hardFail, true)) {
797  handleError(hardFail, abortCreation, "Invalid parsing embedded VType");
798  }
799  // try to parse Lane Change Model params
800  if (!parseLCParams(*vtype, vtype->lcModel, attrs, hardFail)) {
801  handleError(hardFail, abortCreation, "Invalid Lane Change Model Parameters");
802  }
803  // try to Junction Model params
804  if (!parseJMParams(*vtype, attrs, hardFail)) {
805  handleError(hardFail, abortCreation, "Invalid Junction Model Parameters");
806  }
807  } catch (ProcessError&) {
808  delete vtype;
809  throw;
810  }
811  if (!abortCreation) {
812  delete vtype;
813  if (hardFail) {
814  throw ProcessError();
815  } else {
816  return nullptr;
817  }
818  }
819  return vtype;
820  } else {
821  if (hardFail) {
822  throw ProcessError("VType cannot be created");
823  } else {
824  return nullptr;
825  }
826  }
827 }
828 
829 bool
830 SUMOVehicleParserHelper::parseAngleTimesMap(SUMOVTypeParameter& vtype, const std::string atm, const bool hardFail) {
831  StringTokenizer st(atm, ",");
832  std::map<int, std::pair<SUMOTime, SUMOTime>> angleTimesMap;
833  int tripletCount = 0;
834 
835  while (st.hasNext()) {
836  StringTokenizer pos(st.next());
837  if (pos.size() != 3) {
838  if (hardFail) {
839  throw ProcessError("manoeuverAngleTimes format for vType '" + vtype.id + "' " + atm + " contains an invalid triplet.");
840  } else {
841  WRITE_ERROR("manoeuverAngleTimes format for vType '" + vtype.id + "' " + atm + " contains an invalid triplet.");
842  }
843  } else {
844  try {
845  int angle = StringUtils::toInt(pos.next());
846  SUMOTime t1 = static_cast<SUMOTime>(StringUtils::toDouble(pos.next()));
847  t1 = TIME2STEPS(t1);
848  SUMOTime t2 = static_cast<SUMOTime>(StringUtils::toDouble(pos.next()));
849  t2 = TIME2STEPS(t2);
850 
851  angleTimesMap.insert((std::pair<int, std::pair<SUMOTime, SUMOTime>>(angle, std::pair< SUMOTime, SUMOTime>(t1, t2))));
852  } catch (...) {
853  WRITE_ERROR("Triplet '" + st.get(tripletCount) + "' for vType '" + vtype.id + "' manoeuverAngleTimes cannot be parsed as 'int double double'");
854  }
855  tripletCount++;
856  }
857  }
858 
859  if (angleTimesMap.size() > 0) {
860  vtype.myManoeuverAngleTimes.clear();
861  for (std::pair<int, std::pair<SUMOTime, SUMOTime>> angleTime : angleTimesMap) {
862  vtype.myManoeuverAngleTimes.insert(std::pair<int, std::pair<SUMOTime, SUMOTime>>(angleTime));
863  }
864  angleTimesMap.clear();
865  return true;
866  } else {
867  return false;
868  }
869 }
870 
871 
872 bool
873 SUMOVehicleParserHelper::parseVTypeEmbedded(SUMOVTypeParameter& into, const SumoXMLTag element, const SUMOSAXAttributes& attrs, const bool hardFail, const bool fromVType) {
874  const CFAttrMap& allowedCFM = getAllowedCFModelAttrs();
875  bool abortCreation = true;
876  CFAttrMap::const_iterator cf_it = allowedCFM.find(element);
877  // check if given CFM is allowed
878  if (cf_it == allowedCFM.end()) {
879  if (SUMOXMLDefinitions::Tags.has((int)element)) {
880  handleError(hardFail, abortCreation, "Unknown car following model " + toString(element) + " when parsing vType '" + into.id + "'");
881  } else {
882  handleError(hardFail, abortCreation, "Unknown car following model when parsing vType '" + into.id + "'");
883  }
884  return false;
885  }
886  // set car following model
887  if (!fromVType) {
888  into.cfModel = cf_it->first;
890  }
891  // set CFM values
892  bool ok = true;
893  for (const auto& it : cf_it->second) {
894  if (attrs.hasAttribute(it)) {
895  // first obtain CFM attribute in string format
896  std::string parsedCFMAttribute = attrs.get<std::string>(it, into.id.c_str(), ok);
897  // check if attribute is of type "train"
898  if (it == SUMO_ATTR_TRAIN_TYPE) {
899  // check if train value is valid
900  if (SUMOXMLDefinitions::TrainTypes.hasString(parsedCFMAttribute)) {
901  // add parsedCFMAttribute to cfParameter
902  into.cfParameter[it] = parsedCFMAttribute;
903  } else if (hardFail) {
904  throw ProcessError("Invalid train type '" + parsedCFMAttribute + "' used in Car-Following-Attribute " + toString(it));
905  } else {
906  WRITE_ERROR("Invalid train type '" + parsedCFMAttribute + "' used in Car-Following-Attribute " + toString(it));
907  }
908  } else if (it == SUMO_ATTR_CF_IDM_STEPPING) {
909  // declare a int in wich save CFM int attribute
910  int CFMIntAttribute = -1;
911  try {
912  // obtain CFM attribute in int format
913  CFMIntAttribute = StringUtils::toInt(parsedCFMAttribute);
914  } catch (...) {
915  ok = false;
916  if (hardFail) {
917  throw ProcessError("Invalid Car-Following-Model Attribute " + toString(it) + ". Cannot be parsed to int");
918  } else {
919  WRITE_ERROR("Invalid Car-Following-Model Attribute " + toString(it) + ". Cannot be parsed to int");
920  }
921  }
922  // now continue checking other properties
923  if (ok) {
924  if (CFMIntAttribute <= 0) {
925  ok = false;
926  if (hardFail) {
927  throw ProcessError("Invalid Car-Following-Model Attribute " + toString(it) + ". Must be greater than 0");
928  } else {
929  WRITE_ERROR("Invalid Car-Following-Model Attribute " + toString(it) + ". Must be greater than 0");
930  }
931  }
932  if (ok) {
933  // add parsedCFMAttribute to cfParameter
934  into.cfParameter[it] = parsedCFMAttribute;
935  }
936  }
937  } else {
938  // declare a double in wich save CFM float attribute
939  double CFMDoubleAttribute = -1;
940  try {
941  // obtain CFM attribute in double format
942  CFMDoubleAttribute = StringUtils::toDouble(parsedCFMAttribute);
943  } catch (...) {
944  ok = false;
945  if (hardFail) {
946  throw ProcessError("Invalid Car-Following-Model Attribute " + toString(it) + ". Cannot be parsed to float");
947  } else {
948  WRITE_ERROR("Invalid Car-Following-Model Attribute " + toString(it) + ". Cannot be parsed to float");
949  }
950  if (ok) {
951  // add parsedCFMAttribute to cfParameter
952  into.cfParameter[it] = parsedCFMAttribute;
953  }
954  }
955  // now continue checking other properties
956  if (ok) {
957  // check attributes of type "positiveFloatType" (> 0)
958  switch (it) {
959  case SUMO_ATTR_ACCEL:
960  case SUMO_ATTR_DECEL:
963  case SUMO_ATTR_TAU:
964  if (CFMDoubleAttribute <= 0) {
965  ok = false;
966  if (hardFail) {
967  throw ProcessError("Invalid Car-Following-Model Attribute " + toString(it) + ". Must be greater than 0");
968  } else {
969  WRITE_ERROR("Invalid Car-Following-Model Attribute " + toString(it) + ". Must be greater than 0");
970  }
971  }
972  default:
973  break;
974  }
975  // check attributes restricted to [0-1]
976  switch (it) {
977  case SUMO_ATTR_SIGMA:
978  if ((CFMDoubleAttribute < 0) || (CFMDoubleAttribute > 1)) {
979  ok = false;
980  if (hardFail) {
981  throw ProcessError("Invalid Car-Following-Model Attribute " + toString(it) + ". Only values between [0-1] are allowed");
982  } else {
983  WRITE_ERROR("Invalid Car-Following-Model Attribute " + toString(it) + ". Only values between [0-1] are allowed");
984  }
985  }
986  default:
987  break;
988  }
989  // special check for TAU attribute
990  if (it == SUMO_ATTR_TAU) {
991  // check tau in time format
992  if ((string2time(parsedCFMAttribute) < DELTA_T) && gSimulation) {
993  WRITE_WARNING("Value of tau=" + parsedCFMAttribute + " in car following model '" +
994  toString(into.cfModel) + "' lower than simulation step size may cause collisions");
995  }
996  }
997  if (ok) {
998  // add parsedCFMAttribute to cfParameter
999  into.cfParameter[it] = parsedCFMAttribute;
1000  }
1001  }
1002  }
1003  }
1004  }
1005  return ok;
1006 }
1007 
1008 
1011  // init on first use
1012  if (allowedCFModelAttrs.size() == 0) {
1013  std::set<SumoXMLAttr> kraussParams;
1014  kraussParams.insert(SUMO_ATTR_ACCEL);
1015  kraussParams.insert(SUMO_ATTR_DECEL);
1016  kraussParams.insert(SUMO_ATTR_APPARENTDECEL);
1017  kraussParams.insert(SUMO_ATTR_EMERGENCYDECEL);
1018  kraussParams.insert(SUMO_ATTR_SIGMA);
1019  kraussParams.insert(SUMO_ATTR_TAU);
1020  allowedCFModelAttrs[SUMO_TAG_CF_KRAUSS] = kraussParams;
1023  std::set<SumoXMLAttr> allParams(kraussParams);
1024 
1025  std::set<SumoXMLAttr> kraussXParams(kraussParams);
1026  kraussXParams.insert(SUMO_ATTR_TMP1);
1027  kraussXParams.insert(SUMO_ATTR_TMP2);
1028  kraussXParams.insert(SUMO_ATTR_TMP3);
1029  kraussXParams.insert(SUMO_ATTR_TMP4);
1030  kraussXParams.insert(SUMO_ATTR_TMP5);
1031  allowedCFModelAttrs[SUMO_TAG_CF_KRAUSSX] = kraussXParams;
1032  allParams.insert(kraussXParams.begin(), kraussXParams.end());
1033 
1034  std::set<SumoXMLAttr> smartSKParams;
1035  smartSKParams.insert(SUMO_ATTR_ACCEL);
1036  smartSKParams.insert(SUMO_ATTR_DECEL);
1037  smartSKParams.insert(SUMO_ATTR_EMERGENCYDECEL);
1038  smartSKParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
1039  smartSKParams.insert(SUMO_ATTR_SIGMA);
1040  smartSKParams.insert(SUMO_ATTR_TAU);
1041  smartSKParams.insert(SUMO_ATTR_TMP1);
1042  smartSKParams.insert(SUMO_ATTR_TMP2);
1043  smartSKParams.insert(SUMO_ATTR_TMP3);
1044  smartSKParams.insert(SUMO_ATTR_TMP4);
1045  smartSKParams.insert(SUMO_ATTR_TMP5);
1046  allowedCFModelAttrs[SUMO_TAG_CF_SMART_SK] = smartSKParams;
1047  allParams.insert(smartSKParams.begin(), smartSKParams.end());
1048 
1049  std::set<SumoXMLAttr> daniel1Params;
1050  daniel1Params.insert(SUMO_ATTR_ACCEL);
1051  daniel1Params.insert(SUMO_ATTR_DECEL);
1052  daniel1Params.insert(SUMO_ATTR_EMERGENCYDECEL);
1053  daniel1Params.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
1054  daniel1Params.insert(SUMO_ATTR_SIGMA);
1055  daniel1Params.insert(SUMO_ATTR_TAU);
1056  daniel1Params.insert(SUMO_ATTR_TMP1);
1057  daniel1Params.insert(SUMO_ATTR_TMP2);
1058  daniel1Params.insert(SUMO_ATTR_TMP3);
1059  daniel1Params.insert(SUMO_ATTR_TMP4);
1060  daniel1Params.insert(SUMO_ATTR_TMP5);
1061  allowedCFModelAttrs[SUMO_TAG_CF_DANIEL1] = daniel1Params;
1062  allParams.insert(daniel1Params.begin(), daniel1Params.end());
1063 
1064  std::set<SumoXMLAttr> pwagParams;
1065  pwagParams.insert(SUMO_ATTR_ACCEL);
1066  pwagParams.insert(SUMO_ATTR_DECEL);
1067  pwagParams.insert(SUMO_ATTR_EMERGENCYDECEL);
1068  pwagParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
1069  pwagParams.insert(SUMO_ATTR_SIGMA);
1070  pwagParams.insert(SUMO_ATTR_TAU);
1071  pwagParams.insert(SUMO_ATTR_CF_PWAGNER2009_TAULAST);
1072  pwagParams.insert(SUMO_ATTR_CF_PWAGNER2009_APPROB);
1074  allParams.insert(pwagParams.begin(), pwagParams.end());
1075 
1076  std::set<SumoXMLAttr> idmParams;
1077  idmParams.insert(SUMO_ATTR_ACCEL);
1078  idmParams.insert(SUMO_ATTR_DECEL);
1079  idmParams.insert(SUMO_ATTR_EMERGENCYDECEL);
1080  idmParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
1081  idmParams.insert(SUMO_ATTR_TAU);
1082  idmParams.insert(SUMO_ATTR_CF_IDM_DELTA);
1083  idmParams.insert(SUMO_ATTR_CF_IDM_STEPPING);
1084  allowedCFModelAttrs[SUMO_TAG_CF_IDM] = idmParams;
1085  allParams.insert(idmParams.begin(), idmParams.end());
1086 
1087  std::set<SumoXMLAttr> idmmParams;
1088  idmmParams.insert(SUMO_ATTR_ACCEL);
1089  idmmParams.insert(SUMO_ATTR_DECEL);
1090  idmmParams.insert(SUMO_ATTR_EMERGENCYDECEL);
1091  idmmParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
1092  idmmParams.insert(SUMO_ATTR_TAU);
1093  idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_FACTOR);
1094  idmmParams.insert(SUMO_ATTR_CF_IDMM_ADAPT_TIME);
1095  idmmParams.insert(SUMO_ATTR_CF_IDM_STEPPING);
1096  allowedCFModelAttrs[SUMO_TAG_CF_IDMM] = idmmParams;
1097  allParams.insert(idmmParams.begin(), idmmParams.end());
1098 
1099  std::set<SumoXMLAttr> bkernerParams;
1100  bkernerParams.insert(SUMO_ATTR_ACCEL);
1101  bkernerParams.insert(SUMO_ATTR_DECEL);
1102  bkernerParams.insert(SUMO_ATTR_EMERGENCYDECEL);
1103  bkernerParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
1104  bkernerParams.insert(SUMO_ATTR_TAU);
1105  bkernerParams.insert(SUMO_ATTR_K);
1106  bkernerParams.insert(SUMO_ATTR_CF_KERNER_PHI);
1107  allowedCFModelAttrs[SUMO_TAG_CF_BKERNER] = bkernerParams;
1108  allParams.insert(bkernerParams.begin(), bkernerParams.end());
1109 
1110  std::set<SumoXMLAttr> wiedemannParams;
1111  wiedemannParams.insert(SUMO_ATTR_ACCEL);
1112  wiedemannParams.insert(SUMO_ATTR_DECEL);
1113  wiedemannParams.insert(SUMO_ATTR_EMERGENCYDECEL);
1114  wiedemannParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
1115  wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_SECURITY);
1116  wiedemannParams.insert(SUMO_ATTR_CF_WIEDEMANN_ESTIMATION);
1117  allowedCFModelAttrs[SUMO_TAG_CF_WIEDEMANN] = wiedemannParams;
1118  allParams.insert(wiedemannParams.begin(), wiedemannParams.end());
1119 
1120  std::set<SumoXMLAttr> w99Params;
1121  w99Params.insert(SUMO_ATTR_DECEL); // used when patching speed during lane-changing
1122  w99Params.insert(SUMO_ATTR_EMERGENCYDECEL);
1123  w99Params.insert(SUMO_ATTR_CF_W99_CC1);
1124  w99Params.insert(SUMO_ATTR_CF_W99_CC2);
1125  w99Params.insert(SUMO_ATTR_CF_W99_CC3);
1126  w99Params.insert(SUMO_ATTR_CF_W99_CC4);
1127  w99Params.insert(SUMO_ATTR_CF_W99_CC5);
1128  w99Params.insert(SUMO_ATTR_CF_W99_CC6);
1129  w99Params.insert(SUMO_ATTR_CF_W99_CC7);
1130  w99Params.insert(SUMO_ATTR_CF_W99_CC8);
1131  w99Params.insert(SUMO_ATTR_CF_W99_CC9);
1132  allowedCFModelAttrs[SUMO_TAG_CF_W99] = w99Params;
1133  allParams.insert(w99Params.begin(), w99Params.end());
1134 
1135  std::set<SumoXMLAttr> railParams;
1136  railParams.insert(SUMO_ATTR_TRAIN_TYPE);
1137  railParams.insert(SUMO_ATTR_ACCEL);
1138  railParams.insert(SUMO_ATTR_DECEL);
1139  railParams.insert(SUMO_ATTR_APPARENTDECEL);
1140  railParams.insert(SUMO_ATTR_EMERGENCYDECEL);
1141  railParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
1142  allowedCFModelAttrs[SUMO_TAG_CF_RAIL] = railParams;
1143  allParams.insert(railParams.begin(), railParams.end());
1144 
1145  std::set<SumoXMLAttr> ACCParams;
1146  ACCParams.insert(SUMO_ATTR_ACCEL);
1147  ACCParams.insert(SUMO_ATTR_DECEL);
1148  ACCParams.insert(SUMO_ATTR_EMERGENCYDECEL);
1149  ACCParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
1150  ACCParams.insert(SUMO_ATTR_TAU);
1151  ACCParams.insert(SUMO_ATTR_SC_GAIN);
1152  ACCParams.insert(SUMO_ATTR_GCC_GAIN_SPEED);
1153  ACCParams.insert(SUMO_ATTR_GCC_GAIN_SPACE);
1154  ACCParams.insert(SUMO_ATTR_GC_GAIN_SPEED);
1155  ACCParams.insert(SUMO_ATTR_GC_GAIN_SPACE);
1156  ACCParams.insert(SUMO_ATTR_CA_GAIN_SPEED);
1157  ACCParams.insert(SUMO_ATTR_CA_GAIN_SPACE);
1158  allowedCFModelAttrs[SUMO_TAG_CF_ACC] = ACCParams;
1159  allParams.insert(ACCParams.begin(), ACCParams.end());
1160 
1161  std::set<SumoXMLAttr> CACCParams;
1162  CACCParams.insert(SUMO_ATTR_ACCEL);
1163  CACCParams.insert(SUMO_ATTR_DECEL);
1164  CACCParams.insert(SUMO_ATTR_EMERGENCYDECEL);
1165  CACCParams.insert(SUMO_ATTR_COLLISION_MINGAP_FACTOR);
1166  CACCParams.insert(SUMO_ATTR_TAU);
1167  CACCParams.insert(SUMO_ATTR_SC_GAIN_CACC);
1168  CACCParams.insert(SUMO_ATTR_GCC_GAIN_GAP_CACC);
1169  CACCParams.insert(SUMO_ATTR_GCC_GAIN_GAP_DOT_CACC);
1170  CACCParams.insert(SUMO_ATTR_GC_GAIN_GAP_CACC);
1171  CACCParams.insert(SUMO_ATTR_GC_GAIN_GAP_DOT_CACC);
1172  CACCParams.insert(SUMO_ATTR_CA_GAIN_GAP_CACC);
1173  CACCParams.insert(SUMO_ATTR_CA_GAIN_GAP_DOT_CACC);
1174  CACCParams.insert(SUMO_ATTR_GCC_GAIN_SPEED);
1175  CACCParams.insert(SUMO_ATTR_GCC_GAIN_SPACE);
1176  CACCParams.insert(SUMO_ATTR_GC_GAIN_SPEED);
1177  CACCParams.insert(SUMO_ATTR_GC_GAIN_SPACE);
1178  CACCParams.insert(SUMO_ATTR_CA_GAIN_SPEED);
1179  CACCParams.insert(SUMO_ATTR_CA_GAIN_SPACE);
1180  CACCParams.insert(SUMO_ATTR_HEADWAY_TIME_CACC_TO_ACC);
1181  allowedCFModelAttrs[SUMO_TAG_CF_CACC] = CACCParams;
1182  allParams.insert(CACCParams.begin(), CACCParams.end());
1183 
1184  std::set<SumoXMLAttr> ccParams;
1185  ccParams.insert(SUMO_ATTR_ACCEL);
1186  ccParams.insert(SUMO_ATTR_DECEL);
1187  ccParams.insert(SUMO_ATTR_TAU);
1188  ccParams.insert(SUMO_ATTR_CF_CC_C1);
1189  ccParams.insert(SUMO_ATTR_CF_CC_CCDECEL);
1190  ccParams.insert(SUMO_ATTR_CF_CC_CONSTSPACING);
1191  ccParams.insert(SUMO_ATTR_CF_CC_KP);
1192  ccParams.insert(SUMO_ATTR_CF_CC_LAMBDA);
1193  ccParams.insert(SUMO_ATTR_CF_CC_OMEGAN);
1194  ccParams.insert(SUMO_ATTR_CF_CC_TAU);
1195  ccParams.insert(SUMO_ATTR_CF_CC_XI);
1196  ccParams.insert(SUMO_ATTR_CF_CC_LANES_COUNT);
1197  ccParams.insert(SUMO_ATTR_CF_CC_CCACCEL);
1198  ccParams.insert(SUMO_ATTR_CF_CC_PLOEG_KP);
1199  ccParams.insert(SUMO_ATTR_CF_CC_PLOEG_KD);
1200  ccParams.insert(SUMO_ATTR_CF_CC_PLOEG_H);
1201  ccParams.insert(SUMO_ATTR_CF_CC_FLATBED_KA);
1202  ccParams.insert(SUMO_ATTR_CF_CC_FLATBED_KV);
1203  ccParams.insert(SUMO_ATTR_CF_CC_FLATBED_KP);
1204  ccParams.insert(SUMO_ATTR_CF_CC_FLATBED_D);
1205  ccParams.insert(SUMO_ATTR_CF_CC_FLATBED_H);
1206  allowedCFModelAttrs[SUMO_TAG_CF_CC] = ccParams;
1207  allParams.insert(ccParams.begin(), ccParams.end());
1208 
1210  }
1211  return allowedCFModelAttrs;
1212 }
1213 
1214 
1215 bool
1217  if (allowedLCModelAttrs.size() == 0) {
1218  // init static map
1219  std::set<SumoXMLAttr> lc2013Params;
1220  lc2013Params.insert(SUMO_ATTR_LCA_STRATEGIC_PARAM);
1221  lc2013Params.insert(SUMO_ATTR_LCA_COOPERATIVE_PARAM);
1222  lc2013Params.insert(SUMO_ATTR_LCA_SPEEDGAIN_PARAM);
1223  lc2013Params.insert(SUMO_ATTR_LCA_KEEPRIGHT_PARAM);
1224  lc2013Params.insert(SUMO_ATTR_LCA_OPPOSITE_PARAM);
1225  lc2013Params.insert(SUMO_ATTR_LCA_LOOKAHEADLEFT);
1226  lc2013Params.insert(SUMO_ATTR_LCA_SPEEDGAINRIGHT);
1227  lc2013Params.insert(SUMO_ATTR_LCA_MAXSPEEDLATSTANDING);
1228  lc2013Params.insert(SUMO_ATTR_LCA_MAXSPEEDLATFACTOR);
1229  lc2013Params.insert(SUMO_ATTR_LCA_ASSERTIVE);
1230  lc2013Params.insert(SUMO_ATTR_LCA_SPEEDGAIN_LOOKAHEAD);
1231  lc2013Params.insert(SUMO_ATTR_LCA_COOPERATIVE_ROUNDABOUT);
1232  lc2013Params.insert(SUMO_ATTR_LCA_COOPERATIVE_SPEED);
1233  lc2013Params.insert(SUMO_ATTR_LCA_OVERTAKE_RIGHT);
1234  lc2013Params.insert(SUMO_ATTR_LCA_SIGMA);
1235  lc2013Params.insert(SUMO_ATTR_LCA_EXPERIMENTAL1);
1236  allowedLCModelAttrs[LCM_LC2013] = lc2013Params;
1237 
1238  std::set<SumoXMLAttr> sl2015Params = lc2013Params;
1239  sl2015Params.insert(SUMO_ATTR_LCA_PUSHY);
1240  sl2015Params.insert(SUMO_ATTR_LCA_PUSHYGAP);
1241  sl2015Params.insert(SUMO_ATTR_LCA_SUBLANE_PARAM);
1242  sl2015Params.insert(SUMO_ATTR_LCA_IMPATIENCE);
1243  sl2015Params.insert(SUMO_ATTR_LCA_TIME_TO_IMPATIENCE);
1244  sl2015Params.insert(SUMO_ATTR_LCA_ACCEL_LAT);
1245  sl2015Params.insert(SUMO_ATTR_LCA_TURN_ALIGNMENT_DISTANCE);
1246  sl2015Params.insert(SUMO_ATTR_LCA_LANE_DISCIPLINE);
1247  allowedLCModelAttrs[LCM_SL2015] = sl2015Params;
1248 
1249  std::set<SumoXMLAttr> noParams;
1250  allowedLCModelAttrs[LCM_DK2008] = noParams;
1251 
1252  // default model may be either LC2013 or SL2015
1253  // we allow both sets (sl2015 is a superset of lc2013Params)
1254  allowedLCModelAttrs[LCM_DEFAULT] = sl2015Params;
1255  }
1256  bool ok = true;
1257  std::set<SumoXMLAttr> allowed = allowedLCModelAttrs[model];
1258  for (const auto& it : allowed) {
1259  if (attrs.hasAttribute(it)) {
1260  // first obtain CFM attribute in string format
1261  std::string parsedLCMAttribute = attrs.get<std::string>(it, into.id.c_str(), ok);
1262  // declare a double in wich save CFM attribute
1263  double LCMAttribute = -1;
1264  try {
1265  // obtain CFM attribute in double format
1266  LCMAttribute = StringUtils::toDouble(parsedLCMAttribute);
1267  } catch (...) {
1268  ok = false;
1269  if (hardFail) {
1270  throw ProcessError("Invalid Lane-Change-Model Attribute " + toString(it) + ". Cannot be parsed to float");
1271  } else {
1272  WRITE_ERROR("Invalid Lane-Change-Model Attribute " + toString(it) + ". Cannot be parsed to float");
1273  }
1274  }
1275  // now continue checking other properties
1276  if (ok) {
1277  // check attributes of type "nonNegativeFloatType" (>= 0)
1278  switch (it) {
1289  case SUMO_ATTR_LCA_SIGMA:
1290  if (LCMAttribute < 0) {
1291  ok = false;
1292  if (hardFail) {
1293  throw ProcessError("Invalid Lane-Change-Model Attribute " + toString(it) + ". Must be equal or greater than 0");
1294  } else {
1295  WRITE_ERROR("Invalid Lane-Change-Model Attribute " + toString(it) + ". Must be equal or greater than 0");
1296  }
1297  }
1298  default:
1299  break;
1300  }
1301  // check attributes of type "positiveFloatType" (> 0)
1302  switch (it) {
1305  if (LCMAttribute <= 0) {
1306  ok = false;
1307  if (hardFail) {
1308  throw ProcessError("Invalid Lane-Change-Model Attribute " + toString(it) + ". Must be greater than 0");
1309  } else {
1310  WRITE_ERROR("Invalid Lane-Change-Model Attribute " + toString(it) + ". Must be greater than 0");
1311  }
1312  }
1313  default:
1314  break;
1315  }
1316  if (ok) {
1317  // add parsedLCMAttribute to cfParameter
1318  into.lcParameter[it] = parsedLCMAttribute;
1319  }
1320  }
1321  }
1322  }
1323  return ok;
1324 }
1325 
1326 
1327 bool
1329  if (allowedJMAttrs.size() == 0) {
1330  // init static set (there is only one model)
1341  }
1342  bool ok = true;
1343  for (const auto& it : allowedJMAttrs) {
1344  if (attrs.hasAttribute(it)) {
1345  // first obtain CFM attribute in string format
1346  std::string parsedJMAttribute = attrs.get<std::string>(it, into.id.c_str(), ok);
1347  // declare a double in wich save CFM attribute
1348  double JMAttribute = -1;
1349  try {
1350  // obtain CFM attribute in double format
1351  JMAttribute = StringUtils::toDouble(parsedJMAttribute);
1352  } catch (...) {
1353  ok = false;
1354  if (hardFail) {
1355  throw ProcessError("Invalid Junction-Model Attribute " + toString(it) + ". Cannot be parsed to float");
1356  } else {
1357  WRITE_ERROR("Invalid Junction-Model Attribute " + toString(it) + ". Cannot be parsed to float");
1358  }
1359  }
1360  // now continue checking other properties (-1 is the default value)
1361  if (ok && (JMAttribute != -1)) {
1362  // special case for sigma minor
1363  if (it == SUMO_ATTR_JM_SIGMA_MINOR) {
1364  // check attributes sigma minor
1365  if ((JMAttribute < 0) || (JMAttribute > 1)) {
1366  ok = false;
1367  if (hardFail) {
1368  throw ProcessError("Invalid Junction-Model Attribute " + toString(it) + ". Only values between [0-1] are allowed");
1369  } else {
1370  WRITE_ERROR("Invalid Junction-Model Attribute " + toString(it) + ". Only values between [0-1] are allowed");
1371  }
1372  }
1373  } else {
1374  // check attributes of type "nonNegativeFloatType" (>= 0)
1375  if (JMAttribute < 0) {
1376  ok = false;
1377  if (hardFail) {
1378  throw ProcessError("Invalid Junction-Model Attribute " + toString(it) + ". Must be equal or greater than 0");
1379  } else {
1380  WRITE_ERROR("Invalid Junction-Model Attribute " + toString(it) + ". Must be equal or greater than 0");
1381  }
1382  }
1383  }
1384  if (ok) {
1385  // add parsedJMAttribute to cfParameter
1386  into.jmParameter[it] = parsedJMAttribute;
1387  }
1388  }
1389  }
1390  }
1391  return ok;
1392 }
1393 
1394 
1397  SUMOVehicleClass vclass = SVC_IGNORING;
1398  bool ok = true;
1399  std::string vclassS = attrs.getOpt<std::string>(SUMO_ATTR_VCLASS, id.c_str(), ok, "");
1400  if (vclassS == "") {
1401  return vclass;
1402  }
1403  try {
1404  const SUMOVehicleClass result = getVehicleClassID(vclassS);
1405  const std::string& realName = SumoVehicleClassStrings.getString(result);
1406  if (realName != vclassS) {
1407  WRITE_WARNING("The vehicle class '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is deprecated, use '" + realName + "' instead.");
1408  }
1409  return result;
1410  } catch (...) {
1411  WRITE_ERROR("The vehicle class '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is not known.");
1412  }
1413  return vclass;
1414 }
1415 
1416 
1418 SUMOVehicleParserHelper::parseGuiShape(const SUMOSAXAttributes& attrs, const std::string& id) {
1419  bool ok = true;
1420  std::string vclassS = attrs.getOpt<std::string>(SUMO_ATTR_GUISHAPE, id.c_str(), ok, "");
1421  if (SumoVehicleShapeStrings.hasString(vclassS)) {
1422  const SUMOVehicleShape result = SumoVehicleShapeStrings.get(vclassS);
1423  const std::string& realName = SumoVehicleShapeStrings.getString(result);
1424  if (realName != vclassS) {
1425  WRITE_WARNING("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is deprecated, use '" + realName + "' instead.");
1426  }
1427  return result;
1428  } else {
1429  WRITE_ERROR("The shape '" + vclassS + "' for " + attrs.getObjectType() + " '" + id + "' is not known.");
1430  return SVS_UNKNOWN;
1431  }
1432 }
1433 
1434 
1435 double
1436 SUMOVehicleParserHelper::parseWalkPos(SumoXMLAttr attr, const bool hardFail, const std::string& id, double maxPos, const std::string& val, std::mt19937* rng) {
1437  double result;
1438  std::string error;
1439  ArrivalPosDefinition proc;
1440  // only supports 'random' and 'max'
1441  if (!SUMOVehicleParameter::parseArrivalPos(val, toString(SUMO_TAG_WALK), id, result, proc, error)) {
1442  if (hardFail) {
1443  throw ProcessError(error);
1444  } else {
1445  WRITE_ERROR(error);
1446  }
1447  }
1448  if (proc == ArrivalPosDefinition::RANDOM) {
1449  result = RandHelper::rand(maxPos, rng);
1450  } else if (proc == ArrivalPosDefinition::CENTER) {
1451  result = maxPos / 2.;
1452  } else if (proc == ArrivalPosDefinition::MAX) {
1453  result = maxPos;
1454  }
1455  return SUMOVehicleParameter::interpretEdgePos(result, maxPos, attr, id);
1456 }
1457 
1458 
1459 SUMOTime
1461  SUMOTime result = TIME2STEPS(given);
1462  if (result <= 0) {
1463  if (result < 0) {
1464  std::stringstream ss;
1465  ss << "The parameter action-step-length must be a non-negative multiple of the simulation step-length. Ignoring given value (="
1466  << STEPS2TIME(result) << " s.)";
1467  WRITE_WARNING(ss.str());
1468  }
1469  result = DELTA_T;
1470  } else if (result % DELTA_T != 0) {
1471  std::stringstream ss;
1472  result = (SUMOTime)(DELTA_T * floor(double(result) / double(DELTA_T)));
1473  result = MAX2(DELTA_T, result);
1474  if (fabs(given * 1000. - double(result)) > NUMERICAL_EPS) {
1475  ss << "The parameter action-step-length must be a non-negative multiple of the simulation step-length. Parsing given value ("
1476  << given << " s.) to the adjusted value "
1477  << STEPS2TIME(result) << " s.";
1478  WRITE_WARNING(ss.str());
1479  }
1480  }
1481  return result;
1482 }
1483 
1484 
1486 SUMOVehicleParserHelper::handleError(const bool hardFail, bool& abortCreation, const std::string& message) {
1487  if (hardFail) {
1488  abortCreation = true;
1489  throw ProcessError(message);
1490  } else {
1491  WRITE_ERROR(message);
1492  return nullptr;
1493  }
1494 }
1495 
1496 
1497 /****************************************************************************/
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:284
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:276
SUMOTime DELTA_T
Definition: SUMOTime.cpp:37
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
#define SUMOTime_MAX
Definition: SUMOTime.h:32
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
long long int SUMOTime
Definition: SUMOTime.h:31
const int VTYPEPARS_MAXSPEED_SET
const int VTYPEPARS_MANEUVER_ANGLE_TIMES_SET
const int VTYPEPARS_PERSON_CAPACITY
const int VTYPEPARS_HEIGHT_SET
const int VTYPEPARS_VEHICLECLASS_SET
const int VTYPEPARS_COLOR_SET
const int VTYPEPARS_SPEEDFACTOR_SET
const int VTYPEPARS_BOARDING_DURATION
const int VTYPEPARS_IMPATIENCE_SET
const int VTYPEPARS_LATALIGNMENT_SET
const int VTYPEPARS_LENGTH_SET
const int VTYPEPARS_OSGFILE_SET
const int VTYPEPARS_LANE_CHANGE_MODEL_SET
const int VTYPEPARS_MINGAP_SET
const int VTYPEPARS_IMGFILE_SET
const int VTYPEPARS_SHAPE_SET
const int VTYPEPARS_ACTIONSTEPLENGTH_SET
const int VTYPEPARS_LOADING_DURATION
const int VTYPEPARS_CONTAINER_CAPACITY
const int VTYPEPARS_MAXSPEED_LAT_SET
const int VTYPEPARS_EMISSIONCLASS_SET
const int VTYPEPARS_PROBABILITY_SET
const int VTYPEPARS_CAR_FOLLOW_MODEL
const int VTYPEPARS_MINGAP_LAT_SET
const int VTYPEPARS_WIDTH_SET
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
StringBijection< SUMOVehicleShape > SumoVehicleShapeStrings(sumoVehicleShapeStringInitializer, SVS_UNKNOWN, false)
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
const std::string DEFAULT_PEDTYPE_ID
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
@ SVS_UNKNOWN
not defined
const std::string DEFAULT_CONTAINERTYPE_ID
const int VEHPARS_DEPARTEDGE_SET
const int VEHPARS_PROB_SET
const int VEHPARS_VPH_SET
const int VEHPARS_END_SET
const int VEHPARS_ROUTE_SET
const int VEHPARS_COLOR_SET
DepartLaneDefinition
Possible ways to choose a lane on depart.
const int VEHPARS_TO_TAZ_SET
ArrivalSpeedDefinition
Possible ways to choose the arrival speed.
DepartPosLatDefinition
DepartPosDefinition
Possible ways to choose the departure position.
const int VEHPARS_SPEEDFACTOR_SET
ArrivalLaneDefinition
Possible ways to choose the arrival lane.
const int VEHPARS_DEPARTPOS_SET
const int VEHPARS_CONTAINER_NUMBER_SET
const int VEHPARS_ARRIVALLANE_SET
DepartSpeedDefinition
Possible ways to choose the departure speed.
const int VEHPARS_DEPARTLANE_SET
const int VEHPARS_ARRIVALPOSLAT_SET
DepartEdgeDefinition
Possible ways to choose the departure edge.
const int VEHPARS_FROM_TAZ_SET
const int VEHPARS_NUMBER_SET
const int VEHPARS_ARRIVALSPEED_SET
const int VEHPARS_FORCE_REROUTE
ArrivalPosDefinition
Possible ways to choose the arrival position.
@ RANDOM
The arrival position is chosen randomly.
@ MAX
The maximum arrival position is used.
@ CENTER
Half the road length.
const int VEHPARS_LINE_SET
const int VEHPARS_PERSON_NUMBER_SET
const int VEHPARS_DEPARTSPEED_SET
const int VEHPARS_PERIOD_SET
ArrivalPosLatDefinition
Possible ways to choose the departure position.
const int VEHPARS_VTYPE_SET
const int VEHPARS_ARRIVALPOS_SET
const int VEHPARS_DEPARTPOSLAT_SET
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_CF_KRAUSS
@ SUMO_TAG_CF_BKERNER
@ SUMO_TAG_CF_KRAUSSX
@ SUMO_TAG_CF_CACC
@ SUMO_TAG_VTYPE
description of a vehicle type
@ SUMO_TAG_WALK
@ SUMO_TAG_NOTHING
invalid tag
@ SUMO_TAG_CF_CC
@ SUMO_TAG_CF_KRAUSS_PLUS_SLOPE
@ SUMO_TAG_CF_IDM
@ SUMO_TAG_CF_W99
@ SUMO_TAG_CF_RAIL
@ SUMO_TAG_CF_SMART_SK
@ SUMO_TAG_CF_PWAGNER2009
@ SUMO_TAG_CF_KRAUSS_ORIG1
@ SUMO_TAG_CF_WIEDEMANN
@ SUMO_TAG_FLOW
a flow definitio nusing a from-to edges instead of a route (used by router)
@ SUMO_TAG_CONTAINER
@ SUMO_TAG_PERSON
@ SUMO_TAG_CF_IDMM
@ SUMO_TAG_CF_DANIEL1
@ SUMO_TAG_CF_ACC
LaneChangeModel
@ LCM_SL2015
@ LCM_LC2013
@ LCM_DEFAULT
@ LCM_DK2008
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_TMP4
@ SUMO_ATTR_CF_W99_CC9
@ SUMO_ATTR_GCC_GAIN_GAP_DOT_CACC
@ SUMO_ATTR_CF_W99_CC5
@ SUMO_ATTR_LCA_PUSHY
@ SUMO_ATTR_CF_CC_FLATBED_KP
@ SUMO_ATTR_NUMBER
@ SUMO_ATTR_ARRIVALSPEED
@ SUMO_ATTR_GCC_GAIN_SPEED
@ SUMO_ATTR_EMISSIONCLASS
@ SUMO_ATTR_JM_IGNORE_FOE_SPEED
@ SUMO_ATTR_ARRIVALLANE
@ SUMO_ATTR_DEPART
@ SUMO_ATTR_CF_CC_LAMBDA
@ SUMO_ATTR_DEPARTEDGE
@ SUMO_ATTR_CF_CC_FLATBED_D
@ SUMO_ATTR_VEHSPERHOUR
@ SUMO_ATTR_JM_IGNORE_KEEPCLEAR_TIME
@ SUMO_ATTR_LCA_COOPERATIVE_SPEED
@ SUMO_ATTR_CF_CC_FLATBED_KA
@ SUMO_ATTR_CF_CC_PLOEG_KP
@ SUMO_ATTR_CF_WIEDEMANN_SECURITY
@ SUMO_ATTR_LCA_ASSERTIVE
@ SUMO_ATTR_LCA_LANE_DISCIPLINE
@ SUMO_ATTR_TRAIN_TYPE
@ SUMO_ATTR_CF_IDMM_ADAPT_TIME
@ SUMO_ATTR_LANE_CHANGE_MODEL
@ SUMO_ATTR_CF_KERNER_PHI
@ SUMO_ATTR_LCA_TURN_ALIGNMENT_DISTANCE
@ SUMO_ATTR_GC_GAIN_SPACE
@ SUMO_ATTR_JM_STOPLINE_GAP
@ SUMO_ATTR_DEPARTPOS_LAT
@ SUMO_ATTR_LCA_PUSHYGAP
@ SUMO_ATTR_CA_GAIN_GAP_CACC
@ SUMO_ATTR_LCA_LOOKAHEADLEFT
@ SUMO_ATTR_APPARENTDECEL
@ SUMO_ATTR_MAXSPEED_LAT
@ SUMO_ATTR_GC_GAIN_GAP_DOT_CACC
@ SUMO_ATTR_LCA_SPEEDGAIN_PARAM
@ SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_TMP3
@ SUMO_ATTR_ACTIONSTEPLENGTH
@ SUMO_ATTR_CF_CC_PLOEG_H
@ SUMO_ATTR_LCA_IMPATIENCE
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_MINGAP
@ SUMO_ATTR_LCA_COOPERATIVE_ROUNDABOUT
@ SUMO_ATTR_CA_GAIN_GAP_DOT_CACC
@ SUMO_ATTR_JM_DRIVE_AFTER_RED_TIME
@ SUMO_ATTR_HEADWAY_TIME_CACC_TO_ACC
@ SUMO_ATTR_CF_CC_OMEGAN
@ SUMO_ATTR_CONTAINER_NUMBER
@ SUMO_ATTR_CF_CC_C1
@ SUMO_ATTR_TMP2
@ SUMO_ATTR_CF_W99_CC8
@ SUMO_ATTR_CA_GAIN_SPACE
@ SUMO_ATTR_LINE
@ SUMO_ATTR_LOADING_DURATION
@ SUMO_ATTR_CF_IDM_DELTA
@ SUMO_ATTR_LCA_SPEEDGAIN_LOOKAHEAD
@ SUMO_ATTR_LCA_MAXSPEEDLATFACTOR
@ SUMO_ATTR_MANEUVER_ANGLE_TIMES
Class specific timing values for vehicle manoeuvering through angle ranges.
@ SUMO_ATTR_CF_CC_CCACCEL
@ SUMO_ATTR_CF_PWAGNER2009_TAULAST
@ SUMO_ATTR_CF_CC_PLOEG_KD
@ SUMO_ATTR_CF_CC_TAU
@ SUMO_ATTR_GC_GAIN_GAP_CACC
@ SUMO_ATTR_DEPARTPOS
@ SUMO_ATTR_CAR_FOLLOW_MODEL
@ SUMO_ATTR_DECEL
@ SUMO_ATTR_LCA_MAXSPEEDLATSTANDING
@ SUMO_ATTR_JM_DRIVE_AFTER_YELLOW_TIME
@ SUMO_ATTR_LCA_KEEPRIGHT_PARAM
@ SUMO_ATTR_GUISHAPE
@ SUMO_ATTR_REROUTE
@ SUMO_ATTR_JM_IGNORE_FOE_PROB
@ SUMO_ATTR_CONTAINER_CAPACITY
@ SUMO_ATTR_CF_CC_XI
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_LCA_COOPERATIVE_PARAM
@ SUMO_ATTR_LCA_OPPOSITE_PARAM
@ SUMO_ATTR_TO_TAZ
@ SUMO_ATTR_CF_CC_CCDECEL
@ SUMO_ATTR_DEPARTSPEED
@ SUMO_ATTR_GCC_GAIN_SPACE
@ SUMO_ATTR_MINGAP_LAT
@ SUMO_ATTR_EMERGENCYDECEL
@ SUMO_ATTR_CF_CC_FLATBED_H
@ SUMO_ATTR_CF_W99_CC3
@ SUMO_ATTR_CF_CC_LANES_COUNT
@ SUMO_ATTR_HEIGHT
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_LCA_SUBLANE_PARAM
@ SUMO_ATTR_JM_CROSSING_GAP
@ SUMO_ATTR_LCA_SIGMA
@ SUMO_ATTR_LATALIGNMENT
@ SUMO_ATTR_FROM_TAZ
@ SUMO_ATTR_CF_IDM_STEPPING
@ SUMO_ATTR_DEPARTLANE
@ SUMO_ATTR_CF_IDMM_ADAPT_FACTOR
@ SUMO_ATTR_IMPATIENCE
@ SUMO_ATTR_COLLISION_MINGAP_FACTOR
@ SUMO_ATTR_VCLASS
@ SUMO_ATTR_ACCEL
@ SUMO_ATTR_BOARDING_DURATION
@ SUMO_ATTR_CF_CC_CONSTSPACING
@ SUMO_ATTR_CF_W99_CC2
@ SUMO_ATTR_CF_W99_CC4
@ SUMO_ATTR_JM_SIGMA_MINOR
@ SUMO_ATTR_CF_W99_CC6
@ SUMO_ATTR_PROB
@ SUMO_ATTR_SPEEDFACTOR
@ SUMO_ATTR_CA_GAIN_SPEED
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_CF_CC_KP
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_ROUTE
@ SUMO_ATTR_PERSON_NUMBER
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_CF_PWAGNER2009_APPROB
@ SUMO_ATTR_MAXSPEED
@ SUMO_ATTR_ID
@ SUMO_ATTR_SIGMA
@ SUMO_ATTR_K
@ SUMO_ATTR_TMP1
@ SUMO_ATTR_OSGFILE
@ SUMO_ATTR_LCA_OVERTAKE_RIGHT
@ SUMO_ATTR_ARRIVALPOS_LAT
@ SUMO_ATTR_LCA_ACCEL_LAT
@ SUMO_ATTR_CF_W99_CC7
@ SUMO_ATTR_LCA_STRATEGIC_PARAM
@ SUMO_ATTR_CF_W99_CC1
@ SUMO_ATTR_TAU
@ SUMO_ATTR_IMGFILE
@ SUMO_ATTR_WIDTH
@ SUMO_ATTR_PERSON_CAPACITY
@ SUMO_ATTR_GC_GAIN_SPEED
@ SUMO_ATTR_GCC_GAIN_GAP_CACC
@ SUMO_ATTR_LCA_EXPERIMENTAL1
@ SUMO_ATTR_SC_GAIN
@ SUMO_ATTR_TMP5
@ SUMO_ATTR_SC_GAIN_CACC
@ SUMO_ATTR_JM_DRIVE_RED_SPEED
@ SUMO_ATTR_LCA_TIME_TO_IMPATIENCE
@ SUMO_ATTR_JM_TIMEGAP_MINOR
@ SUMO_ATTR_CF_CC_FLATBED_KV
@ SUMO_ATTR_SPEEDDEV
@ SUMO_ATTR_CF_WIEDEMANN_ESTIMATION
@ SUMO_ATTR_PERSONSPERHOUR
@ SUMO_ATTR_LCA_SPEEDGAINRIGHT
bool gSimulation
Definition: StdDefs.cpp:28
T MAX2(T a, T b)
Definition: StdDefs.h:79
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
void parse(const std::string &description, const bool hardFail)
Overwrite by parsable distribution description.
std::vector< double > & getParameter()
Returns the parameters of this distribution.
bool isValid(std::string &error)
check whether the distribution is valid
static bool isAbsolute(const std::string &path)
Returns the information whether the given path is absolute.
static std::string getConfigurationRelative(const std::string &configPath, const std::string &path)
Returns the second path as a relative path to the first file.
static SUMOEmissionClass getClassByName(const std::string &eClass, const SUMOVehicleClass vc=SVC_IGNORING)
Checks whether the string describes a known vehicle class.
static const RGBColor YELLOW
Definition: RGBColor.h:183
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:194
static double rand(std::mt19937 *rng=nullptr)
Returns a random real number in [0, 1)
Definition: RandHelper.h:51
Encapsulated SAX-Attributes.
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 std::string & getObjectType() const
return the objecttype to which these attributes belong
virtual std::string getName(int attr) const =0
Converts the given attribute id into a man readable string.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
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.
Structure representing possible vehicle parameter.
double width
This class' width.
SubParams cfParameter
Car-following parameter.
double defaultProbability
The probability when being added to a distribution without an explicit probability.
SUMOTime actionStepLength
The vehicle type's default actionStepLength [ms], i.e. the interval between two control actions....
double height
This class' height.
SUMOEmissionClass emissionClass
The emission class of this vehicle.
double length
The physical vehicle length.
double maxSpeedLat
The vehicle type's maximum lateral speed [m/s].
LateralAlignment latAlignment
The vehicles desired lateral alignment.
RGBColor color
The color.
double minGap
This class' free space in front of the vehicle itself.
std::string imgFile
Image file for this class.
SUMOVehicleShape shape
This class' shape.
int personCapacity
The person capacity of the vehicle.
Distribution_Parameterized speedFactor
The factor by which the maximum speed may deviate from the allowed max speed on the street.
std::string osgFile
3D model file for this class
double maxSpeed
The vehicle type's maximum speed [m/s].
int parametersSet
Information for the router which parameter were set.
int containerCapacity
The container capacity of the vehicle.
SUMOTime boardingDuration
The time a person needs to board the vehicle.
double minGapLat
The vehicle type's minimum lateral gap [m].
SUMOTime loadingDuration
The time a container needs to get loaded on the vehicle.
std::string id
The vehicle type's id.
SumoXMLTag cfModel
The enum-representation of the car-following model to use.
SubParams lcParameter
Lane-changing parameter.
SubParams jmParameter
Junction-model parameter.
double impatience
The vehicle's impatience (willingness to obstruct others)
std::map< int, std::pair< SUMOTime, SUMOTime > > myManoeuverAngleTimes
Map of manoeuver angles versus the times (entry, exit) to execute the manoeuver.
LaneChangeModel lcModel
The lane-change model to use.
Structure representing possible vehicle parameter.
double departPosLat
(optional) The lateral position the vehicle shall depart from
double arrivalPosLat
(optional) The lateral position the vehicle shall arrive on
double repetitionProbability
The probability for emitting a vehicle per second.
int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
int departLane
(optional) The lane the vehicle shall depart from (index in edge)
ArrivalSpeedDefinition arrivalSpeedProcedure
Information how the vehicle's end speed shall be chosen.
double departSpeed
(optional) The initial speed of the vehicle
SumoXMLTag tag
The vehicle tag.
std::string vtypeid
The vehicle's type id.
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
double speedFactor
individual speedFactor (overriding distribution from vType)
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.
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.
ArrivalLaneDefinition arrivalLaneProcedure
Information how the vehicle shall choose the lane to arrive on.
DepartLaneDefinition departLaneProcedure
Information how the vehicle shall choose the lane to depart from.
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.
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 personNumber
The static number of persons in the vehicle when it departs (not including boarding persons)
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.
DepartPosLatDefinition departPosLatProcedure
Information how the vehicle shall choose the lateral departure position.
SUMOTime repetitionEnd
The time at which the flow ends (only needed when using repetitionProbability)
double departPos
(optional) The position the vehicle shall depart from
DepartSpeedDefinition departSpeedProcedure
Information how the vehicle's initial speed shall be chosen.
RGBColor color
The vehicle's color, TraCI may change this.
double arrivalPos
(optional) The position the vehicle shall arrive on
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.
std::string routeid
The vehicle's route id.
std::string id
The vehicle's id.
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.
int departEdge
(optional) The initial edge within the route of the vehicle
ArrivalPosDefinition arrivalPosProcedure
Information how the vehicle shall choose the arrival position.
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.
DepartEdgeDefinition departEdgeProcedure
Information how the vehicle's initial edge shall be chosen.
std::string toTaz
The vehicle's destination zone (district)
double arrivalSpeed
(optional) The final speed of the vehicle (not used yet)
static double interpretEdgePos(double pos, double maximumValue, SumoXMLAttr attr, const std::string &id, bool silent=false)
Interprets negative edge positions and fits them onto a given edge.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
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.
std::string fromTaz
The vehicle's origin zone (district)
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
std::string line
The vehicle's line (mainly for public transport)
static bool parseDepartEdge(const std::string &val, const std::string &element, const std::string &id, int &edgeIndex, DepartEdgeDefinition &ded, std::string &error)
Validates a given departEdge value.
int containerNumber
The static number of containers in the vehicle when it departs.
ArrivalPosLatDefinition arrivalPosLatProcedure
Information how the vehicle shall choose the lateral arrival position.
static const CFAttrMap & getAllowedCFModelAttrs()
returns allowed attrs for each known CF-model (init on first use)
static SUMOVehicleParameter * handleError(const bool hardFail, bool &abortCreation, const std::string &message)
handle error loading SUMOVehicleParameter
static SUMOVTypeParameter * beginVTypeParsing(const SUMOSAXAttributes &attrs, const bool hardFail, const std::string &file)
Starts to parse a vehicle type.
static bool parseVTypeEmbedded(SUMOVTypeParameter &into, const SumoXMLTag element, const SUMOSAXAttributes &attrs, const bool hardFail, const bool fromVType=false)
Parses an element embedded in vtype definition.
std::map< SumoXMLTag, std::set< SumoXMLAttr > > CFAttrMap
Car-Following attributes map.
static std::string parseID(const SUMOSAXAttributes &attrs, const SumoXMLTag element)
parse ID
static SUMOTime processActionStepLength(double given)
Checks and converts given value for the action step length from seconds to miliseconds assuring it be...
std::map< LaneChangeModel, std::set< SumoXMLAttr > > LCAttrMap
Lane-Change-Model attributes map.
static SUMOVehicleParameter * parseFlowAttributes(SumoXMLTag tag, const SUMOSAXAttributes &attrs, const bool hardFail, const SUMOTime beginDefault, const SUMOTime endDefault, bool isPerson=false)
Parses a flow's attributes.
static double parseWalkPos(SumoXMLAttr attr, const bool hardFail, const std::string &id, double maxPos, const std::string &val, std::mt19937 *rng=0)
parse departPos or arrivalPos for a walk
static void parseCommonAttributes(const SUMOSAXAttributes &attrs, const bool hardFail, SUMOVehicleParameter *ret, std::string element)
Parses attributes common to vehicles and flows.
static SUMOVehicleShape parseGuiShape(const SUMOSAXAttributes &attrs, const std::string &id)
Parses the vehicle class.
static bool parseJMParams(SUMOVTypeParameter &into, const SUMOSAXAttributes &attrs, const bool hardFail)
Parses junction model attributes.
static std::set< SumoXMLAttr > allowedJMAttrs
allowed attrs for the junction model
static SUMOVehicleClass parseVehicleClass(const SUMOSAXAttributes &attrs, const std::string &id)
Parses the vehicle class.
static bool parseAngleTimesMap(SUMOVTypeParameter &vtype, const std::string, const bool hardFail)
Parse string containing AngleTimes triplets (angle, entry time, exit time)
static bool parseLCParams(SUMOVTypeParameter &into, LaneChangeModel model, const SUMOSAXAttributes &attrs, const bool hardFail)
Parses lane change model attributes.
static LCAttrMap allowedLCModelAttrs
allowed attrs for each known LC-model
static SUMOVehicleParameter * parseVehicleAttributes(int element, const SUMOSAXAttributes &attrs, const bool hardFail, const bool optionalID=false, const bool skipDepart=false)
Parses a vehicle's attributes.
static CFAttrMap allowedCFModelAttrs
allowed attrs for each known CF-model
static StringBijection< SumoXMLTag > CarFollowModels
car following models
static bool isValidVehicleID(const std::string &value)
whether the given string is a valid id for a vehicle or flow
static StringBijection< TrainType > TrainTypes
train types
static StringBijection< int > Tags
The names of SUMO-XML elements for use in netbuild.
static StringBijection< LaneChangeModel > LaneChangeModels
lane change models
static StringBijection< LateralAlignment > LateralAlignments
lateral alignments
T get(const std::string &str) const
int size() const
returns the number of existing substrings
std::string get(int pos) const
returns the item at the given position
bool hasNext()
returns the information whether further substrings exist
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter,...