LCOV - code coverage report
Current view: top level - src/router - RORoutable.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 21 21 100.0 %
Date: 2024-05-08 15:29:52 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2002-2024 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    RORoutable.h
      15             : /// @author  Michael Behrisch
      16             : /// @date    Oct 2015
      17             : ///
      18             : // A routable thing such as a vehicle or person
      19             : /****************************************************************************/
      20             : #pragma once
      21             : #include <config.h>
      22             : 
      23             : #include <string>
      24             : #include <iostream>
      25             : #include <utils/common/StdDefs.h>
      26             : #include <utils/common/SUMOTime.h>
      27             : #include <utils/router/RouterProvider.h>
      28             : #include <utils/vehicle/SUMOVehicleParameter.h>
      29             : #include <utils/vehicle/SUMOVTypeParameter.h>
      30             : 
      31             : // ===========================================================================
      32             : // class declarations
      33             : // ===========================================================================
      34             : class OutputDevice;
      35             : class ROEdge;
      36             : class ROLane;
      37             : class RONode;
      38             : class ROVehicle;
      39             : 
      40             : typedef std::vector<const ROEdge*> ConstROEdgeVector;
      41             : typedef IntermodalRouter<ROEdge, ROLane, RONode, ROVehicle> ROIntermodalRouter;
      42             : typedef RouterProvider<ROEdge, ROLane, RONode, ROVehicle> RORouterProvider;
      43             : 
      44             : 
      45             : // ===========================================================================
      46             : // class definitions
      47             : // ===========================================================================
      48             : /**
      49             :  * @class RORoutable
      50             :  * @brief A routable thing such as a vehicle or person
      51             :  */
      52             : class RORoutable {
      53             : public:
      54             :     /** @brief Constructor
      55             :      *
      56             :      * @param[in] pars Parameter of this routable
      57             :      * @param[in] type The type of the routable
      58             :      */
      59             :     RORoutable(const SUMOVehicleParameter& pars, const SUMOVTypeParameter* type)
      60      279124 :         : myParameter(pars), myType(type), myRoutingSuccess(false) {}
      61             : 
      62             : 
      63             :     /// @brief Destructor
      64      279124 :     virtual ~RORoutable() {}
      65             : 
      66             : 
      67             :     /** @brief Returns the definition of the vehicle / person parameter
      68             :     *
      69             :     * @return The vehicle / person's parameter
      70             :     */
      71             :     inline const SUMOVehicleParameter& getParameter() const {
      72      483467 :         return myParameter;
      73             :     }
      74             : 
      75             : 
      76             :     /** @brief Returns the type of the routable
      77             :      *
      78             :      * @return The routable's type
      79             :      *
      80             :      * @todo Why not return a reference?
      81             :      */
      82             :     inline const SUMOVTypeParameter* getType() const {
      83    21897089 :         return myType;
      84             :     }
      85             : 
      86             : 
      87             :     /** @brief Returns the id of the routable
      88             :      *
      89             :      * @return The id of the routable
      90             :      */
      91             :     inline const std::string& getID() const {
      92      279558 :         return myParameter.id;
      93             :     }
      94             : 
      95             : 
      96             :     /** @brief Returns the time the vehicle starts at, -1 for triggered vehicles
      97             :      *
      98             :      * @return The vehicle's depart time
      99             :      */
     100             :     inline SUMOTime getDepart() const {
     101      278278 :         return myParameter.depart;
     102             :     }
     103             : 
     104             :     /// @brief update depart time (for triggered persons)
     105             :     inline void setDepart(SUMOTime t) {
     106             :         myParameter.depart = t;
     107             :     }
     108             : 
     109             :     inline SUMOVehicleClass getVClass() const {
     110     8500809 :         return getType() != 0 ? getType()->vehicleClass : SVC_IGNORING;
     111             :     }
     112             : 
     113             :     /** @brief Returns whether this object is ignoring transient permission
     114             :      * changes (during routing)
     115             :      */
     116             :     bool ignoreTransientPermissions() const {
     117             :         return false;
     118             :     };
     119             : 
     120             :     /// @brief Returns the vehicle's maximum speed
     121     9939723 :     inline double getMaxSpeed() const {
     122     9939723 :         return MIN2(getType()->maxSpeed,
     123     9939723 :                     getType()->desiredMaxSpeed * getType()->speedFactor.getParameter()[0]);
     124             :     }
     125             : 
     126             :     virtual const ROEdge* getDepartEdge() const = 0;
     127             : 
     128             : 
     129             :     inline bool isPublicTransport() const {
     130      554462 :         return myParameter.line != "";
     131             :     }
     132             : 
     133             :     inline bool isPartOfFlow() const {
     134          52 :         return myParameter.repetitionNumber >= 0;
     135             :     }
     136             : 
     137             :     virtual void computeRoute(const RORouterProvider& provider,
     138             :                               const bool removeLoops, MsgHandler* errorHandler) = 0;
     139             : 
     140             : 
     141             :     /** @brief  Saves the routable including the vehicle type (if it was not saved before).
     142             :      *
     143             :      * @param[in] os The routes - output device to store the vehicle's description into
     144             :      * @param[in] altos The route alternatives - output device to store the vehicle's description into
     145             :      * @param[in] typeos The types - output device to store the vehicle types into
     146             :      * @exception IOError If something fails (not yet implemented)
     147             :      */
     148      274630 :     void write(OutputDevice* os, OutputDevice* const altos,
     149             :                OutputDevice* const typeos, OptionsCont& options) const {
     150      274630 :         if (os != nullptr) {
     151      274628 :             if (altos == nullptr && typeos == nullptr) {
     152       51597 :                 saveAsXML(*os, os, false, options);
     153             :             } else {
     154      223031 :                 saveAsXML(*os, typeos, false, options);
     155             :             }
     156             :         }
     157      274630 :         if (altos != nullptr) {
     158      208603 :             saveAsXML(*altos, typeos, true, options);
     159             :         }
     160      274630 :     }
     161             : 
     162             : 
     163             :     inline bool getRoutingSuccess() const {
     164      278078 :         return myRoutingSuccess;
     165             :     }
     166             : 
     167             : 
     168             : protected:
     169             :     /** @brief Saves the complete routable description.
     170             :      *
     171             :      * Saves the routable itself including the route and stops.
     172             :      *
     173             :      * @param[in] os The routes or alternatives output device to store the routable's description into
     174             :      * @param[in] typeos The types - output device to store additional types into
     175             :      * @param[in] asAlternatives Whether the route shall be saved as route alternatives
     176             :      * @param[in] options to find out about defaults and whether exit times for the edges shall be written
     177             :      * @exception IOError If something fails (not yet implemented)
     178             :      */
     179             :     virtual void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options) const = 0;
     180             : 
     181             : 
     182             : private:
     183             :     /// @brief The vehicle's parameter
     184             :     SUMOVehicleParameter myParameter;
     185             : 
     186             :     /// @brief The type of the vehicle
     187             :     const SUMOVTypeParameter* const myType;
     188             : 
     189             : protected:
     190             :     /// @brief Whether the last routing was successful
     191             :     bool myRoutingSuccess;
     192             : 
     193             : 
     194             : private:
     195             :     /// @brief Invalidated copy constructor
     196             :     RORoutable(const RORoutable& src);
     197             : 
     198             :     /// @brief Invalidated assignment operator
     199             :     RORoutable& operator=(const RORoutable& src);
     200             : 
     201             : };

Generated by: LCOV version 1.14