LCOV - code coverage report
Current view: top level - src/utils/router - CHRouterWrapper.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 28 28
Test Date: 2026-03-27 16:39:44 Functions: 85.7 % 14 12

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2001-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    CHRouterWrapper.h
      15              : /// @author  Jakob Erdmann
      16              : /// @author  Laura Bieker
      17              : /// @author  Michael Behrisch
      18              : /// @date    March 2012
      19              : ///
      20              : // Wraps multiple CHRouters for different vehicle types
      21              : /****************************************************************************/
      22              : #pragma once
      23              : #include <config.h>
      24              : 
      25              : #include <string>
      26              : #include <functional>
      27              : #include <vector>
      28              : #include <set>
      29              : #include <limits>
      30              : #include <algorithm>
      31              : #include <iterator>
      32              : #include <utils/common/SysUtils.h>
      33              : #include <utils/common/MsgHandler.h>
      34              : #include <utils/common/StdDefs.h>
      35              : #include <utils/router/SUMOAbstractRouter.h>
      36              : #include <utils/common/SUMOVehicleClass.h>
      37              : #include "CHRouter.h"
      38              : 
      39              : #ifdef HAVE_FOX
      40              : #include <utils/foxtools/MFXWorkerThread.h>
      41              : #endif
      42              : 
      43              : 
      44              : // ===========================================================================
      45              : // class definitions
      46              : // ===========================================================================
      47              : /**
      48              :  * @class CHRouterWrapper
      49              :  * @brief Computes the shortest path through a contracted network
      50              :  *
      51              :  * The template parameters are:
      52              :  * @param E The edge class to use (MSEdge/ROEdge)
      53              :  * @param V The vehicle class to use (MSVehicle/ROVehicle)
      54              :  *
      55              :  * The router is edge-based. It must know the number of edges for internal reasons
      56              :  *  and whether a missing connection between two given edges (unbuild route) shall
      57              :  *  be reported as an error or as a warning.
      58              :  *
      59              :  */
      60              : template<class E, class V>
      61              : class CHRouterWrapper: public SUMOAbstractRouter<E, V> {
      62              : 
      63              : public:
      64              :     /** @brief Constructor
      65              :      */
      66          983 :     CHRouterWrapper(const std::vector<E*>& edges, const bool ignoreErrors, typename SUMOAbstractRouter<E, V>::Operation operation,
      67              :                     const SUMOTime begin, const SUMOTime end, const SUMOTime weightPeriod, bool havePermissions, const int numThreads) :
      68              :         SUMOAbstractRouter<E, V>("CHRouterWrapper", ignoreErrors, operation, nullptr, havePermissions, false),
      69          983 :         myEdges(edges),
      70          983 :         myIgnoreErrors(ignoreErrors),
      71          983 :         myBegin(begin),
      72          983 :         myEnd(end),
      73          983 :         myWeightPeriod(weightPeriod),
      74         1966 :         myMaxNumInstances(numThreads) {
      75          983 :     }
      76              : 
      77         1931 :     ~CHRouterWrapper() {
      78         1581 :         for (typename RouterMap::iterator i = myRouters.begin(); i != myRouters.end(); ++i) {
      79          598 :             delete i->second;
      80              :         }
      81         2914 :     }
      82              : 
      83           12 :     virtual void prohibit(const std::map<const E*, RouterProhibition>& toProhibit) {
      84           12 :         if (toProhibit.size() > 0) {
      85           12 :             WRITE_WARNINGF(TL("Routing algorithm CHWrapper does not support dynamic closing of edges%"), "");
      86              :         }
      87           12 :     }
      88              : 
      89           20 :     virtual bool supportsProhibitions() const {
      90           20 :         WRITE_WARNINGF(TL("Routing algorithm CHWrapper does not support dynamic closing of edges and lanes%"), "");
      91           20 :         return false;
      92              :     }
      93              : 
      94           23 :     virtual SUMOAbstractRouter<E, V>* clone() {
      95           23 :         CHRouterWrapper<E, V>* clone = new CHRouterWrapper<E, V>(myEdges, myIgnoreErrors, this->myOperation, myBegin, myEnd, myWeightPeriod, this->myHavePermissions, myMaxNumInstances);
      96           31 :         for (const auto& item : myRouters) {
      97            8 :             clone->myRouters[item.first] = static_cast<CHRouterType*>(item.second->clone());
      98              :         }
      99           23 :         return clone;
     100              :     }
     101              : 
     102              : 
     103        26612 :     bool compute(const E* from, const E* to, const V* const vehicle,
     104              :                  SUMOTime msTime, std::vector<const E*>& into, bool silent = false) {
     105        20232 :         const std::pair<const SUMOVehicleClass, const double> svc = std::make_pair(vehicle->getVClass(), vehicle->getMaxSpeed());
     106              :         if (myRouters.count(svc) == 0) {
     107              :             // create new router for the given permissions and maximum speed
     108              :             // XXX a new router may also be needed if vehicles differ in speed factor
     109          590 :             myRouters[svc] = new CHRouterType(myEdges, myIgnoreErrors, this->myOperation, svc.first, myWeightPeriod, false, false);
     110              :         }
     111        26612 :         return myRouters[svc]->compute(from, to, vehicle, msTime, into, silent);
     112              :     }
     113              : 
     114              : 
     115              : private:
     116              :     typedef CHRouter<E, V> CHRouterType;
     117              : 
     118              : private:
     119              :     typedef std::map<std::pair<const SUMOVehicleClass, const double>, CHRouterType*> RouterMap;
     120              : 
     121              :     RouterMap myRouters;
     122              : 
     123              :     /// @brief all edges with numerical ids
     124              :     const std::vector<E*>& myEdges;
     125              : 
     126              :     const bool myIgnoreErrors;
     127              : 
     128              :     const SUMOTime myBegin;
     129              :     const SUMOTime myEnd;
     130              :     const SUMOTime myWeightPeriod;
     131              :     const int myMaxNumInstances;
     132              : };
        

Generated by: LCOV version 2.0-1