LCOV - code coverage report
Current view: top level - src/router - RORouteDef.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 9 9
Test Date: 2026-04-16 16:39:47 Functions: 100.0 % 2 2

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2002-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    RORouteDef.h
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @author  Jakob Erdmann
      18              : /// @date    Sept 2002
      19              : ///
      20              : // Base class for a vehicle's route definition
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : #include <string>
      26              : #include <iostream>
      27              : #include <memory>
      28              : #include <utils/common/Named.h>
      29              : #include <utils/router/SUMOAbstractRouter.h>
      30              : #include "RORoute.h"
      31              : 
      32              : 
      33              : // ===========================================================================
      34              : // class declarations
      35              : // ===========================================================================
      36              : class ROEdge;
      37              : class OptionsCont;
      38              : class ROVehicle;
      39              : class OutputDevice;
      40              : 
      41              : 
      42              : // ===========================================================================
      43              : // class definitions
      44              : // ===========================================================================
      45              : /**
      46              :  * @class RORouteDef
      47              :  * @brief Base class for a vehicle's route definition
      48              :  *
      49              :  * This class resembles what a vehicle knows about his route when being loaded
      50              :  *  into a router. Whether it is just the origin and the destination, the whole
      51              :  *  route through the network or even a route with alternatives depends on
      52              :  *  the derived class.
      53              :  */
      54              : class RORouteDef : public Named {
      55              : public:
      56              :     /** @brief Constructor
      57              :      *
      58              :      * @param[in] id The id of the route
      59              :      * @param[in] color The color of the route
      60              :      */
      61              :     RORouteDef(const std::string& id, const int lastUsed,
      62              :                const bool tryRepair, const bool mayBeDisconnected);
      63              : 
      64              : 
      65              :     /// @brief Destructor
      66       604002 :     virtual ~RORouteDef() {}
      67              : 
      68              : 
      69              :     /** @brief Adds a single alternative loaded from the file
      70              :         An alternative may also be generated during DUA */
      71              :     void addLoadedAlternative(std::shared_ptr<RORoute> alternative) {
      72       443884 :         myAlternatives.push_back(alternative);
      73       443884 :     }
      74              : 
      75              :     /** @brief Adds an alternative loaded from the file */
      76              :     void addAlternativeDef(const RORouteDef* alternative);
      77              : 
      78              :     /** @brief removes invalid alternatives and raise an error or warning **/
      79              :     void validateAlternatives(const ROVehicle* veh, MsgHandler* errorHandler);
      80              : 
      81              :     /** @brief Triggers building of the complete route (via
      82              :      * preComputeCurrentRoute) or returns precomputed route */
      83              :     std::shared_ptr<RORoute> buildCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,
      84              :             const ROVehicle& veh) const;
      85              : 
      86              :     /** @brief Builds the complete route
      87              :      * (or chooses her from the list of alternatives, when existing) */
      88              :     void preComputeCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,
      89              :                                 const ROVehicle& veh) const;
      90              : 
      91              :     /** @brief Builds the complete route
      92              :      * (or chooses her from the list of alternatives, when existing) */
      93              :     bool repairCurrentRoute(SUMOAbstractRouter<ROEdge, ROVehicle>& router, SUMOTime begin,
      94              :                             const ROVehicle& veh, ConstROEdgeVector oldEdges, ConstROEdgeVector& newEdges,
      95              :                             bool isTrip = false) const;
      96              : 
      97              :     /** @brief Adds an alternative to the list of routes
      98              :      * and returns the route that was replaced or nullptr
      99              :     *
     100              :      * (This may be the new route) */
     101              :     std::shared_ptr<RORoute> addAlternative(SUMOAbstractRouter<ROEdge, ROVehicle>& router,
     102              :                                             const ROVehicle* const, std::shared_ptr<RORoute> current, SUMOTime begin,
     103              :                                             MsgHandler* errorHandler);
     104              : 
     105              :     const ROEdge* getOrigin() const;
     106              :     const ROEdge* getDestination() const;
     107              : 
     108              :     std::shared_ptr<const RORoute> getFirstRoute() const {
     109      1271080 :         if (myAlternatives.empty()) {
     110              :             return nullptr;
     111              :         }
     112              :         return myAlternatives.front();
     113              :     }
     114              : 
     115              :     std::shared_ptr<const RORoute> getUsedRoute() const {
     116           40 :         return myAlternatives[myLastUsed];
     117              :     }
     118              : 
     119              :     /** @brief Saves the built route / route alternatives
     120              :      *
     121              :      * Writes the route into the given stream.
     122              :      *
     123              :      * @param[in] dev The device to write the route into
     124              :      * @param[in] asAlternatives Whether the route shall be saved as route alternatives
     125              :      * @return The same device for further usage
     126              :      */
     127              :     OutputDevice& writeXMLDefinition(OutputDevice& dev, const ROVehicle* const veh,
     128              :                                      bool asAlternatives, bool withExitTimes, bool withCost, bool withLength) const;
     129              : 
     130              : 
     131              :     /** @brief Returns a deep copy of the route definition.
     132              :      *
     133              :      * The resulting route definition contains copies of all
     134              :      * routes contained in this one
     135              :      *
     136              :      * @param[in] id The id for the new route definition
     137              :      * @param[in] stopOffset The offset time for "until"-stops defined in the original route
     138              :      * @return the new route definition
     139              :      */
     140              :     RORouteDef* copy(const std::string& id, const SUMOTime stopOffset) const;
     141              : 
     142              :     /** @brief Returns the sum of the probablities of the contained routes */
     143              :     double getOverallProb() const;
     144              : 
     145              : 
     146              :     /// @brief whether this route shall be silently discarded
     147              :     bool discardSilent() const {
     148         1925 :         return myDiscardSilent;
     149              :     }
     150              : 
     151              : 
     152              :     static void setUsingJTRR() {
     153          112 :         myUsingJTRR = true;
     154              :     }
     155              : 
     156              :     static void setSkipNew() {
     157           23 :         mySkipNewRoutes = true;
     158           23 :     }
     159              : 
     160              : protected:
     161              :     /// @brief backtrack to last mandatory edge and route to next mandatory
     162              :     static bool backTrack(SUMOAbstractRouter<ROEdge, ROVehicle>& router,
     163              :                           ConstROEdgeVector::const_iterator& i, int lastMandatory, const ROEdge* nextMandatory,
     164              :                           ConstROEdgeVector& newEdges, const ROVehicle& veh, SUMOTime begin);
     165              : 
     166              : protected:
     167              :     /// @brief precomputed route for out-of-order computation
     168              :     mutable std::shared_ptr<RORoute> myPrecomputed;
     169              : 
     170              :     /// @brief Index of the route used within the last step
     171              :     mutable int myLastUsed;
     172              : 
     173              :     /// @brief The alternatives
     174              :     std::vector<std::shared_ptr<RORoute> > myAlternatives;
     175              : 
     176              :     /// @brief Information whether a new route was generated
     177              :     mutable bool myNewRoute;
     178              : 
     179              :     const bool myTryRepair;
     180              :     const bool myMayBeDisconnected;
     181              : 
     182              :     /// @brief Whether this route should be silently discarded
     183              :     mutable bool myDiscardSilent;
     184              : 
     185              :     static bool myUsingJTRR;
     186              :     static bool mySkipNewRoutes;
     187              : 
     188              : private:
     189              :     /// @brief Invalidated copy constructor
     190              :     RORouteDef(const RORouteDef& src) = delete;
     191              : 
     192              :     /// @brief Invalidated assignment operator
     193              :     RORouteDef& operator=(const RORouteDef& src) = delete;
     194              : 
     195              : };
        

Generated by: LCOV version 2.0-1