/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2026 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 NLBuilder.h14/// @author Daniel Krajzewicz15/// @author Michael Behrisch16/// @date Mon, 9 Jul 200117///18// The main interface for loading a microsim19/****************************************************************************/20#pragma once21#include <config.h>2223#include <string>24#include <map>25#include <vector>26#include <utils/xml/SAXWeightsHandler.h>272829// ===========================================================================30// class declarations31// ===========================================================================32class MSNet;33class NLContainer;34class MSJunctionLogic;35class MSDetectorControl;36class OptionsCont;37class NLHandler;38class NLEdgeControlBuilder;39class NLJunctionControlBuilder;40class NLDetectorBuilder;41class NLTriggerBuilder;42class SUMORouteLoader;43class SUMORouteLoaderControl;444546// ===========================================================================47// class definitions48// ===========================================================================49/**50* @class NLBuilder51* @brief The main interface for loading a microsim52*53* It is a black-box where only the options and factories must be supplied54* on the constructor call. An (empty) instance of the network must be55* supplied, too, and is filled during loading.56*/57class NLBuilder {58public:59/** @brief Constructor60*61* @param[in] oc The options to use62* @param[in, out] net The network to fill63* @param[in] eb The builder of edges to use64* @param[in] jb The builder of junctions to use65* @param[in] db The detector builder to use66* @param[in] tb The trigger builder to use67* @param[in] xmlHandler The xml handler to use68*/69NLBuilder(OptionsCont& oc, MSNet& net,70NLEdgeControlBuilder& eb, NLJunctionControlBuilder& jb,71NLDetectorBuilder& db,72NLHandler& xmlHandler);737475/// @brief Destructor76virtual ~NLBuilder();777879/** @brief Builds and initialises the simulation80*81* At first, the network is loaded and the built using "buildNet".82* If this could be done, additional information is loaded (state dump,83* weight files, route files, and additional files).84* If everything could be done, true is returned, otherwise false.85*86* @see buildNet87* @exception ProcessError If something fails on network building88* @todo Again, both returning a bool and throwing an exception; quite inconsistent89*/90virtual bool build();9192/**93* loads the net, additional routes and the detectors94*/95static MSNet* init(const bool isLibsumo = false);9697/// @brief initializes all RNGs98static void initRandomness();99100/** @brief Builds the route loader control101*102* Goes through the list of route files to open defined in the option103* "route-files" and builds loaders reading these files104* @param[in] oc The options to read the list of route files to open from105* @return The built route loader control106* @exception ProcessError If an error occurred107*/108static SUMORouteLoaderControl* buildRouteLoaderControl(const OptionsCont& oc);109110protected:111/** @brief Loads a described subpart form the given list of files112*113* Assuming the given string to be an option name behind which a list of files114* is stored, this method invokes an XML reader on all the files set for this option.115* @param[in] mmlWhat The option to get the file list from116* @param[in] isNet whether a network gets loaded117* @return Whether loading of all files was successful118*/119bool load(const std::string& mmlWhat, const bool isNet = false);120121/// @brief loads meso edge types with a dedicated handler and return whether any were loaded122bool loadMesoEdgeTypes(const std::string& mmlWhat);123124125/** @brief Closes the net building process126*127* Builds the microsim-structures which belong to a MSNet using the factories128* filled while loading. Initialises the network using these structures by calling129* MSNet::closeBuilding.130* If an error occurs, all built structures are deleted and a ProcessError is thrown.131* @exception ProcessError If the loaded structures could not be built132*/133void buildNet();134135/// @brief build meanData definition based on option136void buildDefaultMeanData(const std::string& optionName, const std::string& id, bool useLanes);137138/**139* @class EdgeFloatTimeLineRetriever_EdgeTravelTime140* @brief Obtains edge efforts from a weights handler and stores them within the edges141* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever142*/143class EdgeFloatTimeLineRetriever_EdgeEffort : public SAXWeightsHandler::EdgeFloatTimeLineRetriever {144public:145/// @brief Constructor146EdgeFloatTimeLineRetriever_EdgeEffort(MSNet& net) : myNet(net) {}147148/// @brief Destructor149~EdgeFloatTimeLineRetriever_EdgeEffort() { }150151/** @brief Adds an effort for a given edge and time period152*153* @param[in] id The id of the object to add a weight for154* @param[in] val The effort155* @param[in] beg The begin of the interval the weight is valid for156* @param[in] end The end of the interval the weight is valid for157* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever::addEdgeWeight158*/159void addEdgeWeight(const std::string& id,160double val, double beg, double end) const;161162private:163/// @brief The network edges shall be obtained from164MSNet& myNet;165166};167168169/**170* @class EdgeFloatTimeLineRetriever_EdgeTravelTime171* @brief Obtains edge travel times from a weights handler and stores them within the edges172* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever173*/174class EdgeFloatTimeLineRetriever_EdgeTravelTime : public SAXWeightsHandler::EdgeFloatTimeLineRetriever {175public:176/// @brief Constructor177EdgeFloatTimeLineRetriever_EdgeTravelTime(MSNet& net) : myNet(net) {}178179/// @brief Destructor180~EdgeFloatTimeLineRetriever_EdgeTravelTime() { }181182/** @brief Adds a travel time for a given edge and time period183*184* @param[in] id The id of the object to add a weight for185* @param[in] val The travel time186* @param[in] beg The begin of the interval the weight is valid for187* @param[in] end The end of the interval the weight is valid for188* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever::addEdgeWeight189*/190void addEdgeWeight(const std::string& id,191double val, double beg, double end) const;192193private:194/// @brief The network edges shall be obtained from195MSNet& myNet;196197};198199200protected:201/// @brief The options to get the names of the files to load and further information from202OptionsCont& myOptions;203204/// @brief The edge control builder to use205NLEdgeControlBuilder& myEdgeBuilder;206207/// @brief The junction control builder to use208NLJunctionControlBuilder& myJunctionBuilder;209210/// @brief The detector control builder to use211NLDetectorBuilder& myDetectorBuilder;212213/// @brief The net to fill214MSNet& myNet;215216/// @brief The handler used to parse the net217NLHandler& myXMLHandler;218219220private:221/// @brief invalidated copy operator222NLBuilder(const NLBuilder& s);223224/// @brief invalidated assignment operator225NLBuilder& operator=(const NLBuilder& s);226227};228229230