20 #ifndef PedestrianRouter_h 21 #define PedestrianRouter_h 46 #define TL_RED_PENALTY 20 52 template <
class E,
class L>
57 const std::vector<L*>& lanes = edge->getLanes();
58 for (
typename std::vector<L*>::const_iterator it = lanes.begin(); it != lanes.end(); ++it) {
71 template<
class E,
class N>
78 departPos(_departPos < 0 ? _from->getLength() + _departPos : _departPos),
79 arrivalPos(_arrivalPos < 0 ? _to->getLength() + _arrivalPos : _arrivalPos),
108 template<
class E,
class L,
class N>
110 typedef std::pair<PedestrianEdge*, PedestrianEdge*>
EdgePair;
117 return myEdgeDict.size();
121 myFromToLookup.clear();
122 myBidiLookup.clear();
127 if (myEdgeDict.size() > 0) {
130 #ifdef PedestrianRouter_DEBUG_NETWORK 131 std::cout <<
"initPedestrianNetwork\n";
134 bool haveSeenWalkingArea =
false;
135 unsigned int numericalID = 0;
136 for (
size_t i = 0; i < noE; i++) {
137 E* edge = E::dictionary(i);
138 const L* lane = getSidewalk<E, L>(edge);
139 if (edge->isInternal() || lane == 0) {
141 }
else if (edge->isWalkingArea()) {
143 myEdgeDict.push_back(
PedestrianEdge(numericalID++, edge, lane,
true));
144 haveSeenWalkingArea =
true;
147 myEdgeDict.push_back(
PedestrianEdge(numericalID++, edge, lane,
true));
148 myEdgeDict.push_back(
PedestrianEdge(numericalID++, edge, lane,
false));
150 myEdgeDict.push_back(
PedestrianEdge(numericalID++, edge, lane,
true,
true));
151 myEdgeDict.push_back(
PedestrianEdge(numericalID++, edge, lane,
false,
true));
157 for (
size_t i = 0; i < noE; i++) {
158 E* edge = E::dictionary(i);
159 const L* lane = getSidewalk<E, L>(edge);
160 if (edge->isInternal() || lane == 0) {
162 }
else if (edge->isWalkingArea()) {
164 myBidiLookup[edge] = std::make_pair(&myEdgeDict[numericalID], &myEdgeDict[numericalID]);
165 myFromToLookup[edge] = std::make_pair(&myEdgeDict[numericalID], &myEdgeDict[numericalID]);
168 myBidiLookup[edge] = std::make_pair(&myEdgeDict[numericalID], &myEdgeDict[numericalID + 1]);
169 myFromToLookup[edge] = std::make_pair(&myEdgeDict[numericalID + 2], &myEdgeDict[numericalID + 3]);
175 for (
size_t i = 0; i < noE; i++) {
176 E* edge = E::dictionary(i);
177 const L* sidewalk = getSidewalk<E, L>(edge);
178 if (edge->isInternal() || sidewalk == 0) {
183 const EdgePair& pair = getBothDirections(edge);
184 #ifdef PedestrianRouter_DEBUG_NETWORK 185 std::cout <<
" building connections from " << sidewalk->getID() <<
"\n";
187 if (haveSeenWalkingArea) {
188 std::vector<const L*> outgoing = sidewalk->getOutgoingLanes();
191 bool hasWalkingArea =
false;
192 for (
typename std::vector<const L*>::iterator it = outgoing.begin(); it != outgoing.end(); ++it) {
193 const L* target = *it;
194 const E* targetEdge = &(target->getEdge());
195 if (targetEdge->isWalkingArea()) {
196 hasWalkingArea =
true;
200 for (
typename std::vector<const L*>::iterator it = outgoing.begin(); it != outgoing.end(); ++it) {
201 const L* target = *it;
202 const E* targetEdge = &(target->getEdge());
203 const bool used = (target == getSidewalk<E, L>(targetEdge)
204 && (!hasWalkingArea || targetEdge->isWalkingArea()));
205 #ifdef PedestrianRouter_DEBUG_NETWORK 206 const L* potTarget = getSidewalk<E, L>(targetEdge);
207 std::cout <<
" lane=" << (potTarget == 0 ?
"NULL" : potTarget->getID()) << (used ?
"(used)" :
"") <<
"\n";
210 const EdgePair& targetPair = getBothDirections(targetEdge);
211 pair.first->myFollowingEdges.push_back(targetPair.first);
212 targetPair.second->myFollowingEdges.push_back(pair.second);
213 #ifdef PedestrianRouter_DEBUG_NETWORK 214 std::cout <<
" " << pair.first->getID() <<
" -> " << targetPair.first->getID() <<
"\n";
215 std::cout <<
" " << targetPair.second->getID() <<
" -> " << pair.second->getID() <<
"\n";
222 const N* toNode = edge->getToJunction();
223 std::vector<const E*> outgoing = toNode->getOutgoing();
224 for (
typename std::vector<const E*>::iterator it = outgoing.begin(); it != outgoing.end(); ++it) {
226 const E* targetEdge = *it;
227 const L* target = getSidewalk<E, L>(targetEdge);
228 if (targetEdge->isInternal() || target == 0) {
231 const EdgePair& targetPair = getBothDirections(targetEdge);
232 pair.first->myFollowingEdges.push_back(targetPair.first);
233 targetPair.second->myFollowingEdges.push_back(pair.second);
234 #ifdef PedestrianRouter_DEBUG_NETWORK 235 std::cout <<
" " << pair.first->getID() <<
" -> " << targetPair.first->getID() <<
"\n";
236 std::cout <<
" " << targetPair.second->getID() <<
" -> " << pair.second->getID() <<
"\n";
239 std::vector<const E*> incoming = toNode->getIncoming();
240 for (
typename std::vector<const E*>::iterator it = incoming.begin(); it != incoming.end(); ++it) {
242 const E* targetEdge = *it;
243 const L* target = getSidewalk<E, L>(targetEdge);
244 if (targetEdge->isInternal() || target == 0 || targetEdge == edge) {
247 const EdgePair& targetPair = getBothDirections(targetEdge);
248 pair.first->myFollowingEdges.push_back(targetPair.second);
249 #ifdef PedestrianRouter_DEBUG_NETWORK 250 std::cout <<
" " << pair.first->getID() <<
" -> " << targetPair.second->getID() <<
"\n";
254 const N* fromNode = edge->getFromJunction();
255 outgoing = fromNode->getOutgoing();
256 for (
typename std::vector<const E*>::iterator it = outgoing.begin(); it != outgoing.end(); ++it) {
258 const E* targetEdge = *it;
259 const L* target = getSidewalk<E, L>(targetEdge);
260 if (targetEdge->isInternal() || target == 0 || targetEdge == edge) {
263 const EdgePair& targetPair = getBothDirections(targetEdge);
264 pair.second->myFollowingEdges.push_back(targetPair.first);
265 #ifdef PedestrianRouter_DEBUG_NETWORK 266 std::cout <<
" " << pair.second->getID() <<
" -> " << targetPair.first->getID() <<
"\n";
270 if (edge->isWalkingArea()) {
279 pair.first->myFollowingEdges.push_back(endConnector);
280 pair.second->myFollowingEdges.push_back(endConnector);
281 #ifdef PedestrianRouter_DEBUG_NETWORK 282 std::cout <<
" " << startConnector->
getID() <<
" -> " << pair.first->getID() <<
"\n";
283 std::cout <<
" " << startConnector->
getID() <<
" -> " << pair.second->getID() <<
"\n";
284 std::cout <<
" " << pair.first->getID() <<
" -> " << endConnector->
getID() <<
"\n";
285 std::cout <<
" " << pair.second->getID() <<
" -> " << endConnector->
getID() <<
"\n";
291 return !myAmConnector && (allEdges || (!myEdge->isCrossing() && !myEdge->isWalkingArea()));
300 typename std::map<const E*, EdgePair>::const_iterator it = myBidiLookup.find(e);
301 if (it == myBidiLookup.end()) {
303 throw ProcessError(
"Edge '" + e->getID() +
"' not found in pedestrian network '");
310 typename std::map<const E*, EdgePair>::const_iterator it = myFromToLookup.find(e);
311 if (it == myFromToLookup.end()) {
313 throw ProcessError(
"Edge '" + e->getID() +
"' not found in pedestrian network '");
315 return (*it).second.first;
320 typename std::map<const E*, EdgePair>::const_iterator it = myFromToLookup.find(e);
321 if (it == myFromToLookup.end()) {
323 throw ProcessError(
"Edge '" + e->getID() +
"' not found in pedestrian network '");
325 return (*it).second.second;
332 return myNumericalID;
337 assert(index < myEdgeDict.size());
338 return &myEdgeDict[index];
342 return (
unsigned int)myFollowingEdges.size();
346 return myFollowingEdges;
351 return myFollowingEdges;
355 if (trip->
node == 0) {
360 return (myEdge->getFromJunction() != trip->
node 361 && myEdge->getToJunction() != trip->
node);
398 #ifdef PedestrianRouter_DEBUG_EFFORTS 399 std::cout <<
" effort for " << trip->
getID() <<
" at " << time <<
" edge=" << edge->
getID() <<
" effort=" << length / trip->
speed + tlsDelay <<
" l=" << length <<
" s=" << trip->
speed <<
" tlsDelay=" << tlsDelay <<
"\n";
401 return length / trip->
speed + tlsDelay;
405 PedestrianEdge(
unsigned int numericalID,
const E* edge,
const L* lane,
bool forward,
bool connector =
false) :
406 Named(edge->
getID() + (edge->isWalkingArea() ?
"" :
407 ((forward ?
"_fwd" :
"_bwd") + std::string(connector ?
"_connector" :
"")))),
408 myNumericalID(numericalID),
412 myAmConnector(connector) { }
448 template<
class E,
class L,
class N,
class INTERNALROUTER>
458 _PedestrianEdge::initPedestrianNetwork(E::dictSize());
459 myInternalRouter =
new INTERNALROUTER(_PedestrianEdge::dictSize(),
true, &_PedestrianEdge::getEffort);
464 delete myInternalRouter;
474 SUMOTime msTime,
const N* onlyNode, std::vector<const E*>& into,
bool allEdges =
false) {
476 if (getSidewalk<E, L>(from) == 0) {
477 WRITE_WARNING(
"Departure edge '" + from->getID() +
"' does not allow pedestrians.");
480 if (getSidewalk<E, L>(to) == 0) {
481 WRITE_WARNING(
"Destination edge '" + to->getID() +
"' does not allow pedestrians.");
484 _PedestrianTrip trip(from, to, departPos, arrivalPos, speed, msTime, onlyNode);
485 std::vector<const _PedestrianEdge*> intoPed;
486 myInternalRouter->compute(_PedestrianEdge::getDepartEdge(from),
487 _PedestrianEdge::getArrivalEdge(to), &trip, msTime, intoPed);
488 for (
size_t i = 0; i < intoPed.size(); ++i) {
489 if (intoPed[i]->includeInRoute(allEdges)) {
490 into.push_back(intoPed[i]->getEdge());
493 #ifdef PedestrianRouter_DEBUG_ROUTES 495 for (
size_t i = 0; i < intoPed.size(); ++i) {
496 time += myInternalRouter->getEffort(intoPed[i], &trip, time);
498 std::cout <<
TIME2STEPS(msTime) <<
" trip from " << from->getID() <<
" to " << to->getID()
499 <<
" departPos=" << departPos
500 <<
" arrivalPos=" << arrivalPos
501 <<
" onlyNode=" << (onlyNode == 0 ?
"NULL" : onlyNode->getID())
503 <<
" resultEdges=" <<
toString(into)
512 void compute(
const E*,
const E*,
const _PedestrianTrip*
const,
522 std::vector<_PedestrianEdge*> toProhibitPE;
523 for (
typename std::vector<E*>::const_iterator it = toProhibit.begin(); it != toProhibit.end(); ++it) {
524 toProhibitPE.push_back(_PedestrianEdge::getBothDirections(*it).first);
525 toProhibitPE.push_back(_PedestrianEdge::getBothDirections(*it).second);
527 myInternalRouter->prohibit(toProhibitPE);
543 template<
class E,
class L,
class N>
545 DijkstraRouterTT<PedestrianEdge<E, L, N>, PedestrianTrip<E, N>, prohibited_withPermissions<PedestrianEdge<E, L, N>, PedestrianTrip<E, N> > > > { };
552 template<
class E,
class L,
class N>
555 template<
class E,
class L,
class N>
558 template<
class E,
class L,
class N>
SUMOVehicleClass getVClass() const
PedestrianRouter()
Constructor.
const std::vector< PedestrianEdge * > & getSuccessors() const
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
const L * getSidewalk(const E *edge)
INTERNALROUTER * myInternalRouter
static const EdgePair & getBothDirections(const E *e)
Returns the pair of forward and backward edge.
void compute(const E *, const E *, const _PedestrianTrip *const, SUMOTime, std::vector< const E * > &)
Builds the route between the given edges using the minimum effort at the given time The definition of...
static PedestrianEdge * getDepartEdge(const E *e)
Returns the departing Pedestrian edge.
bool includeInRoute(bool allEdges) const
std::string getID() const
std::string time2string(SUMOTime t)
the "vehicle" type that is given to the internal router (SUMOAbstractRouter)
std::pair< PedestrianEdge *, PedestrianEdge * > EdgePair
std::vector< PedestrianEdge * > myFollowingEdges
List of edges that may be approached from this edge.
static std::vector< PedestrianEdge > myEdgeDict
the edge dictionary
bool myForward
the direction of this edge
const SUMOTime departTime
static PedestrianEdge * getArrivalEdge(const E *e)
Returns the arriving Pedestrian edge.
PedestrianTrip(const E *_from, const E *_to, SUMOReal _departPos, SUMOReal _arrivalPos, SUMOReal _speed, SUMOTime _departTime, const N *_node)
PedestrianTrip & operator=(const PedestrianTrip &)
Invalidated assignment operator.
#define WRITE_WARNING(msg)
const E * myEdge
the original edge
const std::string & getID() const
Returns the id.
void 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...
unsigned int getNumSuccessors() const
const E * getEdge() const
bool myAmConnector
the direction of this edge
bool prohibits(const PedestrianTrip< E, N > *const trip) const
PedestrianTrip< E, N > _PedestrianTrip
const SUMOReal arrivalPos
const L * myLane
the original edge
PedestrianEdge< E, L, N > _PedestrianEdge
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Base class for objects which have an id.
unsigned int getNumericalID() const
void prohibit(const std::vector< E * > &toProhibit)
static const PedestrianEdge * dictionary(size_t index)
Returns the PedstrianEdge with the given numericalID.
const std::vector< PedestrianEdge * > & getSuccessors(SUMOVehicleClass) const
PedestrianEdge(unsigned int numericalID, const E *edge, const L *lane, bool forward, bool connector=false)
The link has red light (must brake)
static std::map< const E *, EdgePair > myBidiLookup
retrieve the forward and backward edge for the given input edge E
the edge type that is given to the internal router (SUMOAbstractRouter)
virtual SUMOAbstractRouter< E, PedestrianTrip< E, N > > * clone() const
static SUMOReal getEffort(const PedestrianEdge *const edge, const PedestrianTrip< E, N > *const trip, SUMOReal time)
unsigned int myNumericalID
the index in myEdgeDict
SUMOReal recomputeCosts(const std::vector< const E * > &, const _PedestrianTrip *const, SUMOTime) const
virtual ~PedestrianRouter()
Destructor.
static void initPedestrianNetwork(size_t noE)
static std::map< const E *, EdgePair > myFromToLookup
retrieve the depart and arrival edge for the given input edge E