LCOV - code coverage report
Current view: top level - src/utils/router - IntermodalEdge.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 82.9 % 76 63
Test Date: 2024-10-24 15:46:30 Functions: 76.6 % 47 36

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-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    IntermodalEdge.h
      15              : /// @author  Jakob Erdmann
      16              : /// @author  Michael Behrisch
      17              : /// @author  Robert Hilbrich
      18              : /// @date    Mon, 03 March 2014
      19              : ///
      20              : // The Edge definition for the Intermodal Router
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : #include <string>
      26              : #include <vector>
      27              : #include <utils/common/SUMOVehicleClass.h>
      28              : #include <utils/common/ValueTimeLine.h>
      29              : #include <utils/common/RandHelper.h>
      30              : #include <utils/common/Named.h>
      31              : #include "IntermodalTrip.h"
      32              : 
      33              : // ===========================================================================
      34              : // function definitions
      35              : // ===========================================================================
      36              : template <class E, class L>
      37      7623112 : inline const L* getSidewalk(const E* edge, SUMOVehicleClass svc = SVC_PEDESTRIAN) {
      38      7730709 :     if (edge == nullptr) {
      39              :         return nullptr;
      40              :     }
      41              :     // prefer lanes that are exclusive to pedestrians
      42              :     const std::vector<L*>& lanes = edge->getLanes();
      43     10937778 :     for (const L* const lane : lanes) {
      44      8984045 :         if (lane->getPermissions() == svc) {
      45              :             return lane;
      46              :         }
      47              :     }
      48      2500009 :     for (const L* const lane : lanes) {
      49      2070779 :         if (lane->allowsVehicleClass(svc)) {
      50              :             return lane;
      51              :         }
      52              :     }
      53       321143 :     if (svc != SVC_PEDESTRIAN) {
      54              :         // persons should always be able to use the sidewalk
      55            0 :         for (const L* const lane : lanes) {
      56            0 :             if (lane->getPermissions() == SVC_PEDESTRIAN) {
      57              :                 return lane;
      58              :             }
      59              :         }
      60            0 :         for (const L* const lane : lanes) {
      61            0 :             if (lane->allowsVehicleClass(SVC_PEDESTRIAN)) {
      62              :                 return lane;
      63              :             }
      64              :         }
      65              :     }
      66              :     return nullptr;
      67              : }
      68              : 
      69              : 
      70              : 
      71              : // ===========================================================================
      72              : // class definitions
      73              : // ===========================================================================
      74              : /// @brief the base edge type that is given to the internal router (SUMOAbstractRouter)
      75              : template<class E, class L, class N, class V>
      76              : class IntermodalEdge : public Named {
      77              : public:
      78      3315338 :     IntermodalEdge(const std::string id, int numericalID, const E* edge, const std::string& line, const double length = -1) :
      79              :         Named(id),
      80      3315338 :         myNumericalID(numericalID),
      81      3315338 :         myEdge(edge),
      82      3315338 :         myLine(line),
      83      3315338 :         myLength(edge == nullptr || length >= 0. ? MAX2(0.0, length) : edge->getLength()),
      84      6630676 :         myEfforts(nullptr) { }
      85              : 
      86      4796355 :     virtual ~IntermodalEdge() {}
      87              : 
      88      1252206 :     virtual bool includeInRoute(bool /* allEdges */) const {
      89      1252206 :         return false;
      90              :     }
      91              : 
      92              :     inline const std::string& getLine() const {
      93      1002673 :         return myLine;
      94              :     }
      95              : 
      96              :     inline const E* getEdge() const {
      97     52190200 :         return myEdge;
      98              :     }
      99              : 
     100              :     int getNumericalID() const {
     101     76683084 :         return myNumericalID;
     102              :     }
     103              : 
     104              :     void addSuccessor(IntermodalEdge* const s, IntermodalEdge* const via = nullptr) {
     105      5464053 :         myFollowingEdges.push_back(s);
     106      4392675 :         myFollowingViaEdges.push_back(std::make_pair(s, via));
     107              :     }
     108              : 
     109        70131 :     void transferSuccessors(IntermodalEdge* to) {
     110        70131 :         to->myFollowingEdges = myFollowingEdges;
     111        70131 :         to->myFollowingViaEdges = myFollowingViaEdges;
     112              :         myFollowingEdges.clear();
     113              :         myFollowingViaEdges.clear();
     114        70131 :     }
     115              : 
     116        69696 :     bool removeSuccessor(const IntermodalEdge* const edge) {
     117        69696 :         auto it = std::find(myFollowingEdges.begin(), myFollowingEdges.end(), edge);
     118        69696 :         if (it != myFollowingEdges.end()) {
     119        69484 :             myFollowingEdges.erase(it);
     120              :         } else {
     121              :             return false;
     122              :         }
     123       280662 :         for (auto viaIt = myFollowingViaEdges.begin(); viaIt != myFollowingViaEdges.end();) {
     124       211178 :             if (viaIt->first == edge) {
     125              :                 viaIt = myFollowingViaEdges.erase(viaIt);
     126              :             } else {
     127              :                 ++viaIt;
     128              :             }
     129              :         }
     130              :         return true;
     131              :     }
     132              : 
     133         1620 :     virtual const std::vector<IntermodalEdge*>& getSuccessors(SUMOVehicleClass vClass = SVC_IGNORING) const {
     134              :         UNUSED_PARAMETER(vClass);
     135              :         // the network is already tailored. No need to check for permissions here
     136         1620 :         return myFollowingEdges;
     137              :     }
     138              : 
     139     23294388 :     virtual const std::vector<std::pair<const IntermodalEdge*, const IntermodalEdge*> >& getViaSuccessors(SUMOVehicleClass vClass = SVC_IGNORING, bool ignoreTransientPermissions = false) const {
     140              :         UNUSED_PARAMETER(vClass);
     141              :         UNUSED_PARAMETER(ignoreTransientPermissions);
     142              :         // the network is already tailored. No need to check for permissions here
     143     23294388 :         return myFollowingViaEdges;
     144              :     }
     145              : 
     146     13149984 :     virtual bool prohibits(const IntermodalTrip<E, N, V>* const /* trip */) const {
     147     13149984 :         return false;
     148              :     }
     149              : 
     150            0 :     virtual bool restricts(const IntermodalTrip<E, N, V>* const /* trip */) const {
     151            0 :         return false;
     152              :     }
     153              : 
     154       461734 :     virtual inline double getPartialLength(const IntermodalTrip<E, N, V>* const /*trip*/) const {
     155       461734 :         return myLength;
     156              :     }
     157              : 
     158              : 
     159      5675909 :     virtual inline double getTravelTime(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
     160      5675909 :         return 0.;
     161              :     }
     162              : 
     163        19060 :     virtual inline double getTravelTimeAggregated(const IntermodalTrip<E, N, V>* const trip, double time) const {
     164        19060 :         return getTravelTime(trip, time);
     165              :     }
     166              : 
     167              :     /// @brief get intended vehicle id and departure time of next public transport ride
     168            0 :     virtual inline double getIntended(const double /* time */, std::string& /* intended */) const {
     169            0 :         return 0.;
     170              :     }
     171              : 
     172     26974776 :     static inline double getTravelTimeStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
     173     26974776 :         return edge == nullptr ? 0. : edge->getTravelTime(trip, time);
     174              :     }
     175              : 
     176        88752 :     static inline double getTravelTimeStaticRandomized(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
     177        88752 :         return edge == nullptr ? 0. : edge->getTravelTime(trip, time) * RandHelper::rand(1., gWeightsRandomFactor);
     178              :     }
     179              : 
     180        23300 :     static inline double getTravelTimeAggregated(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
     181        23300 :         return edge == nullptr ? 0. : edge->getTravelTimeAggregated(trip, time);
     182              :     }
     183              : 
     184              : 
     185          824 :     virtual double getEffort(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
     186          824 :         return 0.;
     187              :     }
     188              : 
     189            0 :     static inline double getEffortStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
     190            0 :         return edge == nullptr || !edge->hasEffort() ? 0. : edge->getEffort(trip, time);
     191              :     }
     192              : 
     193              :     /// @brief required by DijkstraRouter et al for external effort computation
     194              :     inline double getLength() const {
     195     25489864 :         return myLength;
     196              :     }
     197              : 
     198              :     inline void setLength(const double length) {
     199              :         assert(length >= 0);
     200       139392 :         myLength = length;
     201        46899 :     }
     202              : 
     203              :     inline bool isInternal() const {
     204        97873 :         return myEdge != nullptr && myEdge->isInternal();
     205              :     }
     206              : 
     207            0 :     virtual bool hasEffort() const {
     208            0 :         return myEfforts != nullptr;
     209              :     }
     210              : 
     211         3668 :     virtual double getStartPos() const {
     212         3668 :         return 0.;
     213              :     }
     214              : 
     215         6303 :     virtual double getEndPos() const {
     216         6303 :         return myLength;
     217              :     }
     218              : 
     219              :     // only used by AStar
     220              :     inline double getSpeedLimit() const {
     221       465096 :         return myEdge != nullptr ? myEdge->getSpeedLimit() : 200. / 3.6;
     222              :     }
     223              : 
     224              :     // only used by AStar
     225              :     inline double getLengthGeometryFactor() const {
     226       465096 :         return myEdge != nullptr ? myEdge->getLengthGeometryFactor() : 1;
     227              :     }
     228              : 
     229              :     // only used by AStar
     230        32070 :     inline double getDistanceTo(const IntermodalEdge* other) const {
     231        32070 :         return myEdge != nullptr && other->myEdge != nullptr && myEdge != other->myEdge ? myEdge->getDistanceTo(other->myEdge, true) : 0.;
     232              :     }
     233              : 
     234              :     // only used by AStar
     235              :     inline double getMinimumTravelTime(const IntermodalTrip<E, N, V>* const trip) const {
     236            0 :         return myLength / trip->getMaxSpeed();
     237              :     }
     238              : 
     239              :     /// @brief only used by mono-modal routing
     240              :     IntermodalEdge* getBidiEdge() const {
     241              :         return nullptr;
     242              :     }
     243              : 
     244              : protected:
     245              :     /// @brief List of edges that may be approached from this edge
     246              :     std::vector<IntermodalEdge*> myFollowingEdges;
     247              : 
     248              :     /// @brief List of edges that may be approached from this edge with optional internal vias
     249              :     std::vector<std::pair<const IntermodalEdge*, const IntermodalEdge*> > myFollowingViaEdges;
     250              : 
     251              : private:
     252              :     /// @brief the index in myEdges
     253              :     const int myNumericalID;
     254              : 
     255              :     /// @brief  the original edge
     256              :     const E* const myEdge;
     257              : 
     258              :     /// @brief public transport line or ped vs car
     259              :     const std::string myLine;
     260              : 
     261              :     /// @brief adaptable length (for splitted edges)
     262              :     double myLength;
     263              : 
     264              :     /// @brief Container for passing effort varying over time for the edge
     265              :     ValueTimeLine<double>* myEfforts;
     266              : 
     267              : private:
     268              :     /// @brief Invalidated copy constructor
     269              :     IntermodalEdge(const IntermodalEdge& src);
     270              : 
     271              :     /// @brief Invalidated assignment operator
     272              :     IntermodalEdge& operator=(const IntermodalEdge& src);
     273              : 
     274              : };
        

Generated by: LCOV version 2.0-1