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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // The Pedestrian Router builds a special network and delegates to a SUMOAbstractRouter.
18 /****************************************************************************/
19 #ifndef PedestrianRouter_h
20 #define PedestrianRouter_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <vector>
34 #include <algorithm>
35 #include <assert.h>
37 #include <utils/common/SUMOTime.h>
38 #include <utils/common/ToString.h>
39 #include "SUMOAbstractRouter.h"
40 #include "DijkstraRouter.h"
41 #include "IntermodalNetwork.h"
42 
43 //#define PedestrianRouter_DEBUG_ROUTES
44 
45 
46 // ===========================================================================
47 // class definitions
48 // ===========================================================================
53 template<class E, class L, class N, class V, class INTERNALROUTER>
54 class PedestrianRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> > {
55 public:
56 
60 
63  SUMOAbstractRouter<E, _IntermodalTrip>(0, "PedestrianRouter"), myAmClone(false) {
64  myPedNet = new _IntermodalNetwork(E::getAllEdges());
66  }
67 
68  PedestrianRouter(_IntermodalNetwork* net):
69  SUMOAbstractRouter<E, _IntermodalTrip>(0, "PedestrianRouter"), myAmClone(true) {
70  myPedNet = net;
72  }
73 
75  virtual ~PedestrianRouter() {
76  delete myInternalRouter;
77  if (!myAmClone) {
78  delete myPedNet;
79  }
80  }
81 
84  }
85 
88  double compute(const E* from, const E* to, double departPos, double arrivalPos, double speed,
89  SUMOTime msTime, const N* onlyNode, std::vector<const E*>& into, bool allEdges = false) {
90  if (getSidewalk<E, L>(from) == 0) {
91  WRITE_WARNING("Departure edge '" + from->getID() + "' does not allow pedestrians.");
92  return false;
93  }
94  if (getSidewalk<E, L>(to) == 0) {
95  WRITE_WARNING("Destination edge '" + to->getID() + "' does not allow pedestrians.");
96  return false;
97  }
98  _IntermodalTrip trip(from, to, departPos, arrivalPos, speed, msTime, onlyNode);
99  std::vector<const _IntermodalEdge*> intoPed;
100  const bool success = myInternalRouter->compute(myPedNet->getDepartConnector(from),
102  &trip, msTime, intoPed);
103  double time = 0.;
104  if (success) {
105  for (const _IntermodalEdge* pedEdge : intoPed) {
106  if (pedEdge->includeInRoute(allEdges)) {
107  into.push_back(pedEdge->getEdge());
108  }
109  time += myInternalRouter->getEffort(pedEdge, &trip, time);
110  }
111  }
112 #ifdef PedestrianRouter_DEBUG_ROUTES
113  std::cout << TIME2STEPS(msTime) << " trip from " << from->getID() << " to " << to->getID()
114  << " departPos=" << departPos
115  << " arrivalPos=" << arrivalPos
116  << " onlyNode=" << (onlyNode == 0 ? "NULL" : onlyNode->getID())
117  << " edges=" << toString(intoPed)
118  << " resultEdges=" << toString(into)
119  << " time=" << time
120  << "\n";
121 #endif
122  return success ? time : -1.;
123  }
124 
127  bool compute(const E*, const E*, const _IntermodalTrip* const,
128  SUMOTime, std::vector<const E*>&) {
129  throw ProcessError("Do not use this method");
130  }
131 
132  double recomputeCosts(const std::vector<const E*>&, const _IntermodalTrip* const, SUMOTime) const {
133  throw ProcessError("Do not use this method");
134  }
135 
136  void prohibit(const std::vector<E*>& toProhibit) {
137  std::vector<_IntermodalEdge*> toProhibitPE;
138  for (typename std::vector<E*>::const_iterator it = toProhibit.begin(); it != toProhibit.end(); ++it) {
139  toProhibitPE.push_back(myPedNet->getBothDirections(*it).first);
140  toProhibitPE.push_back(myPedNet->getBothDirections(*it).second);
141  }
142  myInternalRouter->prohibit(toProhibitPE);
143  }
144 
145 private:
146  const bool myAmClone;
147  INTERNALROUTER* myInternalRouter;
148  _IntermodalNetwork* myPedNet;
149 
150 
151 private:
154 
155 };
156 
157 // common specializations
158 template<class E, class L, class N, class V>
159 class PedestrianRouterDijkstra : public PedestrianRouter < E, L, N, V,
160  DijkstraRouter<IntermodalEdge<E, L, N, V>, IntermodalTrip<E, N, V>, prohibited_withPermissions<IntermodalEdge<E, L, N, V>, IntermodalTrip<E, N, V> > > > { };
161 
162 
163 #endif
164 
165 /****************************************************************************/
const EdgePair & getBothDirections(const E *e) const
Returns the pair of forward and backward edge.
_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()
INTERNALROUTER * myInternalRouter
IntermodalNetwork< E, L, N, V > _IntermodalNetwork
PedestrianRouter()
Constructor.
static double getTravelTimeStatic(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, double time)
PedestrianRouter(_IntermodalNetwork *net)
virtual SUMOAbstractRouter< E, _IntermodalTrip > * clone()
IntermodalEdge< E, L, N, V > _IntermodalEdge
PedestrianRouter & operator=(const PedestrianRouter &s)
Invalidated assignment operator.
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
bool compute(const E *, const E *, const _IntermodalTrip *const, SUMOTime, std::vector< const E *> &)
Builds the route between the given edges using the minimum effort at the given time The definition of...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
void prohibit(const std::vector< E *> &toProhibit)
double recomputeCosts(const std::vector< const E *> &, const _IntermodalTrip *const, SUMOTime) const
_IntermodalEdge * getArrivalConnector(const E *e, const int splitIndex=0) const
Returns the arriving intermodal connector at the given split offset.
the "vehicle" type that is given to the internal router (SUMOAbstractRouter)
the intermodal network storing edges, connections and the mappings to the "real" edges ...
the base edge type that is given to the internal router (SUMOAbstractRouter)
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...
long long int SUMOTime
Definition: TraCIDefs.h:51
_IntermodalNetwork * myPedNet
virtual ~PedestrianRouter()
Destructor.
IntermodalTrip< E, N, V > _IntermodalTrip