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/****************************************************************************/
18// The ReversedEdge is a wrapper around a ROEdge or a MSEdge used for
19// backward search
20/****************************************************************************/
21#pragma once
22#include <config.h>
23
24
25// ===========================================================================
26// class definitions
27// ===========================================================================
29template<class E, class V>
31public:
32 typedef std::vector<std::pair<const ReversedEdge<E, V>*, const ReversedEdge<E, V>*> > ConstEdgePairVector;
33
34 ReversedEdge(const E* orig) : myOriginal(orig) {
35 }
36
37 void init() {
38 if (!myOriginal->isInternal()) {
39 for (const auto& viaPair : myOriginal->getViaSuccessors()) {
40 const ReversedEdge<E, V>* revSource = viaPair.first->getReversedRoutingEdge();
41 const E* via = viaPair.second;
42 const ReversedEdge<E, V>* preVia = nullptr;
43 while (via != nullptr && via->isInternal()) {
44 via->getReversedRoutingEdge()->myViaSuccessors.push_back(std::make_pair(this, preVia));
45 preVia = via->getReversedRoutingEdge();
46 via = via->getViaSuccessors().front().second;
47 }
48 revSource->myViaSuccessors.push_back(std::make_pair(this, preVia));
49 }
50 }
51 }
52
56 int getNumericalID() const {
57 return myOriginal->getNumericalID();
58 }
59
63 const std::string& getID() const {
64 return myOriginal->getID();
65 }
66
70 double getLength() const {
71 return myOriginal->getLength();
72 }
73
74 const ReversedEdge* getBidiEdge() const {
75 return myOriginal->getBidiEdge()->getReversedRoutingEdge();
76 }
77
78 bool isInternal() const {
79 return myOriginal->isInternal();
80 }
81
82 inline bool prohibits(const V* const vehicle) const {
83 return myOriginal->prohibits(vehicle);
84 }
85
86 inline bool restricts(const V* const vehicle) const {
87 return myOriginal->restricts(vehicle);
88 }
89
90 static inline double getTravelTimeStatic(const ReversedEdge<E, V>* const edge, const V* const veh, double time) {
91 return edge->myOriginal->getTravelTime(veh, time);
92 }
93
94 const ConstEdgePairVector& getViaSuccessors(SUMOVehicleClass vClass = SVC_IGNORING, bool ignoreTransientPermissions = false) const {
95 UNUSED_PARAMETER(ignoreTransientPermissions); // @todo this should be changed (somewhat hidden by #14756)
96 if (vClass == SVC_IGNORING || myOriginal->isTazConnector()) { // || !MSNet::getInstance()->hasPermissions()) {
97 return myViaSuccessors;
98 }
99#ifdef HAVE_FOX
100 FXMutexLock lock(mySuccessorMutex);
101#endif
102 auto i = myClassesViaSuccessorMap.find(vClass);
103 if (i != myClassesViaSuccessorMap.end()) {
104 // can use cached value
105 return i->second;
106 }
107 // instantiate vector
109 // this vClass is requested for the first time. rebuild all successors
110 for (const auto& viaPair : myViaSuccessors) {
111 if (viaPair.first->myOriginal->isTazConnector() || viaPair.first->myOriginal->isConnectedTo(*myOriginal, vClass)) {
112 result.push_back(viaPair);
113 }
114 }
115 return result;
116 }
117
118private:
119 const E* const myOriginal;
121 mutable std::map<SUMOVehicleClass, ConstEdgePairVector> myClassesViaSuccessorMap;
122
124
125#ifdef HAVE_FOX
127 mutable FXMutex mySuccessorMutex;
128#endif
129
130};
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
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)