Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/router/ReversedEdge.h
169678 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file ReversedEdge.h
15
/// @author Michael Behrisch
16
/// @author Ruediger Ebendt
17
/// @date 29.01.2020
18
///
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
// ===========================================================================
29
/// @brief the edge type representing backward edges
30
template<class E, class V>
31
class ReversedEdge {
32
public:
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
54
/// @brief Returns the original edge
55
const E* getOriginalEdge() const {
56
return myOriginal;
57
}
58
59
/** @brief Returns the index (numeric id) of the edge
60
* @return The original edge's numerical id
61
*/
62
int getNumericalID() const {
63
return myOriginal->getNumericalID();
64
}
65
66
/** @brief Returns the id of the edge
67
* @return The original edge's id
68
*/
69
const std::string& getID() const {
70
return myOriginal->getID();
71
}
72
73
/** @brief Returns the length of the edge
74
* @return The original edge's length
75
*/
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
114
ConstEdgePairVector& result = myClassesViaSuccessorMap[vClass];
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
124
private:
125
const E* const myOriginal;
126
/// @brief The successors available for a given vClass
127
mutable std::map<SUMOVehicleClass, ConstEdgePairVector> myClassesViaSuccessorMap;
128
129
mutable ConstEdgePairVector myViaSuccessors;
130
131
#ifdef HAVE_FOX
132
/// @brief Mutex for accessing successor edges
133
mutable FXMutex mySuccessorMutex;
134
#endif
135
136
};
137
138