/****************************************************************************/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 RORouteHandler.h14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Mon, 9 Jul 200118///19// Parser and container for routes during their loading20/****************************************************************************/21#pragma once22#include <config.h>2324#include <string>25#include <vector>26#include <utils/distribution/RandomDistributor.h>27#include <utils/common/SUMOTime.h>28#include <utils/common/MapMatcher.h>29#include <utils/router/PedestrianRouter.h>30#include <utils/vehicle/SUMORouteHandler.h>31#include "ROPerson.h"323334// ===========================================================================35// class declarations36// ===========================================================================37class OutputDevice_String;38class ROEdge;39class ROLane;40class RONet;41class RORoute;42class RORouteDef;434445// ===========================================================================46// class definitions47// ===========================================================================48/**49* @class RORouteHandler50* @brief Parser and container for routes during their loading51*52* RORouteHandler is the container for routes while they are build until53* their transfering to the MSNet::RouteDict54* The result of the operations are single MSNet::Route-instances55*/56class RORouteHandler : public SUMORouteHandler, public MapMatcher<ROEdge, ROLane, RONode> {57public:58/// @brief standard constructor59RORouteHandler(RONet& net, const std::string& file,60const bool tryRepair,61const bool emptyDestinationsAllowed,62const bool ignoreErrors,63const bool checkSchema);6465/// @brief standard destructor66~RORouteHandler() override;6768/// @brief Checks whether the route file is sorted by departure time if needed69bool checkLastDepart() override;7071protected:72void deleteActivePlanAndVehicleParameter();7374/// @name inherited from GenericSAXHandler75//@{7677/** @brief Called on the opening of a tag;78*79* @param[in] element ID of the currently opened element80* @param[in] attrs Attributes within the currently opened element81* @exception ProcessError If something fails82* @see GenericSAXHandler::myStartElement83*/84void myStartElement(int element,85const SUMOSAXAttributes& attrs) override;86//@}8788/** @brief Called for parsing from and to and the corresponding taz attributes89*90* @param[in] element description of the currently opened element91* @param[in] attrs Attributes within the currently opened element92* @exception ProcessError If something fails93*/94void parseFromViaTo(SumoXMLTag tag, const SUMOSAXAttributes& attrs, bool& ok);9596/// @brief opens a type distribution for reading97void openVehicleTypeDistribution(const SUMOSAXAttributes& attrs) override;9899/// @brief closes (ends) the building of a distribution100void closeVehicleTypeDistribution() override;101102/// @brief opens a route for reading103void openRoute(const SUMOSAXAttributes& attrs) override;104105/// @brief opens a flow for reading106void openFlow(const SUMOSAXAttributes& attrs) override;107108/// @brief opens a route flow for reading109void openRouteFlow(const SUMOSAXAttributes& attrs) override;110111/// @brief opens a trip for reading112void openTrip(const SUMOSAXAttributes& attrs) override;113114/**@brief closes (ends) the building of a route.115* @note Afterwards no edges may be added to it;116* this method may throw exceptions when117* a) the route is empty or118* b) another route with the same id already exists119*/120void closeRoute(const bool mayBeDisconnected = false) override;121122/// @brief opens a route distribution for reading123void openRouteDistribution(const SUMOSAXAttributes& attrs) override;124125/// @brief closes (ends) the building of a distribution126void closeRouteDistribution() override;127128/// @brief Ends the processing of a vehicle129void closeVehicle() override;130131/// @brief Ends the processing of a vehicle type132void closeVType() override;133134/// @brief Ends the processing of a person135void closePerson() override;136137/// @brief Ends the processing of a personFlow138void closePersonFlow() override;139140/// @brief Ends the processing of a container141void closeContainer() override;142143/// @brief Ends the processing of a containerFlow144void closeContainerFlow() override;145146/// @brief Ends the processing of a flow147void closeFlow() override;148149/// @brief Ends the processing of a trip150void closeTrip() override;151152/// @brief retrieve stopping place element153const SUMOVehicleParameter::Stop* retrieveStoppingPlace(const SUMOSAXAttributes& attrs, const std::string& errorSuffix, std::string& id, const SUMOVehicleParameter::Stop* stopParam = nullptr);154155/// @brief Processing of a stop156Parameterised* addStop(const SUMOSAXAttributes& attrs) override;157158/// @brief Processing of a person from a personFlow159void addFlowPerson(const std::string& typeID, SUMOTime depart, const std::string& baseID, int i);160161/// @brief Processing of a ride162void addRide(const SUMOSAXAttributes& attrs) override;163164/// @brief Processing of a transport165void addTransport(const SUMOSAXAttributes& attrs) override;166167/// @brief Processing of a tranship168void addTranship(const SUMOSAXAttributes& attrs) override;169170/// @brief Parse edges from strings171void parseEdges(const std::string& desc, ConstROEdgeVector& into,172const std::string& rid, bool& ok);173174/// @brief add a routing request for a walking or intermodal person175void addPersonTrip(const SUMOSAXAttributes& attrs) override;176177/// @brief add a fully specified walk178void addWalk(const SUMOSAXAttributes& attrs) override;179180///@ brief parse depart- and arrival positions of a walk181void parseWalkPositions(const SUMOSAXAttributes& attrs, const std::string& personID,182const ROEdge* fromEdge, const ROEdge*& toEdge,183double& departPos, double& arrivalPos, std::string& busStopID,184const ROPerson::PlanItem* const lastStage, bool& ok);185186void initLaneTree(NamedRTree* tree) override;187188ROEdge* retrieveEdge(const std::string& id) override;189190protected:191/// @brief The current route192RONet& myNet;193194/// @brief The current route195ConstROEdgeVector myActiveRoute;196197/// @brief number of repetitions of the active route198int myActiveRouteRepeat;199SUMOTime myActiveRoutePeriod;200201/// @brief The plan of the current person202std::vector<ROPerson::PlanItem*>* myActivePlan;203204/// @brief The plan of the current container205OutputDevice_String* myActiveContainerPlan;206207/// @brief The number of stages in myActiveContainerPlan208int myActiveContainerPlanSize;209210/// @brief Information whether routes shall be repaired211const bool myTryRepair;212213/// @brief Information whether the "to" attribute is mandatory214const bool myEmptyDestinationsAllowed;215216/// @brief Depending on the "ignore-errors" option different outputs are used217MsgHandler* const myErrorOutput;218219/// @brief The begin time220const SUMOTime myBegin;221222/// @brief whether to keep the vtype distribution in output223const bool myKeepVTypeDist;224225/// @brief whether input is read all at once (no sorting check is necessary)226const bool myUnsortedInput;227228/// @brief The currently parsed distribution of vehicle types (probability->vehicle type)229RandomDistributor<SUMOVTypeParameter*>* myCurrentVTypeDistribution;230231/// @brief The id of the currently parsed vehicle type distribution232std::string myCurrentVTypeDistributionID;233234/// @brief The currently parsed route alternatives235RORouteDef* myCurrentAlternatives;236237/// @brief cached options238bool myUseTaz;239bool myWriteJunctions;240241private:242/// @brief Invalidated copy constructor243RORouteHandler(const RORouteHandler& s) = delete;244245/// @brief Invalidated assignment operator246RORouteHandler& operator=(const RORouteHandler& s) = delete;247};248249250