LCOV - code coverage report
Current view: top level - src/utils/router - ReversedEdge.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 87.1 % 31 27
Test Date: 2024-11-22 15:46:21 Functions: 80.0 % 5 4

            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    ReversedEdge.h
      15              : /// @author  Michael Behrisch
      16              : /// @author  Ruediger Ebendt
      17              : /// @date    29.01.2020
      18              : ///
      19              : // The ReversedEdge is a wrapper around a ROEdge or a MSEdge used for
      20              : // backward search
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : 
      26              : // ===========================================================================
      27              : // class definitions
      28              : // ===========================================================================
      29              : /// @brief the edge type representing backward edges
      30              : template<class E, class V>
      31              : class ReversedEdge {
      32              : public:
      33              :     typedef std::vector<std::pair<const ReversedEdge<E, V>*, const ReversedEdge<E, V>*> > ConstEdgePairVector;
      34              : 
      35        20488 :     ReversedEdge(const E* orig) : myOriginal(orig) {
      36        20488 :     }
      37              : 
      38        20488 :     void init() {
      39        20488 :         if (!myOriginal->isInternal()) {
      40        16904 :             for (const auto& viaPair : myOriginal->getViaSuccessors()) {
      41        13296 :                 const ReversedEdge<E, V>* revSource = viaPair.first->getReversedRoutingEdge();
      42        13296 :                 const E* via = viaPair.second;
      43              :                 const ReversedEdge<E, V>* preVia = nullptr;
      44        30176 :                 while (via != nullptr && via->isInternal()) {
      45        16880 :                     via->getReversedRoutingEdge()->myViaSuccessors.push_back(std::make_pair(this, preVia));
      46        16880 :                     preVia = via->getReversedRoutingEdge();
      47        16880 :                     via = via->getViaSuccessors().front().second;
      48              :                 }
      49        13296 :                 revSource->myViaSuccessors.push_back(std::make_pair(this, preVia));
      50              :             }
      51              :         }
      52        20488 :     }
      53              : 
      54              :     /// @brief Returns the original edge
      55              :     const E* getOriginalEdge() const {
      56              :         return myOriginal;
      57              :     }
      58              : 
      59              :     /** @brief Returns the index (numeric id) of the edge
      60              :      * @return The original edge's numerical id
      61              :      */
      62              :     int getNumericalID() const {
      63         9684 :         return myOriginal->getNumericalID();
      64              :     }
      65              : 
      66              :     /** @brief Returns the id of the edge
      67              :      * @return The original edge's id
      68              :      */
      69              :     const std::string& getID() const {
      70            0 :         return myOriginal->getID();
      71              :     }
      72              : 
      73              :     /** @brief Returns the length of the edge
      74              :      * @return The original edge's length
      75              :      */
      76              :     double getLength() const {
      77        17066 :         return myOriginal->getLength();
      78              :     }
      79              : 
      80              :     const ReversedEdge* getBidiEdge() const {
      81              :         return myOriginal->getBidiEdge()->getReversedRoutingEdge();
      82              :     }
      83              : 
      84              :     bool isInternal() const {
      85        17066 :         return myOriginal->isInternal();
      86              :     }
      87              : 
      88              :     inline bool prohibits(const V* const vehicle) const {
      89            0 :         return myOriginal->prohibits(vehicle);
      90              :     }
      91              : 
      92              :     inline bool restricts(const V* const vehicle) const {
      93            0 :         return myOriginal->restricts(vehicle);
      94              :     }
      95              : 
      96        29162 :     static inline double getTravelTimeStatic(const ReversedEdge<E, V>* const edge, const V* const veh, double time) {
      97        29162 :         return edge->myOriginal->getTravelTime(veh, time);
      98              :     }
      99              : 
     100         1436 :     const ConstEdgePairVector& getViaSuccessors(SUMOVehicleClass vClass = SVC_IGNORING, bool ignoreTransientPermissions = false) const {
     101              :         UNUSED_PARAMETER(ignoreTransientPermissions); // @todo this should be changed (somewhat hidden by #14756)
     102         1436 :         if (vClass == SVC_IGNORING || myOriginal->isTazConnector()) { // || !MSNet::getInstance()->hasPermissions()) {
     103            0 :             return myViaSuccessors;
     104              :         }
     105              : #ifdef HAVE_FOX
     106         1436 :         FXMutexLock lock(mySuccessorMutex);
     107              : #endif
     108              :         auto i = myClassesViaSuccessorMap.find(vClass);
     109         1436 :         if (i != myClassesViaSuccessorMap.end()) {
     110              :             // can use cached value
     111          716 :             return i->second;
     112              :         }
     113              :         // instantiate vector
     114          720 :         ConstEdgePairVector& result = myClassesViaSuccessorMap[vClass];
     115              :         // this vClass is requested for the first time. rebuild all successors
     116         3376 :         for (const auto& viaPair : myViaSuccessors) {
     117         2656 :             if (viaPair.first->myOriginal->isTazConnector() || viaPair.first->myOriginal->isConnectedTo(*myOriginal, vClass)) {
     118         2656 :                 result.push_back(viaPair);
     119              :             }
     120              :         }
     121              :         return result;
     122              :     }
     123              : 
     124              : private:
     125              :     const E* const myOriginal;
     126              :     /// @brief The successors available for a given vClass
     127              :     mutable std::map<SUMOVehicleClass, ConstEdgePairVector> myClassesViaSuccessorMap;
     128              : 
     129              :     mutable ConstEdgePairVector myViaSuccessors;
     130              : 
     131              : #ifdef HAVE_FOX
     132              :     /// @brief Mutex for accessing successor edges
     133              :     mutable FXMutex mySuccessorMutex;
     134              : #endif
     135              : 
     136              : };
        

Generated by: LCOV version 2.0-1