LCOV - code coverage report
Current view: top level - src/router - RORoutable.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 22 22
Test Date: 2024-12-21 15:45:41 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-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       154417 :         : myParameter(pars), myType(type), myRoutingSuccess(false) {}
      61              : 
      62              : 
      63              :     /// @brief Destructor
      64       154417 :     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       269026 :         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     13063760 :         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       154135 :         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       153751 :         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      4509711 :         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      6830592 :     inline double getMaxSpeed() const {
     122      6830592 :         return MIN2(getType()->maxSpeed,
     123      6830592 :                     getType()->desiredMaxSpeed * getType()->speedFactor.getParameter()[0]);
     124              :     }
     125              : 
     126              :     virtual const ROEdge* getDepartEdge() const = 0;
     127              : 
     128              : 
     129              :     inline bool isPublicTransport() const {
     130       305635 :         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       151555 :     void write(OutputDevice* os, OutputDevice* const altos,
     149              :                OutputDevice* const typeos, OptionsCont& options, int quota) const {
     150       303166 :         for (int i = 0; i < quota; i++) {
     151       151611 :             if (os != nullptr) {
     152       151609 :                 if (altos == nullptr && typeos == nullptr) {
     153        27210 :                     saveAsXML(*os, os, false, options, i);
     154              :                 } else {
     155       124399 :                     saveAsXML(*os, typeos, false, options, i);
     156              :                 }
     157              :             }
     158       151611 :             if (altos != nullptr) {
     159       117185 :                 saveAsXML(*altos, typeos, true, options, i);
     160              :             }
     161              :         }
     162       151555 :     }
     163              : 
     164              : 
     165              :     inline bool getRoutingSuccess() const {
     166       153551 :         return myRoutingSuccess;
     167              :     }
     168              : 
     169              : 
     170              : protected:
     171              :     /** @brief Saves the complete routable description.
     172              :      *
     173              :      * Saves the routable itself including the route and stops.
     174              :      *
     175              :      * @param[in] os The routes or alternatives output device to store the routable's description into
     176              :      * @param[in] typeos The types - output device to store additional types into
     177              :      * @param[in] asAlternatives Whether the route shall be saved as route alternatives
     178              :      * @param[in] options to find out about defaults and whether exit times for the edges shall be written
     179              :      * @exception IOError If something fails (not yet implemented)
     180              :      */
     181              :     virtual void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options, int cloneIndex=0) const = 0;
     182              : 
     183              : 
     184              : private:
     185              :     /// @brief The vehicle's parameter
     186              :     SUMOVehicleParameter myParameter;
     187              : 
     188              :     /// @brief The type of the vehicle
     189              :     const SUMOVTypeParameter* const myType;
     190              : 
     191              : protected:
     192              :     /// @brief Whether the last routing was successful
     193              :     bool myRoutingSuccess;
     194              : 
     195              : 
     196              : private:
     197              :     /// @brief Invalidated copy constructor
     198              :     RORoutable(const RORoutable& src);
     199              : 
     200              :     /// @brief Invalidated assignment operator
     201              :     RORoutable& operator=(const RORoutable& src);
     202              : 
     203              : };
        

Generated by: LCOV version 2.0-1