LCOV - code coverage report
Current view: top level - src/router - RORoutable.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 27 27
Test Date: 2026-03-02 16:00:03 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    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/common/RandHelper.h>
      28              : #include <utils/router/RouterProvider.h>
      29              : #include <utils/vehicle/SUMOVehicleParameter.h>
      30              : #include <utils/vehicle/SUMOVTypeParameter.h>
      31              : 
      32              : // ===========================================================================
      33              : // class declarations
      34              : // ===========================================================================
      35              : class OutputDevice;
      36              : class ROEdge;
      37              : class ROLane;
      38              : class RONode;
      39              : class ROVehicle;
      40              : 
      41              : typedef std::vector<const ROEdge*> ConstROEdgeVector;
      42              : typedef IntermodalRouter<ROEdge, ROLane, RONode, ROVehicle> ROIntermodalRouter;
      43              : typedef RouterProvider<ROEdge, ROLane, RONode, ROVehicle> RORouterProvider;
      44              : 
      45              : 
      46              : // ===========================================================================
      47              : // class definitions
      48              : // ===========================================================================
      49              : /**
      50              :  * @class RORoutable
      51              :  * @brief A routable thing such as a vehicle or person
      52              :  */
      53              : class RORoutable {
      54              : public:
      55              :     /** @brief Constructor
      56              :      *
      57              :      * @param[in] pars Parameter of this routable
      58              :      * @param[in] type The type of the routable
      59              :      */
      60       301282 :     RORoutable(const SUMOVehicleParameter& pars, const SUMOVTypeParameter* type) :
      61       301282 :         myParameter(pars),
      62       301282 :         myType(type),
      63       301282 :         myRandomSeed(RandHelper::murmur3_32(pars.id, RandHelper::getSeed())),
      64       602564 :         myRoutingSuccess(false) {}
      65              : 
      66              : 
      67              :     /// @brief Destructor
      68       301282 :     virtual ~RORoutable() {}
      69              : 
      70              : 
      71              :     /** @brief Returns the definition of the vehicle / person parameter
      72              :     *
      73              :     * @return The vehicle / person's parameter
      74              :     */
      75              :     inline const SUMOVehicleParameter& getParameter() const {
      76       395228 :         return myParameter;
      77              :     }
      78              : 
      79              : 
      80              :     /** @brief Returns the type of the routable
      81              :      *
      82              :      * @return The routable's type
      83              :      *
      84              :      * @todo Why not return a reference?
      85              :      */
      86              :     inline const SUMOVTypeParameter* getType() const {
      87     15509733 :         return myType;
      88              :     }
      89              : 
      90              : 
      91              :     /** @brief Returns the id of the routable
      92              :      *
      93              :      * @return The id of the routable
      94              :      */
      95              :     inline const std::string& getID() const {
      96       301910 :         return myParameter.id;
      97              :     }
      98              : 
      99              :     /// @brief return vehicle-specific random number
     100              :     long long int getRandomSeed() const {
     101         6984 :         return myRandomSeed;
     102              :     }
     103              : 
     104              :     /** @brief Returns an upper bound for the speed factor of this vehicle
     105              :      * @return the maximum speed factor
     106              :      */
     107              :     inline double getChosenSpeedFactor() const {
     108     13254316 :         return getParameter().wasSet(VEHPARS_SPEEDFACTOR_SET) ? getParameter().speedFactor :  getType()->speedFactor.getParameter(0);
     109              :     }
     110              : 
     111              :     /** @brief Returns the time the vehicle starts at, -1 for triggered vehicles
     112              :      *
     113              :      * @return The vehicle's depart time
     114              :      */
     115              :     inline SUMOTime getDepart() const {
     116       300317 :         return myParameter.depart;
     117              :     }
     118              : 
     119              :     /// @brief update depart time (for triggered persons)
     120              :     inline void setDepart(SUMOTime t) {
     121              :         myParameter.depart = t;
     122              :     }
     123              : 
     124              :     inline SUMOVehicleClass getVClass() const {
     125     20009557 :         return getType() != 0 ? getType()->vehicleClass : SVC_IGNORING;
     126              :     }
     127              : 
     128              :     /** @brief Returns whether this object is ignoring transient permission
     129              :      * changes (during routing)
     130              :      */
     131              :     bool ignoreTransientPermissions() const {
     132              :         return false;
     133              :     };
     134              : 
     135              :     /// @brief Returns the vehicle's maximum speed
     136              :     inline double getMaxSpeed() const {
     137     13248544 :         return MIN2(getType()->maxSpeed,
     138     13253104 :                     getType()->desiredMaxSpeed * getChosenSpeedFactor());
     139              :     }
     140              : 
     141              :     virtual const ROEdge* getDepartEdge() const = 0;
     142              : 
     143              : 
     144              :     inline bool isPublicTransport() const {
     145       597112 :         return myParameter.line != "";
     146              :     }
     147              : 
     148              :     inline bool isPartOfFlow() const {
     149       297747 :         return myParameter.repetitionNumber >= 0;
     150              :     }
     151              : 
     152              :     virtual void computeRoute(const RORouterProvider& provider,
     153              :                               const bool removeLoops, MsgHandler* errorHandler) = 0;
     154              : 
     155              : 
     156              :     /** @brief  Saves the routable including the vehicle type (if it was not saved before).
     157              :      *
     158              :      * @param[in] os The routes - output device to store the vehicle's description into
     159              :      * @param[in] altos The route alternatives - output device to store the vehicle's description into
     160              :      * @param[in] typeos The types - output device to store the vehicle types into
     161              :      * @exception IOError If something fails (not yet implemented)
     162              :      */
     163       280903 :     void write(OutputDevice* os, OutputDevice* const altos,
     164              :                OutputDevice* const typeos, OptionsCont& options, int quota) const {
     165       561862 :         for (int i = 0; i < quota; i++) {
     166       280959 :             if (os != nullptr) {
     167       280957 :                 if (altos == nullptr && typeos == nullptr) {
     168       159352 :                     saveAsXML(*os, os, false, options, i);
     169              :                 } else {
     170       121605 :                     saveAsXML(*os, typeos, false, options, i);
     171              :                 }
     172              :             }
     173       280959 :             if (altos != nullptr) {
     174       114031 :                 saveAsXML(*altos, typeos, true, options, i);
     175              :             }
     176              :         }
     177       280903 :     }
     178              : 
     179              : 
     180              :     inline bool getRoutingSuccess() const {
     181       300104 :         return myRoutingSuccess;
     182              :     }
     183              : 
     184              : 
     185              : protected:
     186              :     /** @brief Saves the complete routable description.
     187              :      *
     188              :      * Saves the routable itself including the route and stops.
     189              :      *
     190              :      * @param[in] os The routes or alternatives output device to store the routable's description into
     191              :      * @param[in] typeos The types - output device to store additional types into
     192              :      * @param[in] asAlternatives Whether the route shall be saved as route alternatives
     193              :      * @param[in] options to find out about defaults and whether exit times for the edges shall be written
     194              :      * @exception IOError If something fails (not yet implemented)
     195              :      */
     196              :     virtual void saveAsXML(OutputDevice& os, OutputDevice* const typeos, bool asAlternatives, OptionsCont& options, int cloneIndex = 0) const = 0;
     197              : 
     198              : 
     199              : private:
     200              :     /// @brief The vehicle's parameter
     201              :     SUMOVehicleParameter myParameter;
     202              : 
     203              :     /// @brief The type of the vehicle
     204              :     const SUMOVTypeParameter* const myType;
     205              : 
     206              :     /// @brief object-specific random constant
     207              :     const long long int myRandomSeed;
     208              : 
     209              : protected:
     210              :     /// @brief Whether the last routing was successful
     211              :     bool myRoutingSuccess;
     212              : 
     213              : 
     214              : private:
     215              :     /// @brief Invalidated copy constructor
     216              :     RORoutable(const RORoutable& src);
     217              : 
     218              :     /// @brief Invalidated assignment operator
     219              :     RORoutable& operator=(const RORoutable& src);
     220              : 
     221              : };
        

Generated by: LCOV version 2.0-1