SUMO - Simulation of Urban MObility
PedestrianRouter.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // The Pedestrian Router builds a special network and delegates to a SUMOAbstractRouter.
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 #ifndef PedestrianRouter_h
21 #define PedestrianRouter_h
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <vector>
35 #include <algorithm>
36 #include <assert.h>
38 #include <utils/common/SUMOTime.h>
39 #include <utils/common/ToString.h>
40 #include "SUMOAbstractRouter.h"
41 #include "DijkstraRouterTT.h"
42 #include "IntermodalNetwork.h"
43 
44 //#define PedestrianRouter_DEBUG_ROUTES
45 
46 
47 // ===========================================================================
48 // class definitions
49 // ===========================================================================
54 template<class E, class L, class N, class V, class INTERNALROUTER>
55 class PedestrianRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> > {
56 public:
57 
61 
64  SUMOAbstractRouter<E, _IntermodalTrip>(0, "PedestrianRouter"), myAmClone(false) {
65  myPedNet = new _IntermodalNetwork(E::getAllEdges());
67  }
68 
69  PedestrianRouter(_IntermodalNetwork* net):
70  SUMOAbstractRouter<E, _IntermodalTrip>(0, "PedestrianRouter"), myAmClone(true) {
71  myPedNet = net;
73  }
74 
76  virtual ~PedestrianRouter() {
77  delete myInternalRouter;
78  if (!myAmClone) {
79  delete myPedNet;
80  }
81  }
82 
85  }
86 
89  bool compute(const E* from, const E* to, SUMOReal departPos, SUMOReal arrivalPos, SUMOReal speed,
90  SUMOTime msTime, const N* onlyNode, std::vector<const E*>& into, bool allEdges = false) {
91  //startQuery();
92  if (getSidewalk<E, L>(from) == 0) {
93  WRITE_WARNING("Departure edge '" + from->getID() + "' does not allow pedestrians.");
94  return false;
95  }
96  if (getSidewalk<E, L>(to) == 0) {
97  WRITE_WARNING("Destination edge '" + to->getID() + "' does not allow pedestrians.");
98  return false;
99  }
100  _IntermodalTrip trip(from, to, departPos, arrivalPos, speed, msTime, onlyNode);
101  std::vector<const _IntermodalEdge*> intoPed;
102  const bool success = myInternalRouter->compute(myPedNet->getDepartEdge(from),
104  &trip, msTime, intoPed);
105  if (success) {
106  for (size_t i = 0; i < intoPed.size(); ++i) {
107  if (intoPed[i]->includeInRoute(allEdges)) {
108  into.push_back(intoPed[i]->getEdge());
109  }
110  }
111  }
112 #ifdef PedestrianRouter_DEBUG_ROUTES
113  SUMOReal time = msTime;
114  for (size_t i = 0; i < intoPed.size(); ++i) {
115  time += myInternalRouter->getEffort(intoPed[i], &trip, time);
116  }
117  std::cout << TIME2STEPS(msTime) << " trip from " << from->getID() << " to " << to->getID()
118  << " departPos=" << departPos
119  << " arrivalPos=" << arrivalPos
120  << " onlyNode=" << (onlyNode == 0 ? "NULL" : onlyNode->getID())
121  << " edges=" << toString(intoPed)
122  << " resultEdges=" << toString(into)
123  << " time=" << time
124  << "\n";
125 #endif
126  //endQuery();
127  return success;
128  }
129 
132  bool compute(const E*, const E*, const _IntermodalTrip* const,
133  SUMOTime, std::vector<const E*>&) {
134  throw ProcessError("Do not use this method");
135  }
136 
137  SUMOReal recomputeCosts(const std::vector<const E*>&, const _IntermodalTrip* const, SUMOTime) const {
138  throw ProcessError("Do not use this method");
139  }
140 
141  void prohibit(const std::vector<E*>& toProhibit) {
142  std::vector<_IntermodalEdge*> toProhibitPE;
143  for (typename std::vector<E*>::const_iterator it = toProhibit.begin(); it != toProhibit.end(); ++it) {
144  toProhibitPE.push_back(myPedNet->getBothDirections(*it).first);
145  toProhibitPE.push_back(myPedNet->getBothDirections(*it).second);
146  }
147  myInternalRouter->prohibit(toProhibitPE);
148  }
149 
150 private:
151  const bool myAmClone;
152  INTERNALROUTER* myInternalRouter;
153  _IntermodalNetwork* myPedNet;
154 
155 
156 private:
159 
160 };
161 
162 // common specializations
163 template<class E, class L, class N, class V>
164 class PedestrianRouterDijkstra : public PedestrianRouter < E, L, N, V,
165  DijkstraRouterTT<IntermodalEdge<E, L, N, V>, IntermodalTrip<E, N, V>, prohibited_withPermissions<IntermodalEdge<E, L, N, V>, IntermodalTrip<E, N, V> > > > { };
166 
167 
168 #endif
169 
170 /****************************************************************************/
long long int SUMOTime
Definition: SUMOTime.h:43
const std::vector< _IntermodalEdge * > & getAllEdges()
bool compute(const E *from, const E *to, SUMOReal departPos, SUMOReal arrivalPos, SUMOReal 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...
INTERNALROUTER * myInternalRouter
IntermodalNetwork< E, L, N, V > _IntermodalNetwork
SUMOReal recomputeCosts(const std::vector< const E * > &, const _IntermodalTrip *const, SUMOTime) const
PedestrianRouter()
Constructor.
_IntermodalEdge * getDepartEdge(const E *e, const SUMOReal pos=-1.)
Returns the departing Intermodal edge.
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
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...
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
_IntermodalEdge * getArrivalEdge(const E *e, const SUMOReal pos=-1.)
Returns the arriving Intermodal edge.
the "vehicle" type that is given to the internal router (SUMOAbstractRouter)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:54
the pedestrian network storing edges, connections and the mappings to the "real" edges ...
the base edge type that is given to the internal router (SUMOAbstractRouter)
const EdgePair & getBothDirections(const E *e)
Returns the pair of forward and backward edge.
static SUMOReal getTravelTimeStatic(const IntermodalEdge *const edge, const IntermodalTrip< E, N, V > *const trip, SUMOReal time)
#define SUMOReal
Definition: config.h:213
_IntermodalNetwork * myPedNet
virtual ~PedestrianRouter()
Destructor.
void prohibit(const std::vector< E * > &toProhibit)
IntermodalTrip< E, N, V > _IntermodalTrip