Path: blob/main/src/utils/vehicle/SUMOVehicleParserHelper.h
169678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file SUMOVehicleParserHelper.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @author Laura Bieker18/// @date Mon, 07.04.200819///20// Helper methods for parsing vehicle attributes21/****************************************************************************/22#pragma once23#include <config.h>2425#include <random>26#include <string>27#include <utils/common/SUMOTime.h>28#include <utils/xml/SUMOXMLDefinitions.h>293031// ===========================================================================32// class declarations33// ===========================================================================34class SUMOSAXAttributes;35class SUMOVehicleParameter;36class SUMOVTypeParameter;373839// ===========================================================================40// class definitions41// ===========================================================================42/**43* @class SUMOVehicleParserHelper44* @brief Helper methods for parsing vehicle attributes45*46* This class supports helper methods for parsing a vehicle's attributes.47*/48class SUMOVehicleParserHelper {4950public:51/** @brief Parses a flow's attributes52*53* Parses all attributes stored in "SUMOVehicleParameter".54*55* @see SUMOVehicleParameter56* @param[in] tag SumoXMLTag (used in netedit)57* @param[in] attr The SAX-attributes to get vehicle parameter from58* @param[in] hardFail enable or disable hard fails if a parameter is invalid59* @param[in] needID check if flow needs an Id (used by Calibrator flows)60* @param[in] allowInternalRoutes whether references to internal routes are allowed in this context61* @return The parsed attribute structure if no error occurred, 0 otherwise62* @exception ProcessError If an attribute's value is invalid63* @note: the caller is responsible for deleting the returned pointer64*/65static SUMOVehicleParameter* parseFlowAttributes(SumoXMLTag tag, const SUMOSAXAttributes& attrs, const bool hardFail, const bool needID, const SUMOTime beginDefault, const SUMOTime endDefault, const bool allowInternalRoutes = false);6667/** @brief Parses a vehicle's attributes68*69* Parses all attributes stored in "SUMOVehicleParameter".70*71* @see SUMOVehicleParameter72* @param[in] attr The SAX-attributes to get vehicle parameter from73* @param[in] hardFail enable or disable hard fails if a parameter is invalid74* @param[in] optionalID Whether the id shall be skipped (Used only in Calibrator Flows)75* @param[in] skipDepart Whether parsing the departure time shall be skipped76* @param[in] allowInternalRoutes whether references to internal routes are allowed in this context77* @return The parsed attribute structure if no error occurred, 0 otherwise78* @exception ProcessError If an attribute's value is invalid79* @note: the caller is responsible for deleting the returned pointer80*/81static SUMOVehicleParameter* parseVehicleAttributes(int element, const SUMOSAXAttributes& attrs, const bool hardFail, const bool optionalID = false, const bool skipDepart = false, const bool allowInternalRoutes = false);8283/** @brief Starts to parse a vehicle type84*85* @param[in] attr The SAX-attributes to get vehicle parameter from86* @param[in] hardFail enable or disable hard fails if a parameter is invalid87* @param[in] file The name of the file being parsed (for resolving paths)88* @param[in] hardFail enable or disable hard fails if a parameter is invalid89* @exception ProcessError If an attribute's value is invalid and hardFail is enabled90* @see SUMOVTypeParameter91* @note: the caller is responsible for deleting the returned pointer92*/93static SUMOVTypeParameter* beginVTypeParsing(const SUMOSAXAttributes& attrs, const bool hardFail, const std::string& file);9495/** @brief Parse string containing AngleTimes triplets (angle, entry time, exit time)96*97* @param[in] vtype - the vtype element constructed in the parser98* @param[in] string - containing , separated AngleTimes triplets "angle entry time exit time"99* @param[in] hardFail enable or disable hard fails if a parameter is invalid100* @exception ProcessError If an attribute's value is invalid101*102* @note if the map parameter set is an empty string then the vtype map will not be changed103*/104static bool parseAngleTimesMap(SUMOVTypeParameter* vtype, const std::string);105106/** @brief Parses Car Following Mode params107*108* @param[in, filled] into The structure to fill with parsed values109* @param[in] element The id of the currently parsed XML-element110* @param[in] attr The SAX-attributes to get vehicle parameter from111* @param[in] hardFail enable or disable hard fails if a parameter is invalid112* @param[in] nestedCFM Whether the attributes are nested113* @exception ProcessError If an attribute's value is invalid114* @see SUMOVTypeParameter115*/116static bool parseCFMParams(SUMOVTypeParameter* into, const SumoXMLTag element, const SUMOSAXAttributes& attrs, const bool nestedCFM);117118/// @brief Parses lane change model attributes119static bool parseLCParams(SUMOVTypeParameter* into, LaneChangeModel model, const SUMOSAXAttributes& attrs);120121/// @brief Parses junction model attributes122static bool parseJMParams(SUMOVTypeParameter* into, const SUMOSAXAttributes& attrs);123124/** @brief Parses the vehicle class125*126* When given, the vehicle class is parsed using getVehicleClassID.127* Exceptions occuring within this process are catched and reported.128*129* If no vehicle class is available in the attributes, the default class (SVC_IGNORING)130* is returned.131*132* @param[in] attrs The attributes to read the class from133* @param[in] id The id of the parsed element, for error message generation134* @return The parsed vehicle class135* @see SUMOVehicleClass136* @todo Recheck how errors are handled and what happens if they occure137*/138static SUMOVehicleClass parseVehicleClass(const SUMOSAXAttributes& attrs, const std::string& id);139140/** @brief Parses the vehicle class141*142* When given, the vehicle class is parsed using getVehicleShapeID.143* Exceptions occuring within this process are catched and reported.144*145* If no vehicle class is available in the attributes, the default class (SVS_UNKNOWN)146* is returned.147*148* @param[in] attrs The attributes to read the class from149* @param[in] id The id of the parsed element, for error message generation150* @return The parsed vehicle shape151* @see SUMOVehicleShape152* @todo Recheck how errors are handled and what happens if they occure153*/154static SUMOVehicleShape parseGuiShape(const SUMOSAXAttributes& attrs, const std::string& id);155156/// @brief parse departPos or arrivalPos for a walk157static double parseWalkPos(SumoXMLAttr attr, const bool hardFail, const std::string& id, double maxPos, const std::string& val, SumoRNG* rng = 0);158159/** @brief Checks and converts given value for the action step length from seconds160* to miliseconds assuring it being a positive multiple of the simulation step width161*162* @param[in] given The value parsed from the configuration (seconds).163* @return The milisecond value rounded to the next positive multiple of the simulation step length.164*/165static SUMOTime processActionStepLength(double given);166167/** @brief Checks whether the route ID uses the syntax of internal routes.168*169* @param[in] id The route ID to check.170* @return The given route ID follows the syntax of internal routes.171*/172static bool isInternalRouteID(const std::string& id);173174175/** @brief Parse string containing a vector of pairs176*177* @param[in] vtype - the vtype element constructed in the parser178* @param[in] atm - containing separated pairs "A1,B1 A2,B2"179* @param[in] attr - XML-attribute that is being parsed180* @exception ProcessError If an attribute's value is invalid181*182* @note if the vector parameter set is an empty string, then the vtype map will not be changed183*/184static bool validProfile(SUMOVTypeParameter* vtype, const std::string data, const SumoXMLAttr attr);185186static int parseCarWalkTransfer(const OptionsCont& oc, const bool hasTaxi = false);187188private:189/**@brief parse ID190* @return empty string if ID obtained from attrs isn't valid191*/192static std::string parseID(const SUMOSAXAttributes& attrs, const SumoXMLTag element);193194/** @brief Parses attributes common to vehicles and flows195*196* Parses all attributes stored in "SUMOVehicleParameter".197*198* @see SUMOVehicleParameter199* @param[in] attr The SAX-attributes to get vehicle parameter from200* @param[out] ret The parameter to parse into201* @param[in] element The name of the element (vehicle or flow)202* @param[in] allowInternalRoutes Whether internal routes are valid in this context203* @exception ProcessError If an attribute's value is invalid204*/205static void parseCommonAttributes(const SUMOSAXAttributes& attrs, SUMOVehicleParameter* ret, SumoXMLTag tag, const bool allowInternalRoutes = false);206207/// @brief handle error loading SUMOVehicleParameter208static SUMOVehicleParameter* handleVehicleError(const bool hardFail, SUMOVehicleParameter* vehicleParameter, const std::string message = "");209210/// @brief handle error loading SUMOVTypeParameter211static SUMOVTypeParameter* handleVehicleTypeError(const bool hardFail, SUMOVTypeParameter* vehicleTypeParameter, const std::string message = "");212213/// @brief Car-Following attributes map214typedef std::map<SumoXMLTag, std::set<SumoXMLAttr> > CFAttrMap;215216/// @brief Lane-Change-Model attributes map217typedef std::map<LaneChangeModel, std::set<SumoXMLAttr> > LCAttrMap;218219/// @brief returns allowed attrs for each known CF-model (init on first use)220static const CFAttrMap& getAllowedCFModelAttrs();221222/// @brief allowed attrs for each known CF-model223static CFAttrMap allowedCFModelAttrs;224225/// @brief allowed attrs for each known LC-model226static LCAttrMap allowedLCModelAttrs;227228};229230231