Skip to content

Improve linking of fixed stops used by flex trips - #5503

Merged
leonardehrenfried merged 10 commits into
opentripplanner:dev-2.xfrom
leonardehrenfried:flex-linking
Nov 16, 2023
Merged

leonardehrenfried merged 10 commits into
opentripplanner:dev-2.xfrom
leonardehrenfried:flex-linking

Conversation

@leonardehrenfried

Copy link
Copy Markdown
Member

Summary

As shown in #5498 adding stops which are far away from walkable edges to flex trips can lead to catastrophic results.

This PR improves the situation as follows:

  • flex stops are first linked to walkable edges
  • if these edges are not drivable then a second link to drivable edges is created

This leads to desirable results like these

image

Further work

There is a slight problem though: the extra link for the flex trip is also accessible for pedestrians.

image

We can improve this by making the links mode specific. I suggest that we improve this problem in this PR and follow up later.

Issue

Closes #5498

Unit tests

Some added plus a bit of refactoring of the existing tests.

Documentation

Javadoc.

@leonardehrenfried
leonardehrenfried requested a review from a team as a code owner November 13, 2023 12:34
@leonardehrenfried leonardehrenfried added the !Bug Apply to issues describing a bug and PRs witch fixes it. label Nov 13, 2023
@codecov

codecov Bot commented Nov 13, 2023 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (112e9ad) 66.85% compared to head (e6a1cd0) 66.92%.
Report is 49 commits behind head on dev-2.x.

Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #5503      +/-   ##
=============================================
+ Coverage      66.85%   66.92%   +0.07%     
- Complexity     15655    15697      +42     
=============================================
  Files           1817     1818       +1     
  Lines          70160    70244      +84     
  Branches        7383     7392       +9     
=============================================
+ Hits           46904    47013     +109     
+ Misses         20798    20776      -22     
+ Partials        2458     2455       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

vesameskanen
vesameskanen previously approved these changes Nov 14, 2023
@leonardehrenfried
leonardehrenfried requested review from vpaturet and removed request for t2gran November 14, 2023 10:11
@t2gran

t2gran commented Nov 14, 2023 •

Copy link
Copy Markdown
Member

I discussed this a bit with @andtry today. I think we should restrict the NeTEx fixedStopAreaWide stops to one mode. We can do this in the nordic profile because the FlexStopPlace (with multiple areas) has one required mode. In the nordic profile the areas has a many-to-one relationship with FlexStopPlace. Hence, an are can only serve on mode.

We might have to change this in the future, but until then this restriction will make the OTP code a bit less vulnerable.

We (Entur) will try to make a PR for this.

Doc: fixedStopAreaWide


public TransitStopVertex findTransitStopVertices(FeedScopedId stopId) {
@Nullable
public TransitStopVertex getTransitStopVertex(FeedScopedId stopId) {

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.

FYI: According to the naming conventions this does not follow either get or find. Changing this to throw an exception is the "right" thing to do, but I am not sure if we can do it - we might have stops outside the area covered by OSM data - and throwing exception should only be done in cases where we expect it to not happen. I would not have changed the name here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reverted in d91d7c1 but the name findTransitStopVertices is obviously wrong.

if (
linkType == StopLinkType.WALK_AND_CAR && !walkStreetVertex.isConnectedToDriveableEdge()
) {
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.

Consider adding the edges returned here, not adding them inside the function (line 167).

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.

If you do this line 163-169 collapses as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure I follow you. linkVertexPermanently returns void. (That is indeed a bit strange and we don't really need to return anything here, but I'm just following the idiom.) I can explain a bit in a dev meeting,

return linkEdges;
}
);
}

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.

The above function call has a large code-block as one of the arguments - from a clean code perspective this is not the "same level of abstraction". I would make a few private functions and inject those. You have some inline doc here as well witch then could be moved to be JavaDoc.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've reworked it a bit in the latest commit.

@t2gran

t2gran commented Nov 14, 2023

Copy link
Copy Markdown
Member

Thank you for fixing this @leonardehrenfried, I only had a quick look at the core changes - @vpaturet will do the final review from us. Except for the small stuff I pointed out everything looks ok with me, but I will leave the approval to @vpaturet.

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

Tested on Norwegian data, the issue is fixed, no side-effects observed.

@leonardehrenfried
leonardehrenfried merged commit 61fbcd3 into opentripplanner:dev-2.x Nov 16, 2023
t2gran pushed a commit that referenced this pull request Nov 16, 2023
@leonardehrenfried
leonardehrenfried deleted the flex-linking branch November 16, 2023 09:40
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.

Kongsberg linking going wild

4 participants