Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/vehicle/SUMOVehicleParserHelper.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2008-2025 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
/****************************************************************************/
14
/// @file SUMOVehicleParserHelper.h
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @author Laura Bieker
19
/// @date Mon, 07.04.2008
20
///
21
// Helper methods for parsing vehicle attributes
22
/****************************************************************************/
23
#pragma once
24
#include <config.h>
25
26
#include <random>
27
#include <string>
28
#include <utils/common/SUMOTime.h>
29
#include <utils/xml/SUMOXMLDefinitions.h>
30
31
32
// ===========================================================================
33
// class declarations
34
// ===========================================================================
35
class SUMOSAXAttributes;
36
class SUMOVehicleParameter;
37
class SUMOVTypeParameter;
38
39
40
// ===========================================================================
41
// class definitions
42
// ===========================================================================
43
/**
44
* @class SUMOVehicleParserHelper
45
* @brief Helper methods for parsing vehicle attributes
46
*
47
* This class supports helper methods for parsing a vehicle's attributes.
48
*/
49
class SUMOVehicleParserHelper {
50
51
public:
52
/** @brief Parses a flow's attributes
53
*
54
* Parses all attributes stored in "SUMOVehicleParameter".
55
*
56
* @see SUMOVehicleParameter
57
* @param[in] tag SumoXMLTag (used in netedit)
58
* @param[in] attr The SAX-attributes to get vehicle parameter from
59
* @param[in] hardFail enable or disable hard fails if a parameter is invalid
60
* @param[in] needID check if flow needs an Id (used by Calibrator flows)
61
* @param[in] allowInternalRoutes whether references to internal routes are allowed in this context
62
* @return The parsed attribute structure if no error occurred, 0 otherwise
63
* @exception ProcessError If an attribute's value is invalid
64
* @note: the caller is responsible for deleting the returned pointer
65
*/
66
static SUMOVehicleParameter* parseFlowAttributes(SumoXMLTag tag, const SUMOSAXAttributes& attrs, const bool hardFail, const bool needID, const SUMOTime beginDefault, const SUMOTime endDefault, const bool allowInternalRoutes = false);
67
68
/** @brief Parses a vehicle's attributes
69
*
70
* Parses all attributes stored in "SUMOVehicleParameter".
71
*
72
* @see SUMOVehicleParameter
73
* @param[in] attr The SAX-attributes to get vehicle parameter from
74
* @param[in] hardFail enable or disable hard fails if a parameter is invalid
75
* @param[in] optionalID Whether the id shall be skipped (Used only in Calibrator Flows)
76
* @param[in] skipDepart Whether parsing the departure time shall be skipped
77
* @param[in] allowInternalRoutes whether references to internal routes are allowed in this context
78
* @return The parsed attribute structure if no error occurred, 0 otherwise
79
* @exception ProcessError If an attribute's value is invalid
80
* @note: the caller is responsible for deleting the returned pointer
81
*/
82
static SUMOVehicleParameter* parseVehicleAttributes(int element, const SUMOSAXAttributes& attrs, const bool hardFail, const bool optionalID = false, const bool skipDepart = false, const bool allowInternalRoutes = false);
83
84
/** @brief Starts to parse a vehicle type
85
*
86
* @param[in] attr The SAX-attributes to get vehicle parameter from
87
* @param[in] hardFail enable or disable hard fails if a parameter is invalid
88
* @param[in] file The name of the file being parsed (for resolving paths)
89
* @param[in] hardFail enable or disable hard fails if a parameter is invalid
90
* @exception ProcessError If an attribute's value is invalid and hardFail is enabled
91
* @see SUMOVTypeParameter
92
* @note: the caller is responsible for deleting the returned pointer
93
*/
94
static SUMOVTypeParameter* beginVTypeParsing(const SUMOSAXAttributes& attrs, const bool hardFail, const std::string& file);
95
96
/** @brief Parse string containing AngleTimes triplets (angle, entry time, exit time)
97
*
98
* @param[in] vtype - the vtype element constructed in the parser
99
* @param[in] string - containing , separated AngleTimes triplets "angle entry time exit time"
100
* @param[in] hardFail enable or disable hard fails if a parameter is invalid
101
* @exception ProcessError If an attribute's value is invalid
102
*
103
* @note if the map parameter set is an empty string then the vtype map will not be changed
104
*/
105
static bool parseAngleTimesMap(SUMOVTypeParameter* vtype, const std::string);
106
107
/** @brief Parses Car Following Mode params
108
*
109
* @param[in, filled] into The structure to fill with parsed values
110
* @param[in] element The id of the currently parsed XML-element
111
* @param[in] attr The SAX-attributes to get vehicle parameter from
112
* @param[in] hardFail enable or disable hard fails if a parameter is invalid
113
* @param[in] nestedCFM Whether the attributes are nested
114
* @exception ProcessError If an attribute's value is invalid
115
* @see SUMOVTypeParameter
116
*/
117
static bool parseCFMParams(SUMOVTypeParameter* into, const SumoXMLTag element, const SUMOSAXAttributes& attrs, const bool nestedCFM);
118
119
/// @brief Parses lane change model attributes
120
static bool parseLCParams(SUMOVTypeParameter* into, LaneChangeModel model, const SUMOSAXAttributes& attrs);
121
122
/// @brief Parses junction model attributes
123
static bool parseJMParams(SUMOVTypeParameter* into, const SUMOSAXAttributes& attrs);
124
125
/** @brief Parses the vehicle class
126
*
127
* When given, the vehicle class is parsed using getVehicleClassID.
128
* Exceptions occuring within this process are catched and reported.
129
*
130
* If no vehicle class is available in the attributes, the default class (SVC_IGNORING)
131
* is returned.
132
*
133
* @param[in] attrs The attributes to read the class from
134
* @param[in] id The id of the parsed element, for error message generation
135
* @return The parsed vehicle class
136
* @see SUMOVehicleClass
137
* @todo Recheck how errors are handled and what happens if they occure
138
*/
139
static SUMOVehicleClass parseVehicleClass(const SUMOSAXAttributes& attrs, const std::string& id);
140
141
/** @brief Parses the vehicle class
142
*
143
* When given, the vehicle class is parsed using getVehicleShapeID.
144
* Exceptions occuring within this process are catched and reported.
145
*
146
* If no vehicle class is available in the attributes, the default class (SVS_UNKNOWN)
147
* is returned.
148
*
149
* @param[in] attrs The attributes to read the class from
150
* @param[in] id The id of the parsed element, for error message generation
151
* @return The parsed vehicle shape
152
* @see SUMOVehicleShape
153
* @todo Recheck how errors are handled and what happens if they occure
154
*/
155
static SUMOVehicleShape parseGuiShape(const SUMOSAXAttributes& attrs, const std::string& id);
156
157
/// @brief parse departPos or arrivalPos for a walk
158
static double parseWalkPos(SumoXMLAttr attr, const bool hardFail, const std::string& id, double maxPos, const std::string& val, SumoRNG* rng = 0);
159
160
/** @brief Checks and converts given value for the action step length from seconds
161
* to miliseconds assuring it being a positive multiple of the simulation step width
162
*
163
* @param[in] given The value parsed from the configuration (seconds).
164
* @return The milisecond value rounded to the next positive multiple of the simulation step length.
165
*/
166
static SUMOTime processActionStepLength(double given);
167
168
/** @brief Checks whether the route ID uses the syntax of internal routes.
169
*
170
* @param[in] id The route ID to check.
171
* @return The given route ID follows the syntax of internal routes.
172
*/
173
static bool isInternalRouteID(const std::string& id);
174
175
176
/** @brief Parse string containing a vector of pairs
177
*
178
* @param[in] vtype - the vtype element constructed in the parser
179
* @param[in] atm - containing separated pairs "A1,B1 A2,B2"
180
* @param[in] attr - XML-attribute that is being parsed
181
* @exception ProcessError If an attribute's value is invalid
182
*
183
* @note if the vector parameter set is an empty string, then the vtype map will not be changed
184
*/
185
static bool validProfile(SUMOVTypeParameter* vtype, const std::string data, const SumoXMLAttr attr);
186
187
static int parseCarWalkTransfer(const OptionsCont& oc, const bool hasTaxi = false);
188
189
private:
190
/**@brief parse ID
191
* @return empty string if ID obtained from attrs isn't valid
192
*/
193
static std::string parseID(const SUMOSAXAttributes& attrs, const SumoXMLTag element);
194
195
/** @brief Parses attributes common to vehicles and flows
196
*
197
* Parses all attributes stored in "SUMOVehicleParameter".
198
*
199
* @see SUMOVehicleParameter
200
* @param[in] attr The SAX-attributes to get vehicle parameter from
201
* @param[out] ret The parameter to parse into
202
* @param[in] element The name of the element (vehicle or flow)
203
* @param[in] allowInternalRoutes Whether internal routes are valid in this context
204
* @exception ProcessError If an attribute's value is invalid
205
*/
206
static void parseCommonAttributes(const SUMOSAXAttributes& attrs, SUMOVehicleParameter* ret, SumoXMLTag tag, const bool allowInternalRoutes = false);
207
208
/// @brief handle error loading SUMOVehicleParameter
209
static SUMOVehicleParameter* handleVehicleError(const bool hardFail, SUMOVehicleParameter* vehicleParameter, const std::string message = "");
210
211
/// @brief handle error loading SUMOVTypeParameter
212
static SUMOVTypeParameter* handleVehicleTypeError(const bool hardFail, SUMOVTypeParameter* vehicleTypeParameter, const std::string message = "");
213
214
/// @brief Car-Following attributes map
215
typedef std::map<SumoXMLTag, std::set<SumoXMLAttr> > CFAttrMap;
216
217
/// @brief Lane-Change-Model attributes map
218
typedef std::map<LaneChangeModel, std::set<SumoXMLAttr> > LCAttrMap;
219
220
/// @brief returns allowed attrs for each known CF-model (init on first use)
221
static const CFAttrMap& getAllowedCFModelAttrs();
222
223
/// @brief allowed attrs for each known CF-model
224
static CFAttrMap allowedCFModelAttrs;
225
226
/// @brief allowed attrs for each known LC-model
227
static LCAttrMap allowedLCModelAttrs;
228
229
};
230
231