/****************************************************************************/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 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);120121122/** @brief Closes the net building process123*124* Builds the microsim-structures which belong to a MSNet using the factories125* filled while loading. Initialises the network using these structures by calling126* MSNet::closeBuilding.127* If an error occurs, all built structures are deleted and a ProcessError is thrown.128* @exception ProcessError If the loaded structures could not be built129*/130void buildNet();131132/// @brief build meanData definition based on option133void buildDefaultMeanData(const std::string& optionName, const std::string& id, bool useLanes);134135/**136* @class EdgeFloatTimeLineRetriever_EdgeTravelTime137* @brief Obtains edge efforts from a weights handler and stores them within the edges138* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever139*/140class EdgeFloatTimeLineRetriever_EdgeEffort : public SAXWeightsHandler::EdgeFloatTimeLineRetriever {141public:142/// @brief Constructor143EdgeFloatTimeLineRetriever_EdgeEffort(MSNet& net) : myNet(net) {}144145/// @brief Destructor146~EdgeFloatTimeLineRetriever_EdgeEffort() { }147148/** @brief Adds an effort for a given edge and time period149*150* @param[in] id The id of the object to add a weight for151* @param[in] val The effort152* @param[in] beg The begin of the interval the weight is valid for153* @param[in] end The end of the interval the weight is valid for154* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever::addEdgeWeight155*/156void addEdgeWeight(const std::string& id,157double val, double beg, double end) const;158159private:160/// @brief The network edges shall be obtained from161MSNet& myNet;162163};164165166/**167* @class EdgeFloatTimeLineRetriever_EdgeTravelTime168* @brief Obtains edge travel times from a weights handler and stores them within the edges169* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever170*/171class EdgeFloatTimeLineRetriever_EdgeTravelTime : public SAXWeightsHandler::EdgeFloatTimeLineRetriever {172public:173/// @brief Constructor174EdgeFloatTimeLineRetriever_EdgeTravelTime(MSNet& net) : myNet(net) {}175176/// @brief Destructor177~EdgeFloatTimeLineRetriever_EdgeTravelTime() { }178179/** @brief Adds a travel time for a given edge and time period180*181* @param[in] id The id of the object to add a weight for182* @param[in] val The travel time183* @param[in] beg The begin of the interval the weight is valid for184* @param[in] end The end of the interval the weight is valid for185* @see SAXWeightsHandler::EdgeFloatTimeLineRetriever::addEdgeWeight186*/187void addEdgeWeight(const std::string& id,188double val, double beg, double end) const;189190private:191/// @brief The network edges shall be obtained from192MSNet& myNet;193194};195196197protected:198/// @brief The options to get the names of the files to load and further information from199OptionsCont& myOptions;200201/// @brief The edge control builder to use202NLEdgeControlBuilder& myEdgeBuilder;203204/// @brief The junction control builder to use205NLJunctionControlBuilder& myJunctionBuilder;206207/// @brief The detector control builder to use208NLDetectorBuilder& myDetectorBuilder;209210/// @brief The net to fill211MSNet& myNet;212213/// @brief The handler used to parse the net214NLHandler& myXMLHandler;215216217private:218/// @brief invalidated copy operator219NLBuilder(const NLBuilder& s);220221/// @brief invalidated assignment operator222NLBuilder& operator=(const NLBuilder& s);223224};225226227