Line data Source code
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 : /****************************************************************************/
14 : /// @file ReversedEdge.h
15 : /// @author Michael Behrisch
16 : /// @date 29.01.2020
17 : ///
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 : // ===========================================================================
28 : /// @brief the edge type representing backward edges
29 : template<class E, class V>
30 : class ReversedEdge {
31 : public:
32 : typedef std::vector<std::pair<const ReversedEdge<E, V>*, const ReversedEdge<E, V>*> > ConstEdgePairVector;
33 :
34 20488 : ReversedEdge(const E* orig) : myOriginal(orig) {
35 20488 : }
36 :
37 20488 : void init() {
38 20488 : if (!myOriginal->isInternal()) {
39 16904 : for (const auto& viaPair : myOriginal->getViaSuccessors()) {
40 13296 : const ReversedEdge<E, V>* revSource = viaPair.first->getReversedRoutingEdge();
41 13296 : const E* via = viaPair.second;
42 : const ReversedEdge<E, V>* preVia = nullptr;
43 30176 : while (via != nullptr && via->isInternal()) {
44 16880 : via->getReversedRoutingEdge()->myViaSuccessors.push_back(std::make_pair(this, preVia));
45 16880 : preVia = via->getReversedRoutingEdge();
46 16880 : via = via->getViaSuccessors().front().second;
47 : }
48 13296 : revSource->myViaSuccessors.push_back(std::make_pair(this, preVia));
49 : }
50 : }
51 20488 : }
52 :
53 : /** @brief Returns the index (numeric id) of the edge
54 : * @return The original edge's numerical id
55 : */
56 : int getNumericalID() const {
57 9684 : return myOriginal->getNumericalID();
58 : }
59 :
60 : /** @brief Returns the id of the edge
61 : * @return The original edge's id
62 : */
63 : const std::string& getID() const {
64 0 : return myOriginal->getID();
65 : }
66 :
67 : /** @brief Returns the length of the edge
68 : * @return The original edge's length
69 : */
70 : double getLength() const {
71 17066 : return myOriginal->getLength();
72 : }
73 :
74 : const ReversedEdge* getBidiEdge() const {
75 : return myOriginal->getBidiEdge()->getReversedRoutingEdge();
76 : }
77 :
78 : bool isInternal() const {
79 17066 : return myOriginal->isInternal();
80 : }
81 :
82 : inline bool prohibits(const V* const vehicle) const {
83 0 : return myOriginal->prohibits(vehicle);
84 : }
85 :
86 : inline bool restricts(const V* const vehicle) const {
87 0 : return myOriginal->restricts(vehicle);
88 : }
89 :
90 29162 : static inline double getTravelTimeStatic(const ReversedEdge<E, V>* const edge, const V* const veh, double time) {
91 29162 : return edge->myOriginal->getTravelTime(veh, time);
92 : }
93 :
94 1436 : 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 1436 : if (vClass == SVC_IGNORING || myOriginal->isTazConnector()) { // || !MSNet::getInstance()->hasPermissions()) {
97 0 : return myViaSuccessors;
98 : }
99 : #ifdef HAVE_FOX
100 1436 : FXMutexLock lock(mySuccessorMutex);
101 : #endif
102 : auto i = myClassesViaSuccessorMap.find(vClass);
103 1436 : if (i != myClassesViaSuccessorMap.end()) {
104 : // can use cached value
105 716 : return i->second;
106 : }
107 : // instantiate vector
108 720 : ConstEdgePairVector& result = myClassesViaSuccessorMap[vClass];
109 : // this vClass is requested for the first time. rebuild all successors
110 3376 : for (const auto& viaPair : myViaSuccessors) {
111 2656 : if (viaPair.first->myOriginal->isTazConnector() || viaPair.first->myOriginal->isConnectedTo(*myOriginal, vClass)) {
112 2656 : result.push_back(viaPair);
113 : }
114 : }
115 : return result;
116 : }
117 :
118 : private:
119 : const E* const myOriginal;
120 : /// @brief The successors available for a given vClass
121 : mutable std::map<SUMOVehicleClass, ConstEdgePairVector> myClassesViaSuccessorMap;
122 :
123 : mutable ConstEdgePairVector myViaSuccessors;
124 :
125 : #ifdef HAVE_FOX
126 : /// @brief Mutex for accessing successor edges
127 : mutable FXMutex mySuccessorMutex;
128 : #endif
129 :
130 : };
|