LCOV - code coverage report
Current view: top level - src/utils/vehicle - SUMORouteHandler.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 2 2
Test Date: 2026-10-12 15:53:19 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    SUMORouteHandler.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Jakob Erdmann
      17              : /// @author  Michael Behrisch
      18              : /// @date    Mon, 9 Jul 2001
      19              : ///
      20              : // Parser for routes during their loading
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : #include <utils/common/IDSupplier.h>
      26              : #include <utils/common/SUMOTime.h>
      27              : #include <utils/vehicle/SUMOVehicleParameter.h>
      28              : #include <utils/xml/SUMOSAXHandler.h>
      29              : 
      30              : 
      31              : // ===========================================================================
      32              : // class declarations
      33              : // ===========================================================================
      34              : class MsgHandler;
      35              : class SUMOVTypeParameter;
      36              : 
      37              : 
      38              : // ===========================================================================
      39              : // class definitions
      40              : // ===========================================================================
      41              : /**
      42              :  * @class SUMORouteHandler
      43              :  * @brief Parser for routes during their loading
      44              :  *
      45              :  * SUMORouteHandler is the abstract super class for routers
      46              :  * and simulation loading routes.
      47              :  */
      48              : class SUMORouteHandler : public SUMOSAXHandler {
      49              : public:
      50              :     /// @brief enum for stops
      51              :     enum StopPos {
      52              :         STOPPOS_VALID,
      53              :         STOPPOS_INVALID_STARTPOS,
      54              :         STOPPOS_INVALID_ENDPOS,
      55              :         STOPPOS_INVALID_LANELENGTH
      56              :     };
      57              : 
      58              :     /// @brief standard constructor
      59              :     SUMORouteHandler(const std::string& file, const std::string& expectedRoot, const bool hardFail);
      60              : 
      61              :     /// @brief standard destructor
      62              :     virtual ~SUMORouteHandler();
      63              : 
      64              :     /**@brief check start and end position of a stop
      65              :      * @brief return */
      66              :     static StopPos checkStopPos(double& startPos, double& endPos, const double laneLength, const double minLength, const bool friendlyPos);
      67              : 
      68              :     /// @brief returns the first departure time that was ever read
      69              :     SUMOTime getFirstDepart() const;
      70              : 
      71              :     /// @brief Returns the last loaded depart time
      72              :     SUMOTime getLastDepart() const;
      73              : 
      74              :     /// @brief get parsing RNG
      75              :     static SumoRNG* getParsingRNG() {
      76              :         return &myParsingRNG;
      77              :     }
      78              : 
      79              : protected:
      80              :     /// @name inherited from GenericSAXHandler
      81              :     //@{
      82              : 
      83              :     /** @brief Called on the opening of a tag;
      84              :      *
      85              :      * @param[in] element ID of the currently opened element
      86              :      * @param[in] attrs Attributes within the currently opened element
      87              :      * @exception ProcessError If something fails
      88              :      * @see GenericSAXHandler::myStartElement
      89              :      */
      90              :     virtual void myStartElement(int element,
      91              :                                 const SUMOSAXAttributes& attrs);
      92              : 
      93              :     /** @brief Called when a closing tag occurs
      94              :      *
      95              :      * @param[in] element ID of the currently opened element
      96              :      * @exception ProcessError If something fails
      97              :      * @see GenericSAXHandler::myEndElement
      98              :      */
      99              :     virtual void myEndElement(int element);
     100              :     //@}
     101              : 
     102              :     /// @name open element functions
     103              :     //@{
     104              : 
     105              :     /// @brief opens a type distribution for reading
     106              :     virtual void openVehicleTypeDistribution(const SUMOSAXAttributes& attrs) = 0;
     107              : 
     108              :     /// @brief closes (ends) the building of a distribution
     109              :     virtual void closeVehicleTypeDistribution() = 0;
     110              : 
     111              :     /// @brief opens a route for reading
     112              :     virtual void openRoute(const SUMOSAXAttributes& attrs) = 0;
     113              : 
     114              :     /// @brief opens a flow for reading
     115              :     virtual void openFlow(const SUMOSAXAttributes& attrs) = 0;
     116              : 
     117              :     /// @brief opens a route flow for reading
     118              :     virtual void openRouteFlow(const SUMOSAXAttributes& attrs) = 0;
     119              : 
     120              :     /// @brief opens a trip for reading
     121              :     virtual void openTrip(const SUMOSAXAttributes& attrs) = 0;
     122              :     //@}
     123              : 
     124              :     /// @name close element functions
     125              :     //@{
     126              : 
     127              :     /**closes (ends) the building of a route.
     128              :      * Afterwards no edges may be added to it;
     129              :      * this method may throw exceptions when
     130              :      * a) the route is empty or
     131              :      * b) another route with the same id already exists
     132              :      */
     133              :     virtual void closeRoute(const bool mayBeDisconnected = false) = 0;
     134              : 
     135              :     /// @brief opens a route distribution for reading
     136              :     virtual void openRouteDistribution(const SUMOSAXAttributes& attrs) = 0;
     137              : 
     138              :     /// @brief closes (ends) the building of a distribution
     139              :     virtual void closeRouteDistribution() = 0;
     140              : 
     141              :     /// @brief Ends the processing of a vehicle
     142              :     virtual void closeVehicle() = 0;
     143              : 
     144              :     /// @brief Ends the processing of a vehicle type
     145              :     virtual void closeVType() = 0;
     146              : 
     147              :     /// @brief Ends the processing of a person
     148              :     virtual void closePerson() = 0;
     149              : 
     150              :     /// @brief Ends the processing of a person flow
     151              :     virtual void closePersonFlow() = 0;
     152              : 
     153              :     /// @brief Ends the processing of a container
     154              :     virtual void closeContainer() = 0;
     155              : 
     156              :     /// @brief Ends the processing of a container flow
     157              :     virtual void closeContainerFlow() = 0;
     158              : 
     159              :     /// @brief Ends the processing of a flow
     160              :     virtual void closeFlow() = 0;
     161              : 
     162              :     /// @brief Ends the processing of a trip
     163              :     virtual void closeTrip() = 0;
     164              :     //@}
     165              : 
     166              :     /// @name add element functions
     167              :     //@{
     168              : 
     169              :     /// @brief Processing of a person or container
     170         3537 :     virtual void addTransportable(const SUMOSAXAttributes& attrs, const bool isPerson) {
     171              :         UNUSED_PARAMETER(attrs);
     172              :         UNUSED_PARAMETER(isPerson);
     173         3537 :     }
     174              : 
     175              :     /// @brief Processing of a stop
     176              :     virtual Parameterised* addStop(const SUMOSAXAttributes& attrs) = 0;
     177              : 
     178              :     /// @brief add a routing request for a walking or intermodal person
     179              :     virtual void addPersonTrip(const SUMOSAXAttributes& attrs) = 0;
     180              : 
     181              :     /// @brief add a fully specified walk
     182              :     virtual void addWalk(const SUMOSAXAttributes& attrs) = 0;
     183              : 
     184              :     /// @brief Processing of a ride
     185              :     virtual void addRide(const SUMOSAXAttributes& attrs) = 0;
     186              : 
     187              :     /// @brief Processing of a transport
     188              :     virtual void addTransport(const SUMOSAXAttributes& attrs) = 0;
     189              : 
     190              :     /// @brief Processing of a tranship
     191              :     virtual void addTranship(const SUMOSAXAttributes& attrs) = 0;
     192              : 
     193              :     //@}
     194              : 
     195              :     /// @brief Checks whether the route file is sorted by departure time if needed
     196              :     virtual bool checkLastDepart();
     197              : 
     198              :     /// @brief save last depart (only to be used if vehicle is not discarded)
     199              :     void registerLastDepart();
     200              : 
     201              :     /// @brief assign arbitrary vehicle parameters
     202              :     void addParam(const SUMOSAXAttributes& attrs);
     203              : 
     204              :     /// @brief parses attributes common to all stops
     205              :     bool parseStop(SUMOVehicleParameter::Stop& stop, const SUMOSAXAttributes& attrs, std::string errorSuffix, MsgHandler* const errorOutput);
     206              : 
     207              : protected:
     208              :     virtual const SUMOVTypeParameter* getVTypeParameter(const std::string& refid) = 0;
     209              : 
     210              : protected:
     211              :     /// @brief flag to enable or disable hard fails
     212              :     const bool myHardFail;
     213              : 
     214              :     /// @brief Parameter of the current vehicle, trip, person, container or flow
     215              :     SUMOVehicleParameter* myVehicleParameter;
     216              : 
     217              :     /// @brief The stack of currently parsed parameterised objects
     218              :     std::vector<Parameterised*> myParamStack;
     219              : 
     220              :     /// @brief The insertion time of the vehicle read last
     221              :     SUMOTime myLastDepart;
     222              : 
     223              :     /// @brief The id of the current route
     224              :     std::string myActiveRouteID;
     225              : 
     226              :     /// @brief The id of the route the current route references to
     227              :     std::string myActiveRouteRefID;
     228              : 
     229              :     /// @brief The probability of the current route
     230              :     double myActiveRouteProbability;
     231              : 
     232              :     /// @brief The currently parsed route's color
     233              :     const RGBColor* myActiveRouteColor;
     234              : 
     235              :     /// @brief The currently parsed route costs
     236              :     double myCurrentCosts;
     237              : 
     238              :     /// @brief List of the stops on the parsed route
     239              :     StopParVector myActiveRouteStops;
     240              : 
     241              :     /// @brief The currently parsed vehicle type
     242              :     SUMOVTypeParameter* myCurrentVType;
     243              : 
     244              :     /// @brief if the currently parsed vType is only a reference to an existing type, store the refId
     245              :     std::string myCurrentVTypeRef;
     246              : 
     247              :     /// @brief if the currently parsed vType is only a reference, store the probability here
     248              :     double myCurrentVTypeProbability;
     249              : 
     250              :     /// @brief The default value for flow begins
     251              :     SUMOTime myBeginDefault;
     252              : 
     253              :     /// @brief The default value for flow ends
     254              :     SUMOTime myEndDefault;
     255              : 
     256              :     /// @brief the first read departure time
     257              :     SUMOTime myFirstDepart;
     258              : 
     259              :     /// @brief where stop edges can be inserted into the current route (-1 means no insertion)
     260              :     int myInsertStopEdgesAt;
     261              : 
     262              :     /// @brief hierarchy of elements being parsed
     263              :     std::vector<int> myElementStack;
     264              : 
     265              :     /// @brief whether references to internal routes are allowed in this context
     266              :     bool myAllowInternalRoutes;
     267              : 
     268              :     /// @brief IDs of skipped vehicles to suppress errors for the triggered transportables within
     269              :     std::set<std::string> mySkippedVehicles;
     270              : 
     271              :     /// @brief A random number generator used to choose from vtype/route distributions and computing the speed factors
     272              :     static SumoRNG myParsingRNG;
     273              : 
     274              : private:
     275              :     /// @brief Invalidated copy constructor
     276              :     SUMORouteHandler(const SUMORouteHandler& s) = delete;
     277              : 
     278              :     /// @brief Invalidated assignment operator
     279              :     SUMORouteHandler& operator=(const SUMORouteHandler& s) = delete;
     280              : };
        

Generated by: LCOV version 2.0-1