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 IntermodalEdge.h
15 : /// @author Jakob Erdmann
16 : /// @author Michael Behrisch
17 : /// @author Robert Hilbrich
18 : /// @date Mon, 03 March 2014
19 : ///
20 : // The Edge definition for the Intermodal Router
21 : /****************************************************************************/
22 : #pragma once
23 : #include <config.h>
24 :
25 : #include <string>
26 : #include <vector>
27 : #include <utils/common/SUMOVehicleClass.h>
28 : #include <utils/common/ValueTimeLine.h>
29 : #include <utils/common/RandHelper.h>
30 : #include <utils/common/Named.h>
31 : #include "IntermodalTrip.h"
32 :
33 : // ===========================================================================
34 : // function definitions
35 : // ===========================================================================
36 : template <class E, class L>
37 7614056 : inline const L* getSidewalk(const E* edge, SUMOVehicleClass svc = SVC_PEDESTRIAN) {
38 7721653 : if (edge == nullptr) {
39 : return nullptr;
40 : }
41 : // prefer lanes that are exclusive to pedestrians
42 : const std::vector<L*>& lanes = edge->getLanes();
43 10946092 : for (const L* const lane : lanes) {
44 8982568 : if (lane->getPermissions() == svc) {
45 : return lane;
46 : }
47 : }
48 2510946 : for (const L* const lane : lanes) {
49 2081049 : if (lane->allowsVehicleClass(svc)) {
50 : return lane;
51 : }
52 : }
53 322050 : if (svc != SVC_PEDESTRIAN) {
54 : // persons should always be able to use the sidewalk
55 0 : for (const L* const lane : lanes) {
56 0 : if (lane->getPermissions() == SVC_PEDESTRIAN) {
57 : return lane;
58 : }
59 : }
60 0 : for (const L* const lane : lanes) {
61 0 : if (lane->allowsVehicleClass(SVC_PEDESTRIAN)) {
62 : return lane;
63 : }
64 : }
65 : }
66 : return nullptr;
67 : }
68 :
69 :
70 :
71 : // ===========================================================================
72 : // class definitions
73 : // ===========================================================================
74 : /// @brief the base edge type that is given to the internal router (SUMOAbstractRouter)
75 : template<class E, class L, class N, class V>
76 : class IntermodalEdge : public Named {
77 : public:
78 3339502 : IntermodalEdge(const std::string id, int numericalID, const E* edge, const std::string& line, const double length = -1) :
79 : Named(id),
80 3339502 : myNumericalID(numericalID),
81 3339502 : myEdge(edge),
82 3339502 : myLine(line),
83 3339502 : myLength(edge == nullptr || length >= 0. ? MAX2(0.0, length) : edge->getLength()),
84 6679004 : myEfforts(nullptr) { }
85 :
86 4829340 : virtual ~IntermodalEdge() {}
87 :
88 1248962 : virtual bool includeInRoute(bool /* allEdges */) const {
89 1248962 : return false;
90 : }
91 :
92 : inline const std::string& getLine() const {
93 994571 : return myLine;
94 : }
95 :
96 : inline const E* getEdge() const {
97 52200765 : return myEdge;
98 : }
99 :
100 : int getNumericalID() const {
101 76660239 : return myNumericalID;
102 : }
103 :
104 : void addSuccessor(IntermodalEdge* const s, IntermodalEdge* const via = nullptr) {
105 5512710 : myFollowingEdges.push_back(s);
106 4433402 : myFollowingViaEdges.push_back(std::make_pair(s, via));
107 : }
108 :
109 70095 : void transferSuccessors(IntermodalEdge* to) {
110 70095 : to->myFollowingEdges = myFollowingEdges;
111 70095 : to->myFollowingViaEdges = myFollowingViaEdges;
112 : myFollowingEdges.clear();
113 : myFollowingViaEdges.clear();
114 70095 : }
115 :
116 69660 : bool removeSuccessor(const IntermodalEdge* const edge) {
117 69660 : auto it = std::find(myFollowingEdges.begin(), myFollowingEdges.end(), edge);
118 69660 : if (it != myFollowingEdges.end()) {
119 69448 : myFollowingEdges.erase(it);
120 : } else {
121 : return false;
122 : }
123 280450 : for (auto viaIt = myFollowingViaEdges.begin(); viaIt != myFollowingViaEdges.end();) {
124 211002 : if (viaIt->first == edge) {
125 : viaIt = myFollowingViaEdges.erase(viaIt);
126 : } else {
127 : ++viaIt;
128 : }
129 : }
130 : return true;
131 : }
132 :
133 1620 : virtual const std::vector<IntermodalEdge*>& getSuccessors(SUMOVehicleClass vClass = SVC_IGNORING) const {
134 : UNUSED_PARAMETER(vClass);
135 : // the network is already tailored. No need to check for permissions here
136 1620 : return myFollowingEdges;
137 : }
138 :
139 23257083 : virtual const std::vector<std::pair<const IntermodalEdge*, const IntermodalEdge*> >& getViaSuccessors(SUMOVehicleClass vClass = SVC_IGNORING, bool ignoreTransientPermissions = false) const {
140 : UNUSED_PARAMETER(vClass);
141 : UNUSED_PARAMETER(ignoreTransientPermissions);
142 : // the network is already tailored. No need to check for permissions here
143 23257083 : return myFollowingViaEdges;
144 : }
145 :
146 13147054 : virtual bool prohibits(const IntermodalTrip<E, N, V>* const /* trip */) const {
147 13147054 : return false;
148 : }
149 :
150 0 : virtual bool restricts(const IntermodalTrip<E, N, V>* const /* trip */) const {
151 0 : return false;
152 : }
153 :
154 459041 : virtual inline double getPartialLength(const IntermodalTrip<E, N, V>* const /*trip*/) const {
155 459041 : return myLength;
156 : }
157 :
158 :
159 5669711 : virtual inline double getTravelTime(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
160 5669711 : return 0.;
161 : }
162 :
163 19060 : virtual inline double getTravelTimeAggregated(const IntermodalTrip<E, N, V>* const trip, double time) const {
164 19060 : return getTravelTime(trip, time);
165 : }
166 :
167 : /// @brief get intended vehicle id and departure time of next public transport ride
168 0 : virtual inline double getIntended(const double /* time */, std::string& /* intended */) const {
169 0 : return 0.;
170 : }
171 :
172 26936781 : static inline double getTravelTimeStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
173 26936781 : return edge == nullptr ? 0. : edge->getTravelTime(trip, time);
174 : }
175 :
176 88752 : static inline double getTravelTimeStaticRandomized(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
177 88752 : return edge == nullptr ? 0. : edge->getTravelTime(trip, time) * RandHelper::rand(1., gWeightsRandomFactor);
178 : }
179 :
180 23300 : static inline double getTravelTimeAggregated(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
181 23300 : return edge == nullptr ? 0. : edge->getTravelTimeAggregated(trip, time);
182 : }
183 :
184 :
185 824 : virtual double getEffort(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
186 824 : return 0.;
187 : }
188 :
189 0 : static inline double getEffortStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
190 0 : return edge == nullptr || !edge->hasEffort() ? 0. : edge->getEffort(trip, time);
191 : }
192 :
193 : /// @brief required by DijkstraRouter et al for external effort computation
194 : inline double getLength() const {
195 25424990 : return myLength;
196 : }
197 :
198 : inline void setLength(const double length) {
199 : assert(length >= 0);
200 139320 : myLength = length;
201 46875 : }
202 :
203 : inline bool isInternal() const {
204 97966 : return myEdge != nullptr && myEdge->isInternal();
205 : }
206 :
207 0 : virtual bool hasEffort() const {
208 0 : return myEfforts != nullptr;
209 : }
210 :
211 3668 : virtual double getStartPos() const {
212 3668 : return 0.;
213 : }
214 :
215 6305 : virtual double getEndPos() const {
216 6305 : return myLength;
217 : }
218 :
219 : // only used by AStar
220 : inline double getSpeedLimit() const {
221 468252 : return myEdge != nullptr ? myEdge->getSpeedLimit() : 200. / 3.6;
222 : }
223 :
224 : // only used by AStar
225 : inline double getLengthGeometryFactor() const {
226 468252 : return myEdge != nullptr ? myEdge->getLengthGeometryFactor() : 1;
227 : }
228 :
229 : // only used by AStar
230 33604 : inline double getDistanceTo(const IntermodalEdge* other) const {
231 33604 : return myEdge != nullptr && other->myEdge != nullptr && myEdge != other->myEdge ? myEdge->getDistanceTo(other->myEdge, true) : 0.;
232 : }
233 :
234 : // only used by AStar
235 : inline double getMinimumTravelTime(const IntermodalTrip<E, N, V>* const trip) const {
236 0 : return myLength / trip->getMaxSpeed();
237 : }
238 :
239 : /// @brief only used by mono-modal routing
240 : IntermodalEdge* getBidiEdge() const {
241 : return nullptr;
242 : }
243 :
244 : protected:
245 : /// @brief List of edges that may be approached from this edge
246 : std::vector<IntermodalEdge*> myFollowingEdges;
247 :
248 : /// @brief List of edges that may be approached from this edge with optional internal vias
249 : std::vector<std::pair<const IntermodalEdge*, const IntermodalEdge*> > myFollowingViaEdges;
250 :
251 : private:
252 : /// @brief the index in myEdges
253 : const int myNumericalID;
254 :
255 : /// @brief the original edge
256 : const E* const myEdge;
257 :
258 : /// @brief public transport line or ped vs car
259 : const std::string myLine;
260 :
261 : /// @brief adaptable length (for splitted edges)
262 : double myLength;
263 :
264 : /// @brief Container for passing effort varying over time for the edge
265 : ValueTimeLine<double>* myEfforts;
266 :
267 : private:
268 : /// @brief Invalidated copy constructor
269 : IntermodalEdge(const IntermodalEdge& src);
270 :
271 : /// @brief Invalidated assignment operator
272 : IntermodalEdge& operator=(const IntermodalEdge& src);
273 :
274 : };
|