Eclipse SUMO - Simulation of Urban MObility
PedestrianRouter.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 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 /****************************************************************************/
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>
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 // ===========================================================================
44 template<class E, class L, class N, class V>
45 class PedestrianRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> > {
46 private:
51 
52 public:
55  SUMOAbstractRouter<E, _IntermodalTrip>("PedestrianRouter", true, nullptr, nullptr, false, false), myAmClone(false) {
56  myPedNet = new _IntermodalNetwork(E::getAllEdges(), true);
59  }
60 
62  SUMOAbstractRouter<E, _IntermodalTrip>("PedestrianRouterClone", true, nullptr, nullptr, false, false), myAmClone(true) {
63  myPedNet = net;
66  }
67 
69  virtual ~PedestrianRouter() {
70  delete myInternalRouter;
71  if (!myAmClone) {
72  delete myPedNet;
73  }
74  }
75 
78  }
79 
82  double compute(const E* from, const E* to, double departPos, double arrivalPos, double speed,
83  SUMOTime msTime, const N* onlyNode, std::vector<const E*>& into, bool allEdges = false) {
84  if (getSidewalk<E, L>(from) == 0) {
85  WRITE_WARNING("Departure edge '" + from->getID() + "' does not allow pedestrians.");
86  return false;
87  }
88  if (getSidewalk<E, L>(to) == 0) {
89  WRITE_WARNING("Destination edge '" + to->getID() + "' does not allow pedestrians.");
90  return false;
91  }
92  _IntermodalTrip trip(from, to, departPos, arrivalPos, speed, msTime, onlyNode);
93  std::vector<const _IntermodalEdge*> intoPed;
94  const bool success = myInternalRouter->compute(myPedNet->getDepartConnector(from),
96  &trip, msTime, intoPed);
97  double time = 0.;
98  if (success) {
99  for (const _IntermodalEdge* pedEdge : intoPed) {
100  if (pedEdge->includeInRoute(allEdges)) {
101  into.push_back(pedEdge->getEdge());
102  }
103  time += myInternalRouter->getEffort(pedEdge, &trip, time);
104  }
105  }
106 #ifdef PedestrianRouter_DEBUG_ROUTES
107  std::cout << TIME2STEPS(msTime) << " trip from " << from->getID() << " to " << to->getID()
108  << " departPos=" << departPos
109  << " arrivalPos=" << arrivalPos
110  << " onlyNode=" << (onlyNode == 0 ? "NULL" : onlyNode->getID())
111  << " edges=" << toString(intoPed)
112  << " resultEdges=" << toString(into)
113  << " time=" << time
114  << "\n";
115 #endif
116  return success ? time : -1.;
117  }
118 
121  bool compute(const E*, const E*, const _IntermodalTrip* const,
122  SUMOTime, std::vector<const E*>&, bool) {
123  throw ProcessError("Do not use this method");
124  }
125 
126  void prohibit(const std::vector<E*>& toProhibit) {
127  std::vector<_IntermodalEdge*> toProhibitPE;
128  for (typename std::vector<E*>::const_iterator it = toProhibit.begin(); it != toProhibit.end(); ++it) {
129  toProhibitPE.push_back(myPedNet->getBothDirections(*it).first);
130  toProhibitPE.push_back(myPedNet->getBothDirections(*it).second);
131  }
132  myInternalRouter->prohibit(toProhibitPE);
133  }
134 
135 private:
136  const bool myAmClone;
139 
140 
141 private:
144 
145 };
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:276
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
long long int SUMOTime
Definition: SUMOTime.h:31
double gWeightsRandomFactor
Definition: StdDefs.cpp:29
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
Computes the shortest path through a network using the Dijkstra algorithm.
bool compute(const E *from, const E *to, const V *const vehicle, SUMOTime msTime, std::vector< const E * > &into, bool silent=false)
Builds the route between the given edges using the minimum effort at the given time The definition of...
void prohibit(const std::vector< E * > &toProhibit)
the base edge type that is given to the internal router (SUMOAbstractRouter)
static double getTravelTimeStatic(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, double time)
static double getTravelTimeStaticRandomized(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, double time)
the intermodal network storing edges, connections and the mappings to the "real" edges
_IntermodalEdge * getArrivalConnector(const E *e, const int splitIndex=0) const
Returns the arriving intermodal connector at the given split offset.
const EdgePair & getBothDirections(const E *e) const
Returns the pair of forward and backward edge.
const std::vector< _IntermodalEdge * > & getAllEdges()
_IntermodalEdge * getDepartConnector(const E *e, const int splitIndex=0) const
Returns the departing intermodal connector at the given split offset.
the "vehicle" type that is given to the internal router (SUMOAbstractRouter)
void prohibit(const std::vector< E * > &toProhibit)
DijkstraRouter< _IntermodalEdge, _IntermodalTrip > _InternalRouter
_IntermodalNetwork * myPedNet
PedestrianRouter & operator=(const PedestrianRouter &s)
Invalidated assignment operator.
IntermodalTrip< E, N, V > _IntermodalTrip
PedestrianRouter(_IntermodalNetwork *net)
IntermodalNetwork< E, L, N, V > _IntermodalNetwork
bool compute(const E *, const E *, const _IntermodalTrip *const, SUMOTime, std::vector< const E * > &, bool)
Builds the route between the given edges using the minimum effort at the given time The definition of...
PedestrianRouter()
Constructor.
virtual SUMOAbstractRouter< E, _IntermodalTrip > * clone()
IntermodalEdge< E, L, N, V > _IntermodalEdge
double compute(const E *from, const E *to, double departPos, double arrivalPos, double speed, SUMOTime msTime, const N *onlyNode, std::vector< const E * > &into, bool allEdges=false)
Builds the route between the given edges using the minimum effort at the given time The definition of...
virtual ~PedestrianRouter()
Destructor.
_InternalRouter * myInternalRouter
double getEffort(const E *const e, const V *const v, double t) const