Consider escalator edges in island pruning#5591
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev-2.x #5591 +/- ##
=============================================
- Coverage 67.46% 67.46% -0.01%
+ Complexity 16194 16191 -3
=============================================
Files 1858 1862 +4
Lines 71130 71184 +54
Branches 7408 7401 -7
=============================================
+ Hits 47986 48021 +35
- Misses 20669 20673 +4
- Partials 2475 2490 +15 ☔ View full report in Codecov by Sentry. |
|
I'm afraid I'm going to have to ask you to write a test for this. You could:
|
|
|
||
| @Test | ||
| public void streetEdgesBetweenEscalatorEdgesRetained() { | ||
| Assertions.assertTrue( |
There was a problem hiding this comment.
Please use a static import for that.
| 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); | ||
| } | ||
| } |
There was a problem hiding this comment.
This method is a direct copy of PruneNoIslandsTest. Please extract a reusable method.
There was a problem hiding this comment.
Just to clarify, where should the extracted method be placed? Since it would be used in some other test files as well, it would seem a bit weird to import it as a static from this class as that would imply this special test has some general functionality that other tests need
There was a problem hiding this comment.
Make a package-private class and put the static method there.
|
|
||
| @BeforeAll | ||
| static void setup() { | ||
| graph = |
There was a problem hiding this comment.
Since it's only one test, you don't need the global setup method. Just build the graph in the test itself.
|
Please use the new graph build method for adaptive pruning test as well. Just pass pruning params to graph builder. |
| .map(streetEdge -> streetEdge.getName().toString()) | ||
| .collect(Collectors.toSet()) | ||
| .containsAll(Set.of("490072445")) | ||
| ); |
There was a problem hiding this comment.
contains("490072445")
don't use a set of single member
| e instanceof StreetEdge || | ||
| e instanceof ElevatorEdge || | ||
| e instanceof FreeEdge || | ||
| e instanceof StreetTransitEntityLink | ||
| e instanceof StreetTransitEntityLink || | ||
| e instanceof EscalatorEdge |
There was a problem hiding this comment.
@vesameskanen Would it be a good idea to convert these instanceOf checks into a method on Edge instead?
(I'm not going to expect @nurmAV to do it in this PR.)
There was a problem hiding this comment.
I am quite sure that there is a need for refactoring. Use of instanceof indicates that something has gone wrong in first place. Adding a proper method sounds like a correct fix.
However, I am not 100% sure if there is a need for considering only certain type of edges at all. Maybe pruning works fine in 99.99% of cases even if all edges are considered.
I will test this - it is easy to check the pruning stats and see if selective edge traversal is necessary.
There was a problem hiding this comment.
I found out that helsinki area pruning works exactly the same way, when all edges are considered. I suggest removing edge class test.
I am sorry that this comment comes this late. Somehow the new test now appears redundant. Test refactoring is useful, though.
There was a problem hiding this comment.
Good investigation. I think this code may have been from a time when we had transit edges (TransitHopEdge) in the graph and you would probably never want to prune them.
|
If you apply these cosmetic changes to the PR, I'm happy to approve: leonardehrenfried@a8086b1 |
vesameskanen
left a comment
There was a problem hiding this comment.
Thank you for the cleanup, Leonard!
Summary
This PR adds consideration of escalator edges in island pruning. Previously, street edges that were only connected to escalator edges were pruned out.
Issue
When escalator edges were added in a previous PR, they were not considered in island pruning, leading to some their neighbouring street edges being pruned out.
Unit tests
The change was tested manually by checking the street network in OTP debug UI.