Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/router/IntermodalEdge.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 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
inline const L* getSidewalk(const E* edge, SUMOVehicleClass svc = SVC_PEDESTRIAN) {
38
if (edge == nullptr) {
39
return nullptr;
40
}
41
// prefer lanes that are exclusive to pedestrians
42
const std::vector<L*>& lanes = edge->getLanes();
43
for (const L* const lane : lanes) {
44
if (lane->getPermissions() == svc) {
45
return lane;
46
}
47
}
48
for (const L* const lane : lanes) {
49
if (lane->allowsVehicleClass(svc)) {
50
return lane;
51
}
52
}
53
if (svc != SVC_PEDESTRIAN) {
54
// persons should always be able to use the sidewalk
55
for (const L* const lane : lanes) {
56
if (lane->getPermissions() == SVC_PEDESTRIAN) {
57
return lane;
58
}
59
}
60
for (const L* const lane : lanes) {
61
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
IntermodalEdge(const std::string id, int numericalID, const E* edge, const std::string& line, const double length = -1) :
79
Named(id),
80
myNumericalID(numericalID),
81
myEdge(edge),
82
myLine(line),
83
myLength(edge == nullptr || length >= 0. ? MAX2(0.0, length) : edge->getLength()),
84
myEfforts(nullptr) { }
85
86
virtual ~IntermodalEdge() {}
87
88
virtual bool includeInRoute(bool /* allEdges */) const {
89
return false;
90
}
91
92
inline const std::string& getLine() const {
93
return myLine;
94
}
95
96
inline const E* getEdge() const {
97
return myEdge;
98
}
99
100
int getNumericalID() const {
101
return myNumericalID;
102
}
103
104
void addSuccessor(IntermodalEdge* const s, IntermodalEdge* const via = nullptr) {
105
myFollowingEdges.push_back(s);
106
myFollowingViaEdges.push_back(std::make_pair(s, via));
107
}
108
109
void transferSuccessors(IntermodalEdge* to) {
110
to->myFollowingEdges = myFollowingEdges;
111
to->myFollowingViaEdges = myFollowingViaEdges;
112
myFollowingEdges.clear();
113
myFollowingViaEdges.clear();
114
}
115
116
bool removeSuccessor(const IntermodalEdge* const edge) {
117
auto it = std::find(myFollowingEdges.begin(), myFollowingEdges.end(), edge);
118
if (it != myFollowingEdges.end()) {
119
myFollowingEdges.erase(it);
120
} else {
121
return false;
122
}
123
for (auto viaIt = myFollowingViaEdges.begin(); viaIt != myFollowingViaEdges.end();) {
124
if (viaIt->first == edge) {
125
viaIt = myFollowingViaEdges.erase(viaIt);
126
} else {
127
++viaIt;
128
}
129
}
130
return true;
131
}
132
133
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
return myFollowingEdges;
137
}
138
139
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
return myFollowingViaEdges;
144
}
145
146
virtual bool prohibits(const IntermodalTrip<E, N, V>* const /* trip */) const {
147
return false;
148
}
149
150
virtual bool restricts(const IntermodalTrip<E, N, V>* const /* trip */) const {
151
return false;
152
}
153
154
virtual inline double getPartialLength(const IntermodalTrip<E, N, V>* const /*trip*/) const {
155
return myLength;
156
}
157
158
159
virtual inline double getTravelTime(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
160
return 0.;
161
}
162
163
virtual inline double getTravelTimeAggregated(const IntermodalTrip<E, N, V>* const trip, double time) const {
164
return getTravelTime(trip, time);
165
}
166
167
/// @brief get intended vehicle id and departure time of next public transport ride
168
virtual inline double getIntended(const double /* time */, std::string& /* intended */) const {
169
return 0.;
170
}
171
172
static inline double getTravelTimeStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
173
return edge == nullptr ? 0. : edge->getTravelTime(trip, time);
174
}
175
176
static inline double getTravelTimeStaticRandomized(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
177
return edge == nullptr ? 0. : edge->getTravelTime(trip, time) * RandHelper::rand(1., gWeightsRandomFactor);
178
}
179
180
static inline double getTravelTimeAggregated(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
181
return edge == nullptr ? 0. : edge->getTravelTimeAggregated(trip, time);
182
}
183
184
185
virtual double getEffort(const IntermodalTrip<E, N, V>* const /* trip */, double /* time */) const {
186
return 0.;
187
}
188
189
static inline double getEffortStatic(const IntermodalEdge* const edge, const IntermodalTrip<E, N, V>* const trip, double time) {
190
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
return myLength;
196
}
197
198
inline void setLength(const double length) {
199
assert(length >= 0);
200
myLength = length;
201
}
202
203
inline bool isInternal() const {
204
return myEdge != nullptr && myEdge->isInternal();
205
}
206
207
virtual bool hasEffort() const {
208
return myEfforts != nullptr;
209
}
210
211
virtual double getStartPos() const {
212
return 0.;
213
}
214
215
virtual double getEndPos() const {
216
return myLength;
217
}
218
219
// only used by AStar
220
inline double getSpeedLimit() const {
221
return myEdge != nullptr ? myEdge->getSpeedLimit() : 200. / 3.6;
222
}
223
224
// only used by AStar
225
inline double getLengthGeometryFactor() const {
226
return myEdge != nullptr ? myEdge->getLengthGeometryFactor() : 1;
227
}
228
229
// only used by AStar
230
inline double getDistanceTo(const IntermodalEdge* other) const {
231
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
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
};
275
276