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 /****************************************************************************/
15 // The Pedestrian Router builds a special network and delegates to a SUMOAbstractRouter.
16 /****************************************************************************/
17 #ifndef PedestrianRouter_h
18 #define PedestrianRouter_h
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <vector>
28 #include <algorithm>
29 #include <assert.h>
31 #include <utils/common/SUMOTime.h>
32 #include <utils/common/ToString.h>
33 #include "SUMOAbstractRouter.h"
34 #include "DijkstraRouter.h"
35 #include "IntermodalNetwork.h"
36 
37 //#define PedestrianRouter_DEBUG_ROUTES
38 
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
47 template<class E, class L, class N, class V>
48 class PedestrianRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> > {
49 private:
54 
55 public:
58  SUMOAbstractRouter<E, _IntermodalTrip>("PedestrianRouter", true), myAmClone(false) {
59  myPedNet = new _IntermodalNetwork(E::getAllEdges(), true);
62  }
63 
64  PedestrianRouter(_IntermodalNetwork* net):
65  SUMOAbstractRouter<E, _IntermodalTrip>("PedestrianRouterClone", true), myAmClone(true) {
66  myPedNet = net;
69  }
70 
72  virtual ~PedestrianRouter() {
73  delete myInternalRouter;
74  if (!myAmClone) {
75  delete myPedNet;
76  }
77  }
78 
81  }
82 
85  double compute(const E* from, const E* to, double departPos, double arrivalPos, double speed,
86  SUMOTime msTime, const N* onlyNode, std::vector<const E*>& into, bool allEdges = false) {
87  if (getSidewalk<E, L>(from) == 0) {
88  WRITE_WARNING("Departure edge '" + from->getID() + "' does not allow pedestrians.");
89  return false;
90  }
91  if (getSidewalk<E, L>(to) == 0) {
92  WRITE_WARNING("Destination edge '" + to->getID() + "' does not allow pedestrians.");
93  return false;
94  }
95  _IntermodalTrip trip(from, to, departPos, arrivalPos, speed, msTime, onlyNode);
96  std::vector<const _IntermodalEdge*> intoPed;
97  const bool success = myInternalRouter->compute(myPedNet->getDepartConnector(from),
99  &trip, msTime, intoPed);
100  double time = 0.;
101  if (success) {
102  for (const _IntermodalEdge* pedEdge : intoPed) {
103  if (pedEdge->includeInRoute(allEdges)) {
104  into.push_back(pedEdge->getEdge());
105  }
106  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  }
121 
124  bool compute(const E*, const E*, const _IntermodalTrip* const,
125  SUMOTime, std::vector<const E*>&, bool) {
126  throw ProcessError("Do not use this method");
127  }
128 
129  void prohibit(const std::vector<E*>& toProhibit) {
130  std::vector<_IntermodalEdge*> toProhibitPE;
131  for (typename std::vector<E*>::const_iterator it = toProhibit.begin(); it != toProhibit.end(); ++it) {
132  toProhibitPE.push_back(myPedNet->getBothDirections(*it).first);
133  toProhibitPE.push_back(myPedNet->getBothDirections(*it).second);
134  }
135  myInternalRouter->prohibit(toProhibitPE);
136  }
137 
138 private:
139  const bool myAmClone;
140  _InternalRouter* myInternalRouter;
141  _IntermodalNetwork* myPedNet;
142 
143 
144 private:
147 
148 };
149 
150 
151 #endif
152 
153 /****************************************************************************/
const EdgePair & getBothDirections(const E *e) const
Returns the pair of forward and backward edge.
long long int SUMOTime
Definition: SUMOTime.h:35
_IntermodalEdge * getDepartConnector(const E *e, const int splitIndex=0) const
Returns the departing intermodal connector at the given split offset.
const std::vector< _IntermodalEdge * > & getAllEdges()
virtual ~PedestrianRouter()
Destructor.
virtual SUMOAbstractRouter< E, _IntermodalTrip > * clone()
IntermodalTrip< E, N, V > _IntermodalTrip
static double getTravelTimeStatic(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, double time)
#define TIME2STEPS(x)
Definition: SUMOTime.h:59
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
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.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
Computes the shortest path through a network using the Dijkstra algorithm.
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...
_IntermodalNetwork * myPedNet
_IntermodalEdge * getArrivalConnector(const E *e, const int splitIndex=0) const
Returns the arriving intermodal connector at the given split offset.
IntermodalEdge< E, L, N, V > _IntermodalEdge
PedestrianRouter & operator=(const PedestrianRouter &s)
Invalidated assignment operator.
the intermodal network storing edges, connections and the mappings to the "real" edges ...
double gWeightsRandomFactor
Definition: StdDefs.cpp:31
the base edge type that is given to the internal router (SUMOAbstractRouter)
virtual 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)
_InternalRouter * myInternalRouter
PedestrianRouter(_IntermodalNetwork *net)
static double getTravelTimeStaticRandomized(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, double time)
IntermodalNetwork< E, L, N, V > _IntermodalNetwork
the "vehicle" type that is given to the internal router (SUMOAbstractRouter)
DijkstraRouter< _IntermodalEdge, _IntermodalTrip, SUMOAbstractRouterPermissions< _IntermodalEdge, _IntermodalTrip > > _InternalRouter