/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-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 NIImporter_MATSim.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @date Tue, 26.04.201117///18// Importer for networks stored in MATSim format19/****************************************************************************/20#pragma once21#include <config.h>2223#include <string>24#include <map>25#include <netbuild/NBCapacity2Lanes.h>26#include <utils/xml/SUMOSAXHandler.h>27#include <utils/common/UtilExceptions.h>282930// ===========================================================================31// class declarations32// ===========================================================================33class NBEdge;34class NBEdgeCont;35class NBNetBuilder;36class NBNode;37class NBNodeCont;38class NBTrafficLightLogicCont;39class NBTypeCont;40class OptionsCont;414243// ===========================================================================44// class definitions45// ===========================================================================46/**47* @class NIImporter_MATSim48* @brief Importer for networks stored in MATSim format49*50*/51class NIImporter_MATSim {52public:53/** @brief Loads content of the optionally given MATSIM network files54*55* If the option "matsim-files" is set, the file(s) stored therein is read and56* the network definition stored therein is stored within the given network57* builder.58*59* If the option "matsim-files" is not set, this method simply returns.60*61* @param[in] oc The options to use62* @param[in] nb The network builder to fill63*/64static void loadNetwork(const OptionsCont& oc, NBNetBuilder& nb);656667private:68/**69* @class NodesHandler70* @brief A class which extracts MATSIM-nodes from a parsed MATSIM-file71*/72class NodesHandler : public GenericSAXHandler {73public:74/** @brief Contructor75* @param[in] toFill The nodes container to fill76*/77NodesHandler(NBNodeCont& toFill);787980/// @brief Destructor81~NodesHandler();828384protected:85/// @name inherited from GenericSAXHandler86//@{8788/** @brief Called on the opening of a tag;89*90* @param[in] element ID of the currently opened element91* @param[in] attrs Attributes within the currently opened element92* @exception ProcessError If something fails93* @see GenericSAXHandler::myStartElement94*/95void myStartElement(int element, const SUMOSAXAttributes& attrs);96//@}979899private:100/// @brief The nodes container to fill101NBNodeCont& myNodeCont;102103104private:105/** @brief invalidated copy constructor */106NodesHandler(const NodesHandler& s);107108/** @brief invalidated assignment operator */109NodesHandler& operator=(const NodesHandler& s);110111};112113114115/**116* @class EdgesHandler117* @brief A class which extracts MATSIM-edges from a parsed MATSIM-file118*/119class EdgesHandler : public GenericSAXHandler {120public:121/** @brief Constructor122*123* @param[in] nc The node container to retrieve nodes form124* @param[in, out] toFill The edges container to fill with read edges125* @param[in] keepEdgeLengths Whether the loaded lengths shal be used126* @param[in] lanesFromCapacity Whether the lane number shall be computed from the capacity127* @param[in] capacity2Lanes The converter from flow to lanes128*/129EdgesHandler(NBNodeCont& nc, NBEdgeCont& toFill,130bool keepEdgeLengths, bool lanesFromCapacity,131NBCapacity2Lanes capacity2Lanes);132133134/// @brief Destructor135~EdgesHandler();136137138protected:139/// @name inherited from GenericSAXHandler140//@{141142/** @brief Called on the opening of a tag;143*144* @param[in] element ID of the currently opened element145* @param[in] attrs Attributes within the currently opened element146* @exception ProcessError If something fails147* @see GenericSAXHandler::myStartElement148*/149void myStartElement(int element, const SUMOSAXAttributes& attrs);150//@}151152private:153void insertEdge(const std::string& id, NBNode* fromNode, NBNode* toNode, double freeSpeed, int numLanes, double capacity, double length, SVCPermissions perm = SVCAll);154SVCPermissions computePermission(std::string modes);155156private:157/// @brief The previously parsed nodes158NBNodeCont& myNodeCont;159160/// @brief The edge container to fill161NBEdgeCont& myEdgeCont;162163/// @brief The capacity norming164double myCapacityNorm;165166/// @brief Whether the loaded lengths shal be used167bool myKeepEdgeLengths;168169/// @brief Whether the lane number shall be computed from the capacity170bool myLanesFromCapacity;171172/// @brief The converter from flow to lanes173NBCapacity2Lanes myCapacity2Lanes;174175176private:177/** @brief invalidated copy constructor */178EdgesHandler(const EdgesHandler& s);179180/** @brief invalidated assignment operator */181EdgesHandler& operator=(const EdgesHandler& s);182183};184185186/**187* @enum MatsimXMLTag188* @brief Numbers representing MATSIM-XML - element names189* @see GenericSAXHandler190*/191enum MatsimXMLTag {192MATSIM_TAG_NOTHING = 0,193MATSIM_TAG_NETWORK,194MATSIM_TAG_NODE,195MATSIM_TAG_LINK,196MATSIM_TAG_LINKS197};198199200/**201* @enum MatsimXMLAttr202* @brief Numbers representing MATSIM-XML - attributes203* @see GenericSAXHandler204*/205enum MatsimXMLAttr {206MATSIM_ATTR_NOTHING = 0,207MATSIM_ATTR_ID,208MATSIM_ATTR_X,209MATSIM_ATTR_Y,210MATSIM_ATTR_FROM,211MATSIM_ATTR_TO,212MATSIM_ATTR_LENGTH,213MATSIM_ATTR_FREESPEED,214MATSIM_ATTR_CAPACITY,215MATSIM_ATTR_PERMLANES,216MATSIM_ATTR_ONEWAY,217MATSIM_ATTR_MODES,218MATSIM_ATTR_ORIGID,219MATSIM_ATTR_CAPPERIOD,220MATSIM_ATTR_CAPDIVIDER221};222223/// The names of MATSIM-XML elements (for passing to GenericSAXHandler)224static SequentialStringBijection::Entry matsimTags[];225226/// The names of MATSIM-XML attributes (for passing to GenericSAXHandler)227static SequentialStringBijection::Entry matsimAttrs[];228229230};231232233