Skip to content

Consider escalator edges in island pruning#5591

Merged
vesameskanen merged 9 commits into
opentripplanner:dev-2.xfrom
HSLdevcom:DT-6123
Jan 5, 2024
Merged

Consider escalator edges in island pruning#5591
vesameskanen merged 9 commits into
opentripplanner:dev-2.xfrom
HSLdevcom:DT-6123

Conversation

@nurmAV

@nurmAV nurmAV commented Dec 21, 2023

Copy link
Copy Markdown
Contributor

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.

@nurmAV nurmAV requested a review from a team as a code owner December 21, 2023 11:11
@codecov

codecov Bot commented Dec 21, 2023

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c766bde) 67.46% compared to head (bb19842) 67.46%.
Report is 41 commits behind head on dev-2.x.

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.
📢 Have feedback on the report? Share it here.

@leonardehrenfried

Copy link
Copy Markdown
Member

I'm afraid I'm going to have to ask you to write a test for this. You could:

  • construct a graph manually (preferred but a bit complicated. i'm happy to help)
  • extract a tiny piece of OSM data like this and write a test with it. @vesameskanen can help you with this.


@Test
public void streetEdgesBetweenEscalatorEdgesRetained() {
Assertions.assertTrue(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a static import for that.

Comment on lines +40 to +70
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);
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is a direct copy of PruneNoIslandsTest. Please extract a reusable method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a package-private class and put the static method there.


@BeforeAll
static void setup() {
graph =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's only one test, you don't need the global setup method. Just build the graph in the test itself.

@leonardehrenfried leonardehrenfried added the !Bug Apply to issues describing a bug and PRs witch fixes it. label Dec 22, 2023
@vesameskanen

Copy link
Copy Markdown
Contributor

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"))
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contains("490072445")

don't use a set of single member

Comment on lines +344 to +348
e instanceof StreetEdge ||
e instanceof ElevatorEdge ||
e instanceof FreeEdge ||
e instanceof StreetTransitEntityLink
e instanceof StreetTransitEntityLink ||
e instanceof EscalatorEdge

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vesameskanen vesameskanen Jan 4, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@t2gran t2gran added this to the 2.5 (next release) milestone Jan 4, 2024
@vesameskanen vesameskanen self-requested a review January 4, 2024 18:18
vesameskanen
vesameskanen previously approved these changes Jan 4, 2024
@leonardehrenfried

Copy link
Copy Markdown
Member

If you apply these cosmetic changes to the PR, I'm happy to approve: leonardehrenfried@a8086b1

vesameskanen
vesameskanen previously approved these changes Jan 5, 2024

@vesameskanen vesameskanen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the cleanup, Leonard!

@vesameskanen vesameskanen merged commit d71c768 into opentripplanner:dev-2.x Jan 5, 2024
@vesameskanen vesameskanen deleted the DT-6123 branch January 5, 2024 07:02
t2gran pushed a commit that referenced this pull request Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!Bug Apply to issues describing a bug and PRs witch fixes it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants