Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
PedestrianRouter.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2026 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>
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// ===========================================================================
44template<class E, class L, class N, class V>
45class PedestrianRouter : public SUMOAbstractRouter<E, IntermodalTrip<E, N, V> > {
46private:
51
52public:
55 SUMOAbstractRouter<E, _IntermodalTrip>("PedestrianRouter", true, nullptr, nullptr, false, false), myAmClone(false) {
56 myPedNet = new _IntermodalNetwork(E::getAllEdges(), true);
59 nullptr, false, nullptr, true);
60 }
61
63 SUMOAbstractRouter<E, _IntermodalTrip>("PedestrianRouterClone", true, nullptr, nullptr, false, false), myAmClone(true) {
64 myPedNet = net;
67 nullptr, false, nullptr, true);
68 }
69
72 delete myInternalRouter;
73 if (!myAmClone) {
74 delete myPedNet;
75 }
76 }
77
81
84 double compute(const E* from, const E* to, double departPos, double arrivalPos, double speed,
85 SUMOTime msTime, const N* onlyNode, const SUMOVTypeParameter& pars, std::vector<const E*>& into, bool allEdges = false) const {
86 if (getSidewalk<E, L>(from) == 0) {
87 WRITE_WARNINGF(TL("Departure edge '%' does not allow pedestrians."), from->getID());
88 return false;
89 }
90 if (getSidewalk<E, L>(to) == 0) {
91 WRITE_WARNINGF(TL("Destination edge '%' does not allow pedestrians."), to->getID());
92 return false;
93 }
94 _IntermodalTrip trip(from, to, departPos, arrivalPos, speed, msTime, onlyNode, pars);
95 std::vector<const _IntermodalEdge*> intoPed;
96 const bool silent = allEdges; // no warning is needed when called from MSPModel_Striping
97 const bool success = myInternalRouter->compute(myPedNet->getDepartConnector(from),
99 &trip, msTime, intoPed, silent);
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(TL("Do not use this method"));
127 }
128
129 void prohibit(const std::map<const E*, RouterProhibition>& toProhibit) {
130 typename _InternalRouter::Prohibitions toProhibitPE;
131 for (auto item : toProhibit) {
132 // an edge without pedestrian edges in the network (e.g. closed for pedestrians when the network was built)
133 // cannot be walked on anyway (#18601)
134 if (myPedNet->hasBothDirections(item.first)) {
135 toProhibitPE[myPedNet->getBothDirections(item.first).first] = item.second;
136 toProhibitPE[myPedNet->getBothDirections(item.first).second] = item.second;
137 }
138 }
139 myInternalRouter->prohibit(toProhibitPE);
140 }
141
142 double recomputeWalkCosts(const std::vector<const E*>& edges, double speed, double fromPos, double toPos, SUMOTime msTime, const SUMOVTypeParameter& pars, double& length) const {
143 // edges are normal edges so we need to reconstruct paths across intersection
144 if (edges.size() == 0) {
145 length = 0;
146 return 0;
147 } else if (edges.size() == 1) {
148 length = fabs(toPos - fromPos);
149 return length / speed;
150 } else {
151 double cost = 0;
152 int last = (int)edges.size() - 1;
153 for (int i = 0; i < last; i++) {
154 std::vector<const E*> into;
155 const E* from = edges[i];
156 const E* to = edges[i + 1];
157 const double fp = (i == 0 ? fromPos : from->getLength() / 2);
158 const double tp = (i == (last - 1) ? toPos : to->getLength() / 2);
159 const N* node = getCommonNode(from, to);
160 if (i == 0) {
161 if (node == from->getToJunction()) {
162 length += from->getLength() - fromPos;
163 } else {
164 length += fromPos;
165 }
166 } else {
167 length += from->getLength();
168 }
169 if (i == (last - 1)) {
170 if (node == to->getFromJunction()) {
171 length += toPos;
172 } else {
173 length += to->getLength() - toPos;
174 }
175 }
176 double time = this->compute(from, to, fp, tp, speed, msTime, node, pars, into, true);
177 if (time >= 0) {
178 cost += time;
179 for (const E* edge : into) {
180 if (edge->isCrossing()) {
181 length += edge->getLength();
182 } else if (edge->isWalkingArea()) {
183 // this is wrong because the length is path-dependent
184 length += edge->getLength();
185 }
186 }
187 } else {
188 throw ProcessError("Could not compute cost between edge '" + from->getID() + "' and edge '" + to->getID() + "'.");
189 }
190 }
191 return cost;
192 }
193 }
194
195
196private:
197 const bool myAmClone;
200
201 const N* getCommonNode(const E* from, const E* to) const {
202 if (from->getToJunction() == to->getFromJunction() || from->getToJunction() == to->getToJunction()) {
203 return from->getToJunction();
204 } else if (from->getFromJunction() == to->getFromJunction() || from->getFromJunction() == to->getToJunction()) {
205 return from->getFromJunction();
206 } else {
207 return nullptr;
208 }
209 }
210
211private:
214
215};
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:299
#define TL(string)
Definition MsgHandler.h:316
constexpr SUMOTime TIME2STEPS(double x)
Definition SUMOTime.h:60
double gWeightsRandomFactor
Definition StdDefs.cpp:35
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:57
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...
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
const std::vector< _IntermodalEdge * > & getAllEdges()
_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.
bool hasBothDirections(const E *e) const
Returns whether the network contains pedestrian edges for the given edge.
_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)
PedestrianRouter & operator=(const PedestrianRouter &s)
Invalidated assignment operator.
DijkstraRouter< _IntermodalEdge, _IntermodalTrip > _InternalRouter
_IntermodalNetwork * myPedNet
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.
void prohibit(const std::map< const E *, RouterProhibition > &toProhibit)
double compute(const E *from, const E *to, double departPos, double arrivalPos, double speed, SUMOTime msTime, const N *onlyNode, const SUMOVTypeParameter &pars, std::vector< const E * > &into, bool allEdges=false) const
Builds the route between the given edges using the minimum effort at the given time The definition of...
double recomputeWalkCosts(const std::vector< const E * > &edges, double speed, double fromPos, double toPos, SUMOTime msTime, const SUMOVTypeParameter &pars, double &length) const
IntermodalEdge< E, L, N, V > _IntermodalEdge
virtual SUMOAbstractRouter< E, _IntermodalTrip > * clone()
const N * getCommonNode(const E *from, const E *to) const
virtual ~PedestrianRouter()
Destructor.
_InternalRouter * myInternalRouter
std::map< const E *, RouterProhibition > Prohibitions
double getEffort(const E *const e, const V *const v, double t) const
virtual void prohibit(const Prohibitions &toProhibit)
Structure representing possible vehicle parameter.
unsigned node