Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
ReversedEdge.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-2024 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/****************************************************************************/
19// The ReversedEdge is a wrapper around a ROEdge or a MSEdge used for
20// backward search
21/****************************************************************************/
22#pragma once
23#include <config.h>
24
25
26// ===========================================================================
27// class definitions
28// ===========================================================================
30template<class E, class V>
32public:
33 typedef std::vector<std::pair<const ReversedEdge<E, V>*, const ReversedEdge<E, V>*> > ConstEdgePairVector;
34
35 ReversedEdge(const E* orig) : myOriginal(orig) {
36 }
37
38 void init() {
39 if (!myOriginal->isInternal()) {
40 for (const auto& viaPair : myOriginal->getViaSuccessors()) {
41 const ReversedEdge<E, V>* revSource = viaPair.first->getReversedRoutingEdge();
42 const E* via = viaPair.second;
43 const ReversedEdge<E, V>* preVia = nullptr;
44 while (via != nullptr && via->isInternal()) {
45 via->getReversedRoutingEdge()->myViaSuccessors.push_back(std::make_pair(this, preVia));
46 preVia = via->getReversedRoutingEdge();
47 via = via->getViaSuccessors().front().second;
48 }
49 revSource->myViaSuccessors.push_back(std::make_pair(this, preVia));
50 }
51 }
52 }
53
55 const E* getOriginalEdge() const {
56 return myOriginal;
57 }
58
62 int getNumericalID() const {
63 return myOriginal->getNumericalID();
64 }
65
69 const std::string& getID() const {
70 return myOriginal->getID();
71 }
72
76 double getLength() const {
77 return myOriginal->getLength();
78 }
79
80 const ReversedEdge* getBidiEdge() const {
81 return myOriginal->getBidiEdge()->getReversedRoutingEdge();
82 }
83
84 bool isInternal() const {
85 return myOriginal->isInternal();
86 }
87
88 inline bool prohibits(const V* const vehicle) const {
89 return myOriginal->prohibits(vehicle);
90 }
91
92 inline bool restricts(const V* const vehicle) const {
93 return myOriginal->restricts(vehicle);
94 }
95
96 static inline double getTravelTimeStatic(const ReversedEdge<E, V>* const edge, const V* const veh, double time) {
97 return edge->myOriginal->getTravelTime(veh, time);
98 }
99
100 const ConstEdgePairVector& getViaSuccessors(SUMOVehicleClass vClass = SVC_IGNORING, bool ignoreTransientPermissions = false) const {
101 UNUSED_PARAMETER(ignoreTransientPermissions); // @todo this should be changed (somewhat hidden by #14756)
102 if (vClass == SVC_IGNORING || myOriginal->isTazConnector()) { // || !MSNet::getInstance()->hasPermissions()) {
103 return myViaSuccessors;
104 }
105#ifdef HAVE_FOX
106 FXMutexLock lock(mySuccessorMutex);
107#endif
108 auto i = myClassesViaSuccessorMap.find(vClass);
109 if (i != myClassesViaSuccessorMap.end()) {
110 // can use cached value
111 return i->second;
112 }
113 // instantiate vector
115 // this vClass is requested for the first time. rebuild all successors
116 for (const auto& viaPair : myViaSuccessors) {
117 if (viaPair.first->myOriginal->isTazConnector() || viaPair.first->myOriginal->isConnectedTo(*myOriginal, vClass)) {
118 result.push_back(viaPair);
119 }
120 }
121 return result;
122 }
123
124private:
125 const E* const myOriginal;
127 mutable std::map<SUMOVehicleClass, ConstEdgePairVector> myClassesViaSuccessorMap;
128
130
131#ifdef HAVE_FOX
133 mutable FXMutex mySuccessorMutex;
134#endif
135
136};
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
#define UNUSED_PARAMETER(x)
Definition StdDefs.h:30
the edge type representing backward edges
const ConstEdgePairVector & getViaSuccessors(SUMOVehicleClass vClass=SVC_IGNORING, bool ignoreTransientPermissions=false) const
double getLength() const
Returns the length of the edge.
const std::string & getID() const
Returns the id of the edge.
std::vector< std::pair< const ReversedEdge< E, V > *, const ReversedEdge< E, V > * > > ConstEdgePairVector
ConstEdgePairVector myViaSuccessors
const E *const myOriginal
bool prohibits(const V *const vehicle) const
std::map< SUMOVehicleClass, ConstEdgePairVector > myClassesViaSuccessorMap
The successors available for a given vClass.
const ReversedEdge * getBidiEdge() const
const E * getOriginalEdge() const
Returns the original edge.
bool restricts(const V *const vehicle) const
ReversedEdge(const E *orig)
int getNumericalID() const
Returns the index (numeric id) of the edge.
bool isInternal() const
static double getTravelTimeStatic(const ReversedEdge< E, V > *const edge, const V *const veh, double time)