Skip to content

Commit 34f4bf6

Browse files
authored
Merge pull request opentripplanner#6495 from HSLdevcom/optimize-area-linking
Optimize routing time vertex linking with areas
2 parents 9c216c4 + 9ee7de6 commit 34f4bf6

File tree

15 files changed

+494
-239
lines changed

15 files changed

+494
-239
lines changed

application/src/main/java/org/opentripplanner/graph_builder/module/StreetLinkerModule.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,31 @@ public class StreetLinkerModule implements GraphBuilderModule {
5252
private final VehicleParkingRepository parkingRepository;
5353
private final TimetableRepository timetableRepository;
5454
private final DataImportIssueStore issueStore;
55-
private final Boolean addExtraEdgesToAreas;
55+
private final boolean areaVisibility;
56+
private final int maxAreaNodes;
5657

5758
public StreetLinkerModule(
5859
Graph graph,
5960
VehicleParkingRepository parkingRepository,
6061
TimetableRepository timetableRepository,
6162
DataImportIssueStore issueStore,
62-
boolean addExtraEdgesToAreas
63+
boolean areaVisibility,
64+
int maxAreaNodes
6365
) {
6466
this.graph = graph;
6567
this.parkingRepository = parkingRepository;
6668
this.timetableRepository = timetableRepository;
6769
this.issueStore = issueStore;
68-
this.addExtraEdgesToAreas = addExtraEdgesToAreas;
70+
this.areaVisibility = areaVisibility;
71+
this.maxAreaNodes = maxAreaNodes;
6972
}
7073

7174
@Override
7275
public void buildGraph() {
7376
timetableRepository.index();
7477
graph.index(timetableRepository.getSiteRepository());
75-
graph.getLinker().setAddExtraEdgesToAreas(this.addExtraEdgesToAreas);
78+
graph.getLinker().setAreaVisibility(this.areaVisibility);
79+
graph.getLinker().setMaxAreaNodes(this.maxAreaNodes);
7680

7781
if (graph.hasStreets) {
7882
linkTransitStops(graph, timetableRepository);

application/src/main/java/org/opentripplanner/graph_builder/module/configure/GraphBuilderModules.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ static StreetLinkerModule provideStreetLinkerModule(
175175
parkingRepository,
176176
timetableRepository,
177177
issueStore,
178-
config.areaVisibility
178+
config.areaVisibility,
179+
config.maxAreaNodes
179180
);
180181
}
181182

@@ -197,7 +198,8 @@ static PruneIslands providePruneIslands(
197198
parkingRepository,
198199
timetableRepository,
199200
issueStore,
200-
config.areaVisibility
201+
config.areaVisibility,
202+
config.maxAreaNodes
201203
)
202204
);
203205
pruneIslands.setPruningThresholdIslandWithoutStops(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public void buildGraph() {
132132
build();
133133
graph.hasStreets = true;
134134
streetLimitationParameters.initMaxCarSpeed(getMaxCarSpeed());
135+
streetLimitationParameters.initMaxAreaNodes(params.maxAreaNodes());
135136
}
136137

137138
@Override

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.opentripplanner.routing.graph.Graph;
1111
import org.opentripplanner.service.osminfo.OsmInfoGraphBuildRepository;
1212
import org.opentripplanner.service.vehicleparking.VehicleParkingRepository;
13+
import org.opentripplanner.street.model.StreetConstants;
1314
import org.opentripplanner.street.model.StreetLimitationParameters;
1415

1516
/**
@@ -29,7 +30,7 @@ public class OsmModuleBuilder {
2930
private boolean staticParkAndRide = false;
3031
private boolean staticBikeParkAndRide = false;
3132
private boolean includeOsmSubwayEntrances = false;
32-
private int maxAreaNodes;
33+
private int maxAreaNodes = StreetConstants.DEFAULT_MAX_AREA_NODES;
3334
private StreetLimitationParameters streetLimitationParameters = new StreetLimitationParameters();
3435

3536
OsmModuleBuilder(

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ public void buildWithVisibility(OsmAreaGroup group) {
167167
// Edges which are part of the rings
168168
Set<Edge> ringEdges = new HashSet<>();
169169

170+
HashMap<AreaGroup, HashSet<IntersectionVertex>> visibilityVertexCandidates = new HashMap<>();
171+
170172
// OSM ways that this area group consists of
171173
Set<Long> osmWayIds = group.areas
172174
.stream()
@@ -189,7 +191,6 @@ public void buildWithVisibility(OsmAreaGroup group) {
189191
HashSet<IntersectionVertex> platformLinkingVertices = new HashSet<>();
190192
HashSet<IntersectionVertex> visibilityVertices = new HashSet<>();
191193
GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
192-
193194
OsmEntity areaEntity = group.getSomeOsmObject();
194195

195196
for (OsmArea area : group.areas) {
@@ -293,13 +294,11 @@ public void buildWithVisibility(OsmAreaGroup group) {
293294
}
294295
continue;
295296
}
296-
297-
areaGroup.addVisibilityVertices(visibilityVertices);
298-
createAreas(areaGroup, ring, group.areas);
299-
300297
if (visibilityVertices.size() > maxAreaNodes) {
301298
issueStore.add(new AreaTooComplicated(group, visibilityVertices.size(), maxAreaNodes));
302299
}
300+
visibilityVertexCandidates.put(areaGroup, visibilityVertices);
301+
createAreas(areaGroup, ring, group.areas);
303302

304303
// if area is too complex, consider only part of visibility nodes
305304
// so that at least some edges passing through the area are added
@@ -343,6 +342,21 @@ public void buildWithVisibility(OsmAreaGroup group) {
343342
}
344343
}
345344
pruneAreaEdges(startingVertices, edges, ringEdges);
345+
346+
visibilityVertexCandidates.forEach((areaGroup, vertices) -> {
347+
if (vertices.size() > maxAreaNodes) {
348+
// keep nodes which have most connections
349+
areaGroup.addVisibilityVertices(
350+
vertices
351+
.stream()
352+
.sorted((v1, v2) -> Long.compare((v2.getDegreeOut()), v1.getDegreeOut()))
353+
.limit(maxAreaNodes)
354+
.collect(Collectors.toSet())
355+
);
356+
} else {
357+
areaGroup.addVisibilityVertices(vertices);
358+
}
359+
});
346360
}
347361

348362
/**

0 commit comments

Comments
 (0)