Skip to content

Commit

Permalink
Merge pull request opentripplanner#5591 from HSLdevcom/DT-6123
Browse files Browse the repository at this point in the history
Consider escalator edges in island pruning
  • Loading branch information
vesameskanen authored Jan 5, 2024
2 parents 7fb9773 + bb19842 commit d71c768
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
import org.opentripplanner.street.model.edge.AreaEdge;
import org.opentripplanner.street.model.edge.AreaEdgeList;
import org.opentripplanner.street.model.edge.Edge;
import org.opentripplanner.street.model.edge.ElevatorEdge;
import org.opentripplanner.street.model.edge.FreeEdge;
import org.opentripplanner.street.model.edge.StreetEdge;
import org.opentripplanner.street.model.edge.StreetTransitEntityLink;
import org.opentripplanner.street.model.vertex.StreetVertex;
import org.opentripplanner.street.model.vertex.TransitStopVertex;
import org.opentripplanner.street.model.vertex.Vertex;
Expand Down Expand Up @@ -338,16 +335,6 @@ private void collectNeighbourVertices(
}
State s0 = new State(gv, request);
for (Edge e : gv.getOutgoing()) {
if (
!(
e instanceof StreetEdge ||
e instanceof ElevatorEdge ||
e instanceof FreeEdge ||
e instanceof StreetTransitEntityLink
)
) {
continue;
}
if (
e instanceof StreetEdge &&
shouldMatchNoThruType != ((StreetEdge) e).isNoThruTraffic(traverseMode)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
package org.opentripplanner.graph_builder.module.islandpruning;

import java.io.File;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opentripplanner.graph_builder.module.islandpruning.IslandPruningUtils.buildOsmGraph;

import java.util.stream.Collectors;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.graph_builder.module.osm.OsmModule;
import org.opentripplanner.openstreetmap.OsmProvider;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.test.support.ResourceLoader;
import org.opentripplanner.transit.model.framework.Deduplicator;
import org.opentripplanner.transit.service.StopModel;
import org.opentripplanner.transit.service.TransitModel;

/* Test data consists of one bigger graph and two small sub graphs. These are totally disconnected.
One small graphs is only at 5 meter distance from the big graph and another one 30 m away.
Adaptive pruning retains the distant island but removes the closer one which appears to be
disconnected part of the main graph.
/**
* Test data consists of one bigger graph and two small sub graphs. These are totally disconnected.
* One small graphs is only at 5 meter distance from the big graph and another one 30 m away.
* Adaptive pruning retains the distant island but removes the closer one which appears to be
* disconnected part of the main graph.
*/

public class AdaptivePruningTest {

private static Graph graph;

@BeforeAll
static void setup() {
graph = buildOsmGraph(ResourceLoader.of(AdaptivePruningTest.class).file("isoiiluoto.pbf"));
graph =
buildOsmGraph(
ResourceLoader.of(AdaptivePruningTest.class).file("isoiiluoto.pbf"),
5,
0,
20,
30
);
}

@Test
public void distantIslandIsRetained() {
Assertions.assertTrue(
assertTrue(
graph
.getStreetEdges()
.stream()
Expand All @@ -55,7 +58,7 @@ public void nearIslandIsRemoved() {

@Test
public void mainGraphIsNotRemoved() {
Assertions.assertTrue(
assertTrue(
graph
.getStreetEdges()
.stream()
Expand All @@ -64,42 +67,4 @@ public void mainGraphIsNotRemoved() {
.contains("73347312")
);
}

private static Graph buildOsmGraph(File file) {
try {
var deduplicator = new Deduplicator();
var graph = new Graph(deduplicator);
var transitModel = new TransitModel(new StopModel(), deduplicator);
// Add street data from OSM
OsmProvider osmProvider = new OsmProvider(file, true);
OsmModule osmModule = OsmModule.of(osmProvider, graph).withEdgeNamer(new TestNamer()).build();

osmModule.buildGraph();

transitModel.index();
graph.index(transitModel.getStopModel());

// Prune floating islands and set noThru where necessary
PruneIslands pruneIslands = new PruneIslands(
graph,
transitModel,
DataImportIssueStore.NOOP,
null
);
// all 3 sub graphs are larger than 5 edges
pruneIslands.setPruningThresholdIslandWithoutStops(5);

// up to 5*20 = 100 edge graphs get pruned if they are too close
pruneIslands.setAdaptivePruningFactor(20);

// Distant island is 30 m away from main graph, let's keep it
pruneIslands.setAdaptivePruningDistance(30);

pruneIslands.buildGraph();

return graph;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.opentripplanner.graph_builder.module.islandpruning;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opentripplanner.graph_builder.module.islandpruning.IslandPruningUtils.buildOsmGraph;

import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.opentripplanner.test.support.ResourceLoader;

public class EscalatorPruningTest {

@Test
public void streetEdgesBetweenEscalatorEdgesRetained() {
var graph = buildOsmGraph(
ResourceLoader.of(EscalatorPruningTest.class).file("matinkyla-escalator.pbf"),
10,
2,
50,
250
);
assertTrue(
graph
.getStreetEdges()
.stream()
.map(streetEdge -> streetEdge.getName().toString())
.collect(Collectors.toSet())
.contains("490072445")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.opentripplanner.graph_builder.module.islandpruning;

import java.io.File;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.graph_builder.module.osm.OsmModule;
import org.opentripplanner.openstreetmap.OsmProvider;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.transit.model.framework.Deduplicator;
import org.opentripplanner.transit.service.StopModel;
import org.opentripplanner.transit.service.TransitModel;

class IslandPruningUtils {

static Graph buildOsmGraph(
File osmFile,
int thresholdIslandWithoutStops,
int thresholdIslandWithStops,
double adaptivePruningFactor,
int adaptivePruningDistance
) {
try {
var deduplicator = new Deduplicator();
var graph = new Graph(deduplicator);
var transitModel = new TransitModel(new StopModel(), deduplicator);
// Add street data from OSM
OsmProvider osmProvider = new OsmProvider(osmFile, true);
OsmModule osmModule = OsmModule.of(osmProvider, graph).withEdgeNamer(new TestNamer()).build();

osmModule.buildGraph();

transitModel.index();
graph.index(transitModel.getStopModel());

// Prune floating islands and set noThru where necessary
PruneIslands pruneIslands = new PruneIslands(
graph,
transitModel,
DataImportIssueStore.NOOP,
null
);
pruneIslands.setPruningThresholdIslandWithoutStops(thresholdIslandWithoutStops);
pruneIslands.setPruningThresholdIslandWithStops(thresholdIslandWithStops);
pruneIslands.setAdaptivePruningFactor(adaptivePruningFactor);
pruneIslands.setAdaptivePruningDistance(adaptivePruningDistance);
pruneIslands.buildGraph();

return graph;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package org.opentripplanner.graph_builder.module.islandpruning;

import java.io.File;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opentripplanner.graph_builder.module.islandpruning.IslandPruningUtils.buildOsmGraph;

import java.util.Set;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.graph_builder.module.osm.OsmModule;
import org.opentripplanner.openstreetmap.OsmProvider;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.street.model.edge.StreetEdge;
import org.opentripplanner.test.support.ResourceLoader;
import org.opentripplanner.transit.model.framework.Deduplicator;
import org.opentripplanner.transit.service.StopModel;
import org.opentripplanner.transit.service.TransitModel;

public class PruneNoThruIslandsTest {

Expand All @@ -26,13 +22,17 @@ static void setup() {
buildOsmGraph(
ResourceLoader
.of(PruneNoThruIslandsTest.class)
.file("herrenberg-island-prune-nothru.osm.pbf")
.file("herrenberg-island-prune-nothru.osm.pbf"),
10,
2,
50,
250
);
}

@Test
public void bicycleIslandsBecomeNoThru() {
Assertions.assertTrue(
assertTrue(
graph
.getStreetEdges()
.stream()
Expand All @@ -45,7 +45,7 @@ public void bicycleIslandsBecomeNoThru() {

@Test
public void carIslandsBecomeNoThru() {
Assertions.assertTrue(
assertTrue(
graph
.getStreetEdges()
.stream()
Expand All @@ -67,36 +67,4 @@ public void pruneFloatingBikeAndWalkIsland() {
.contains("159830257")
);
}

private static Graph buildOsmGraph(File osmFile) {
try {
var deduplicator = new Deduplicator();
var graph = new Graph(deduplicator);
var transitModel = new TransitModel(new StopModel(), deduplicator);
// Add street data from OSM
OsmProvider osmProvider = new OsmProvider(osmFile, true);
OsmModule osmModule = OsmModule.of(osmProvider, graph).withEdgeNamer(new TestNamer()).build();

osmModule.buildGraph();

transitModel.index();
graph.index(transitModel.getStopModel());

// Prune floating islands and set noThru where necessary
PruneIslands pruneIslands = new PruneIslands(
graph,
transitModel,
DataImportIssueStore.NOOP,
null
);
pruneIslands.setPruningThresholdIslandWithoutStops(40);
pruneIslands.setPruningThresholdIslandWithStops(5);
pruneIslands.setAdaptivePruningFactor(1);
pruneIslands.buildGraph();

return graph;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Binary file not shown.

0 comments on commit d71c768

Please sign in to comment.