Skip to content

Commit 2a3eeee

Browse files
committed
Clarify documentation and variable naming in ElevatorProcessor.
1 parent 41f8c36 commit 2a3eeee

1 file changed

Lines changed: 53 additions & 36 deletions

File tree

application/src/main/java/org/opentripplanner/graph_builder/module/osm/ElevatorProcessor.java

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,47 @@
4040
* which is the reason this is not a public class.
4141
* <p>
4242
* Elevators have three types of edges: ElevatorAlightEdges, ElevatorHopEdges, and
43-
* ElevatorBoardEdges. The build process involves creating FreeEdges to disconnect from the
44-
* graph, GenericVertices to serve as attachment points, and ElevatorBoardEdges and
45-
* ElevatorAlightEdges to connect future ElevatorHopEdges to.
43+
* ElevatorBoardEdges. Elevators also have two types of vertices: the OsmElevatorVertex and the
44+
* ElevatorHopVertex.
45+
* <p>
46+
* For elevator nodes, the build process first generates OsmElevatorVertices during previous phases
47+
* of the graph build. These vertices serve as attachment points to the graph for elevators.
48+
* Elevator ways connect to the graph by using existing intersection vertices that are also part of
49+
* the elevator way.
50+
* <p>
51+
* The next step is to iterate over these attachment points and generate the ElevatorBoardEdges and
52+
* ElevatorAlightEdges. The other end for these edges is an ElevatorHopVertex. The
53+
* ElevatorBoardEdge allows boarding while the ElevatorAlightEdge allows alighting the elevator.
54+
* <p>
55+
* The last step is to connect all ElevatorHopVertices with ElevatorHopEdges. The amount of levels
56+
* between ElevatorHopVertices is stored in the edge. This incurs a cost dependent on the amount of
57+
* levels traveled. If the ElevatorHopVertices are on the same level (for example because of bad
58+
* data), the ElevatorHopEdge can have a cost of zero, but the board cost still applies in the
59+
* ElevatorBoardEdge.
4660
* <p>
4761
* With two connected ways to a node (which can be on the same level), after building the
4862
* ElevatorAlightEdge and ElevatorBoardEdge the graph will look like this (side view):
4963
*
50-
* +==+~~X
64+
* +==X
5165
*
52-
* +==+~~X
66+
* +==X
5367
*
54-
* + GenericVertex
55-
* X EndpointVertex
56-
* ~~ FreeEdge
57-
* == ElevatorBoardEdge/ElevatorAlightEdge
68+
* + ElevatorHopVertex
69+
* X OsmElevatorVertex or IntersectionVertex
70+
* == ElevatorBoardEdge and ElevatorAlightEdge
5871
* <p>
5972
* Another loop fills in the ElevatorHopEdges. After filling in the ElevatorHopEdges when a node
6073
* has 3 connected ways the graph will look like this (side view):
6174
*
62-
* +==+~~X
75+
* +==X
6376
* |
64-
* +==+~~X
77+
* +==X
6578
* |
66-
* +==+~~X
79+
* +==X
6780
*
68-
* + GenericVertex
69-
* X EndpointVertex
70-
* ~~ FreeEdge
71-
* == ElevatorBoardEdge/ElevatorAlightEdge
81+
* + ElevatorHopVertex
82+
* X OsmElevatorVertex or IntersectionVertex
83+
* == ElevatorBoardEdge and ElevatorAlightEdge
7284
* | ElevatorHopEdge
7385
*/
7486
class ElevatorProcessor {
@@ -128,11 +140,16 @@ public void buildElevatorEdgesFromElevatorNodes() {
128140
.thenComparing(OsmElevatorKey::entityId)
129141
.thenComparing(OsmElevatorKey::osmEntityType)
130142
);
131-
List<Vertex> onboardVertices = new ArrayList<>();
143+
List<ElevatorHopVertex> elevatorHopVertices = new ArrayList<>();
132144
for (OsmElevatorKey key : osmElevatorKeys) {
133145
OsmElevatorVertex sourceVertex = vertices.get(key);
134146
OsmLevel level = verticeLevels.get(key);
135-
createElevatorVertices(onboardVertices, sourceVertex, sourceVertex.getLabelString(), level);
147+
createElevatorVertices(
148+
elevatorHopVertices,
149+
sourceVertex,
150+
sourceVertex.getLabelString(),
151+
level
152+
);
136153
}
137154

138155
var wheelchair = node.explicitWheelchairAccessibility();
@@ -141,7 +158,7 @@ public void buildElevatorEdgesFromElevatorNodes() {
141158
.map(Duration::toSeconds)
142159
.orElse(-1L);
143160
createElevatorHopEdges(
144-
onboardVertices,
161+
elevatorHopVertices,
145162
osmElevatorKeys.stream().map(key -> verticeLevels.get(key)).toList(),
146163
wheelchair,
147164
!node.isBicycleDenied(),
@@ -172,13 +189,13 @@ public void buildElevatorEdgeFromElevatorWay(OsmWay elevatorWay) {
172189
nodeLevels = Collections.nCopies(nodes.size(), OsmLevelFactory.DEFAULT);
173190
}
174191

175-
List<Vertex> onboardVertices = new ArrayList<>();
192+
List<ElevatorHopVertex> elevatorHopVertices = new ArrayList<>();
176193
for (int i = 0; i < nodes.size(); i++) {
177194
Long node = nodes.get(i);
178195
var sourceVertex = vertexGenerator.intersectionNodes().get(node);
179196
OsmLevel level = nodeLevels.get(i);
180197
createElevatorVertices(
181-
onboardVertices,
198+
elevatorHopVertices,
182199
sourceVertex,
183200
elevatorWay.getId() + "_" + i + "_" + sourceVertex.getLabelString(),
184201
level
@@ -191,7 +208,7 @@ public void buildElevatorEdgeFromElevatorWay(OsmWay elevatorWay) {
191208
.map(Duration::toSeconds)
192209
.orElse(-1L);
193210
createElevatorHopEdges(
194-
onboardVertices,
211+
elevatorHopVertices,
195212
nodeLevels,
196213
wheelchair,
197214
!elevatorWay.isBicycleDenied(),
@@ -201,38 +218,38 @@ public void buildElevatorEdgeFromElevatorWay(OsmWay elevatorWay) {
201218
}
202219

203220
private void createElevatorVertices(
204-
List<Vertex> onboardVertices,
221+
List<ElevatorHopVertex> elevatorHopVertices,
205222
IntersectionVertex sourceVertex,
206223
String label,
207224
OsmLevel level
208225
) {
209-
ElevatorHopVertex onboardVertex = vertexFactory.elevator(sourceVertex, label);
226+
ElevatorHopVertex elevatorHopVertex = vertexFactory.elevator(sourceVertex, label);
210227

211-
ElevatorBoardEdge.createElevatorBoardEdge(sourceVertex, onboardVertex);
228+
ElevatorBoardEdge.createElevatorBoardEdge(sourceVertex, elevatorHopVertex);
212229
ElevatorAlightEdge.createElevatorAlightEdge(
213-
onboardVertex,
230+
elevatorHopVertex,
214231
sourceVertex,
215232
// TODO this will be removed in a later PR and moved to the StreetDetailsService
216233
new NonLocalizedString(level.name())
217234
);
218235

219-
// accumulate onboard vertices to so they can be connected by hop edges later
220-
onboardVertices.add(onboardVertex);
236+
// Accumulate ElevatorHopVertices so they can be connected by ElevatorHopEdges later.
237+
elevatorHopVertices.add(elevatorHopVertex);
221238
}
222239

223240
private static void createElevatorHopEdges(
224-
List<Vertex> onboardVertices,
225-
List<OsmLevel> onboardVertexLevels,
241+
List<ElevatorHopVertex> elevatorHopVertices,
242+
List<OsmLevel> elevatorHopVertexLevels,
226243
Accessibility wheelchair,
227244
boolean bicycleAllowed,
228245
int travelTime
229246
) {
230-
// -1 because we loop over onboardVertices two at a time
231-
for (int i = 0, vSize = onboardVertices.size() - 1; i < vSize; i++) {
232-
Vertex from = onboardVertices.get(i);
233-
Vertex to = onboardVertices.get(i + 1);
234-
OsmLevel fromLevel = onboardVertexLevels.get(i);
235-
OsmLevel toLevel = onboardVertexLevels.get(i + 1);
247+
// -1 because we loop over elevatorHopVertices two at a time
248+
for (int i = 0, vSize = elevatorHopVertices.size() - 1; i < vSize; i++) {
249+
Vertex from = elevatorHopVertices.get(i);
250+
Vertex to = elevatorHopVertices.get(i + 1);
251+
OsmLevel fromLevel = elevatorHopVertexLevels.get(i);
252+
OsmLevel toLevel = elevatorHopVertexLevels.get(i + 1);
236253

237254
// default permissions: pedestrian, wheelchair, check tag bicycle=yes
238255
StreetTraversalPermission permission = bicycleAllowed

0 commit comments

Comments
 (0)