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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
14 // The Pedestrian Router builds a special network and delegates to a SUMOAbstractRouter.
15 /****************************************************************************/
16 #ifndef PedestrianRouter_h
17 #define PedestrianRouter_h
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <string>
26 #include <vector>
27 #include <algorithm>
28 #include <assert.h>
30 #include <utils/common/SUMOTime.h>
31 #include <utils/common/ToString.h>
32 #include "SUMOAbstractRouter.h"
33 #include "DijkstraRouter.h"
34 #include "IntermodalNetwork.h"
35 
36 //#define PedestrianRouter_DEBUG_ROUTES
37 
38 
39 // ===========================================================================
40 // class definitions
41 // ===========================================================================
46 template<class E, class L, class N, class V>
47 class PedestrianRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> > {
48 private:
53 
54 public:
57  SUMOAbstractRouter<E, _IntermodalTrip>("PedestrianRouter", true, nullptr, nullptr, false, false), myAmClone(false) {
58  myPedNet = new _IntermodalNetwork(E::getAllEdges(), true);
61  }
62 
64  SUMOAbstractRouter<E, _IntermodalTrip>("PedestrianRouterClone", true, nullptr, nullptr, false, false), myAmClone(true) {
65  myPedNet = net;
68  }
69 
71  virtual ~PedestrianRouter() {
72  delete myInternalRouter;
73  if (!myAmClone) {
74  delete myPedNet;
75  }
76  }
77 
80  }
81 
84  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  if (getSidewalk<E, L>(from) == 0) {
87  WRITE_WARNING("Departure edge '" + from->getID() + "' does not allow pedestrians.");
88  return false;
89  }
90  if (getSidewalk<E, L>(to) == 0) {
91  WRITE_WARNING("Destination edge '" + to->getID() + "' does not allow pedestrians.");
92  return false;
93  }
94  _IntermodalTrip trip(from, to, departPos, arrivalPos, speed, msTime, onlyNode);
95  std::vector<const _IntermodalEdge*> intoPed;
96  const bool success = myInternalRouter->compute(myPedNet->getDepartConnector(from),
98  &trip, msTime, intoPed);
99  double time = 0.;
100  if (success) {
101  for (const _IntermodalEdge* pedEdge : intoPed) {
102  if (pedEdge->includeInRoute(allEdges)) {
103  into.push_back(pedEdge->getEdge());
104  }
105  time += myInternalRouter->getEffort(pedEdge, &trip, time);
106  }
107  }
108 #ifdef PedestrianRouter_DEBUG_ROUTES
109  std::cout << TIME2STEPS(msTime) << " trip from " << from->getID() << " to " << to->getID()
110  << " departPos=" << departPos
111  << " arrivalPos=" << arrivalPos
112  << " onlyNode=" << (onlyNode == 0 ? "NULL" : onlyNode->getID())
113  << " edges=" << toString(intoPed)
114  << " resultEdges=" << toString(into)
115  << " time=" << time
116  << "\n";
117 #endif
118  return success ? time : -1.;
119  }
120 
123  bool compute(const E*, const E*, const _IntermodalTrip* const,
124  SUMOTime, std::vector<const E*>&, bool) {
125  throw ProcessError("Do not use this method");
126  }
127 
128  void prohibit(const std::vector<E*>& toProhibit) {
129  std::vector<_IntermodalEdge*> toProhibitPE;
130  for (typename std::vector<E*>::const_iterator it = toProhibit.begin(); it != toProhibit.end(); ++it) {
131  toProhibitPE.push_back(myPedNet->getBothDirections(*it).first);
132  toProhibitPE.push_back(myPedNet->getBothDirections(*it).second);
133  }
134  myInternalRouter->prohibit(toProhibitPE);
135  }
136 
137 private:
138  const bool myAmClone;
141 
142 
143 private:
146 
147 };
148 
149 
150 #endif
151 
152 /****************************************************************************/
PedestrianRouter::myAmClone
const bool myAmClone
Definition: PedestrianRouter.h:138
ToString.h
PedestrianRouter
Definition: MSNet.h:81
WRITE_WARNING
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:275
SUMOTime.h
PedestrianRouter::PedestrianRouter
PedestrianRouter()
Constructor.
Definition: PedestrianRouter.h:56
PedestrianRouter::compute
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...
Definition: PedestrianRouter.h:84
PedestrianRouter::operator=
PedestrianRouter & operator=(const PedestrianRouter &s)
Invalidated assignment operator.
MsgHandler.h
IntermodalEdge::getTravelTimeStaticRandomized
static double getTravelTimeStaticRandomized(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, double time)
Definition: IntermodalEdge.h:123
SUMOAbstractRouter::getEffort
double getEffort(const E *const e, const V *const v, double t) const
Definition: SUMOAbstractRouter.h:216
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
PedestrianRouter::_IntermodalNetwork
IntermodalNetwork< E, L, N, V > _IntermodalNetwork
Definition: PedestrianRouter.h:50
IntermodalEdge
the base edge type that is given to the internal router (SUMOAbstractRouter)
Definition: IntermodalEdge.h:39
DijkstraRouter
Computes the shortest path through a network using the Dijkstra algorithm.
Definition: DijkstraRouter.h:61
gWeightsRandomFactor
double gWeightsRandomFactor
Definition: StdDefs.cpp:30
PedestrianRouter::~PedestrianRouter
virtual ~PedestrianRouter()
Destructor.
Definition: PedestrianRouter.h:71
TIME2STEPS
#define TIME2STEPS(x)
Definition: SUMOTime.h:58
IntermodalEdge::getTravelTimeStatic
static double getTravelTimeStatic(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, double time)
Definition: IntermodalEdge.h:119
PedestrianRouter::compute
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...
Definition: PedestrianRouter.h:123
PedestrianRouter::clone
virtual SUMOAbstractRouter< E, _IntermodalTrip > * clone()
Definition: PedestrianRouter.h:78
PedestrianRouter::myPedNet
_IntermodalNetwork * myPedNet
Definition: PedestrianRouter.h:140
ProcessError
Definition: UtilExceptions.h:39
DijkstraRouter::compute
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...
Definition: DijkstraRouter.h:113
PedestrianRouter::prohibit
void prohibit(const std::vector< E * > &toProhibit)
Definition: PedestrianRouter.h:128
IntermodalNetwork::getDepartConnector
_IntermodalEdge * getDepartConnector(const E *e, const int splitIndex=0) const
Returns the departing intermodal connector at the given split offset.
Definition: IntermodalNetwork.h:335
IntermodalNetwork::getAllEdges
const std::vector< _IntermodalEdge * > & getAllEdges()
Definition: IntermodalNetwork.h:280
SUMOAbstractRouter
Definition: SUMOAbstractRouter.h:46
PedestrianRouter::_IntermodalEdge
IntermodalEdge< E, L, N, V > _IntermodalEdge
Definition: PedestrianRouter.h:49
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
DijkstraRouter::prohibit
void prohibit(const std::vector< E * > &toProhibit)
Definition: DijkstraRouter.h:229
PedestrianRouter::_InternalRouter
DijkstraRouter< _IntermodalEdge, _IntermodalTrip > _InternalRouter
Definition: PedestrianRouter.h:52
IntermodalNetwork
the intermodal network storing edges, connections and the mappings to the "real" edges
Definition: IntermodalNetwork.h:76
IntermodalNetwork::getBothDirections
const EdgePair & getBothDirections(const E *e) const
Returns the pair of forward and backward edge.
Definition: IntermodalNetwork.h:285
PedestrianRouter::PedestrianRouter
PedestrianRouter(_IntermodalNetwork *net)
Definition: PedestrianRouter.h:63
config.h
IntermodalNetwork::getArrivalConnector
_IntermodalEdge * getArrivalConnector(const E *e, const int splitIndex=0) const
Returns the arriving intermodal connector at the given split offset.
Definition: IntermodalNetwork.h:363
DijkstraRouter.h
SUMOAbstractRouter.h
IntermodalTrip
the "vehicle" type that is given to the internal router (SUMOAbstractRouter)
Definition: IntermodalTrip.h:38
PedestrianRouter::_IntermodalTrip
IntermodalTrip< E, N, V > _IntermodalTrip
Definition: PedestrianRouter.h:51
PedestrianRouter::myInternalRouter
_InternalRouter * myInternalRouter
Definition: PedestrianRouter.h:139
IntermodalNetwork.h