LCOV - code coverage report
Current view: top level - src/utils/router - CHRouterWrapper.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 25 25
Test Date: 2024-10-24 15:46:30 Functions: 91.7 % 12 11

            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    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          863 :     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          863 :         myEdges(edges),
      70          863 :         myIgnoreErrors(ignoreErrors),
      71          863 :         myBegin(begin),
      72          863 :         myEnd(end),
      73          863 :         myWeightPeriod(weightPeriod),
      74         1726 :         myMaxNumInstances(numThreads) {
      75          863 :     }
      76              : 
      77         1698 :     ~CHRouterWrapper() {
      78         1360 :         for (typename RouterMap::iterator i = myRouters.begin(); i != myRouters.end(); ++i) {
      79          497 :             delete i->second;
      80              :         }
      81         2561 :     }
      82              : 
      83            6 :     virtual void prohibit(const std::vector<E*>& toProhibit) {
      84            6 :         if (toProhibit.size() > 0) {
      85           12 :             WRITE_WARNINGF(TL("Routing algorithm CHWrapper does not support dynamic closing of edges%"), "");
      86              :         }
      87            6 :     }
      88              : 
      89           23 :     virtual SUMOAbstractRouter<E, V>* clone() {
      90           23 :         CHRouterWrapper<E, V>* clone = new CHRouterWrapper<E, V>(myEdges, myIgnoreErrors, this->myOperation, myBegin, myEnd, myWeightPeriod, this->myHavePermissions, myMaxNumInstances);
      91           31 :         for (const auto& item : myRouters) {
      92            8 :             clone->myRouters[item.first] = static_cast<CHRouterType*>(item.second->clone());
      93              :         }
      94           23 :         return clone;
      95              :     }
      96              : 
      97              : 
      98        16233 :     bool compute(const E* from, const E* to, const V* const vehicle,
      99              :                  SUMOTime msTime, std::vector<const E*>& into, bool silent = false) {
     100        16233 :         const std::pair<const SUMOVehicleClass, const double> svc = std::make_pair(vehicle->getVClass(), vehicle->getMaxSpeed());
     101              :         if (myRouters.count(svc) == 0) {
     102              :             // create new router for the given permissions and maximum speed
     103              :             // XXX a new router may also be needed if vehicles differ in speed factor
     104          489 :             myRouters[svc] = new CHRouterType(myEdges, myIgnoreErrors, this->myOperation, svc.first, myWeightPeriod, false, false);
     105              :         }
     106        16233 :         return myRouters[svc]->compute(from, to, vehicle, msTime, into, silent);
     107              :     }
     108              : 
     109              : 
     110              : private:
     111              :     typedef CHRouter<E, V> CHRouterType;
     112              : 
     113              : private:
     114              :     typedef std::map<std::pair<const SUMOVehicleClass, const double>, CHRouterType*> RouterMap;
     115              : 
     116              :     RouterMap myRouters;
     117              : 
     118              :     /// @brief all edges with numerical ids
     119              :     const std::vector<E*>& myEdges;
     120              : 
     121              :     const bool myIgnoreErrors;
     122              : 
     123              :     const SUMOTime myBegin;
     124              :     const SUMOTime myEnd;
     125              :     const SUMOTime myWeightPeriod;
     126              :     const int myMaxNumInstances;
     127              : };
        

Generated by: LCOV version 2.0-1