LCOV - code coverage report
Current view: top level - src/utils/router - PedestrianRouter.h (source / functions) Coverage Total Hit
Test: lcov.info Lines: 90.5 % 42 38
Test Date: 2024-11-22 15:46:21 Functions: 66.7 % 15 10

            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    PedestrianRouter.h
      15              : /// @author  Jakob Erdmann
      16              : /// @date    Mon, 03 March 2014
      17              : ///
      18              : // The Pedestrian Router builds a special network and delegates to a SUMOAbstractRouter.
      19              : /****************************************************************************/
      20              : #pragma once
      21              : #include <config.h>
      22              : 
      23              : #include <string>
      24              : #include <vector>
      25              : #include <algorithm>
      26              : #include <assert.h>
      27              : #include <utils/common/MsgHandler.h>
      28              : #include <utils/common/SUMOTime.h>
      29              : #include <utils/common/ToString.h>
      30              : #include "SUMOAbstractRouter.h"
      31              : #include "DijkstraRouter.h"
      32              : #include "IntermodalNetwork.h"
      33              : 
      34              : //#define PedestrianRouter_DEBUG_ROUTES
      35              : 
      36              : 
      37              : // ===========================================================================
      38              : // class definitions
      39              : // ===========================================================================
      40              : /**
      41              :  * @class PedestrianRouter
      42              :  * The router for pedestrians (on a bidirectional network of sidewalks and crossings)
      43              :  */
      44              : template<class E, class L, class N, class V>
      45              : class PedestrianRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> > {
      46              : private:
      47              :     typedef IntermodalEdge<E, L, N, V> _IntermodalEdge;
      48              :     typedef IntermodalNetwork<E, L, N, V> _IntermodalNetwork;
      49              :     typedef IntermodalTrip<E, N, V> _IntermodalTrip;
      50              :     typedef DijkstraRouter<_IntermodalEdge, _IntermodalTrip> _InternalRouter;
      51              : 
      52              : public:
      53              :     /// Constructor
      54         8724 :     PedestrianRouter():
      55         8724 :         SUMOAbstractRouter<E, _IntermodalTrip>("PedestrianRouter", true, nullptr, nullptr, false, false), myAmClone(false) {
      56         8724 :         myPedNet = new _IntermodalNetwork(E::getAllEdges(), true);
      57        17448 :         myInternalRouter = new _InternalRouter(myPedNet->getAllEdges(), true,
      58         8724 :                                                gWeightsRandomFactor > 1 ? &_IntermodalEdge::getTravelTimeStaticRandomized : &_IntermodalEdge::getTravelTimeStatic,
      59              :                                                nullptr, false, nullptr, true);
      60         8724 :     }
      61              : 
      62           48 :     PedestrianRouter(_IntermodalNetwork* net):
      63           48 :         SUMOAbstractRouter<E, _IntermodalTrip>("PedestrianRouterClone", true, nullptr, nullptr, false, false), myAmClone(true) {
      64           48 :         myPedNet = net;
      65           96 :         myInternalRouter = new _InternalRouter(myPedNet->getAllEdges(), true,
      66           48 :                                                gWeightsRandomFactor > 1 ? &_IntermodalEdge::getTravelTimeStaticRandomized : &_IntermodalEdge::getTravelTimeStatic,
      67              :                                                nullptr, false, nullptr, true);
      68           48 :     }
      69              : 
      70              :     /// Destructor
      71        17544 :     virtual ~PedestrianRouter() {
      72         8772 :         delete myInternalRouter;
      73         8772 :         if (!myAmClone) {
      74         8724 :             delete myPedNet;
      75              :         }
      76        26316 :     }
      77              : 
      78           48 :     virtual SUMOAbstractRouter<E, _IntermodalTrip>* clone() {
      79           48 :         return new PedestrianRouter<E, L, N, V>(myPedNet);
      80              :     }
      81              : 
      82              :     /** @brief Builds the route between the given edges using the minimum effort at the given time
      83              :         The definition of the effort depends on the wished routing scheme */
      84       817866 :     double compute(const E* from, const E* to, double departPos, double arrivalPos, double speed,
      85              :                    SUMOTime msTime, const N* onlyNode, std::vector<const E*>& into, bool allEdges = false) {
      86       817866 :         if (getSidewalk<E, L>(from) == 0) {
      87            0 :             WRITE_WARNINGF(TL("Departure edge '%' does not allow pedestrians."), from->getID());
      88            0 :             return false;
      89              :         }
      90       817866 :         if (getSidewalk<E, L>(to) == 0) {
      91           12 :             WRITE_WARNINGF(TL("Destination edge '%' does not allow pedestrians."), to->getID());
      92            4 :             return false;
      93              :         }
      94              :         _IntermodalTrip trip(from, to, departPos, arrivalPos, speed, msTime, onlyNode);
      95              :         std::vector<const _IntermodalEdge*> intoPed;
      96              :         const bool silent = allEdges; // no warning is needed when called from MSPModel_Striping
      97       817862 :         const bool success = myInternalRouter->compute(myPedNet->getDepartConnector(from),
      98       817862 :                              myPedNet->getArrivalConnector(to),
      99              :                              &trip, msTime, intoPed, silent);
     100              :         double time = 0.;
     101       817862 :         if (success) {
     102      4364228 :             for (const _IntermodalEdge* pedEdge : intoPed) {
     103      3546399 :                 if (pedEdge->includeInRoute(allEdges)) {
     104      2724601 :                     into.push_back(pedEdge->getEdge());
     105              :                 }
     106      3546399 :                 time += myInternalRouter->getEffort(pedEdge, &trip, time);
     107              :             }
     108              :         }
     109              : #ifdef PedestrianRouter_DEBUG_ROUTES
     110              :         std::cout << TIME2STEPS(msTime) << " trip from " << from->getID() << " to " << to->getID()
     111              :                   << " departPos=" << departPos
     112              :                   << " arrivalPos=" << arrivalPos
     113              :                   << " onlyNode=" << (onlyNode == 0 ? "NULL" : onlyNode->getID())
     114              :                   << " edges=" << toString(intoPed)
     115              :                   << " resultEdges=" << toString(into)
     116              :                   << " time=" << time
     117              :                   << "\n";
     118              : #endif
     119              :         return success ? time : -1.;
     120       817862 :     }
     121              : 
     122              :     /** @brief Builds the route between the given edges using the minimum effort at the given time
     123              :         The definition of the effort depends on the wished routing scheme */
     124            0 :     bool compute(const E*, const E*, const _IntermodalTrip* const,
     125              :                  SUMOTime, std::vector<const E*>&, bool) {
     126            0 :         throw ProcessError(TL("Do not use this method"));
     127              :     }
     128              : 
     129       817866 :     void prohibit(const std::vector<E*>& toProhibit) {
     130              :         std::vector<_IntermodalEdge*> toProhibitPE;
     131      1632225 :         for (typename std::vector<E*>::const_iterator it = toProhibit.begin(); it != toProhibit.end(); ++it) {
     132       814359 :             toProhibitPE.push_back(myPedNet->getBothDirections(*it).first);
     133       814359 :             toProhibitPE.push_back(myPedNet->getBothDirections(*it).second);
     134              :         }
     135       817866 :         myInternalRouter->prohibit(toProhibitPE);
     136       817866 :     }
     137              : 
     138              : private:
     139              :     const bool myAmClone;
     140              :     _InternalRouter* myInternalRouter;
     141              :     _IntermodalNetwork* myPedNet;
     142              : 
     143              : 
     144              : private:
     145              :     /// @brief Invalidated assignment operator
     146              :     PedestrianRouter& operator=(const PedestrianRouter& s);
     147              : 
     148              : };
        

Generated by: LCOV version 2.0-1