Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple states during transfer edge traversals #6238

Conversation

flaktack
Copy link
Contributor

@flaktack flaktack commented Nov 7, 2024

Summary

(This builds on #6237)

In EdgeTraverser when traversing edge lists multiple states could be returned which was not handled correctly.

This updates `EdgeTraverser˙ and its uses to allow multiple states.

Issue

Closes #6210

Unit tests

Unit tests are added for EdgeTraverser. To test the updated transfer and leg traversal a CAR_PICKUP snapshot test is added and then updated.

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 96.77419% with 1 line in your changes missing coverage. Please review.

Project coverage is 69.72%. Comparing base (cd158d2) to head (4d11307).
Report is 98 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...tripplanner/street/search/state/EdgeTraverser.java 94.73% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6238      +/-   ##
=============================================
+ Coverage      69.71%   69.72%   +0.01%     
- Complexity     17692    17700       +8     
=============================================
  Files           2008     2008              
  Lines          75822    75825       +3     
  Branches        7761     7763       +2     
=============================================
+ Hits           52858    52869      +11     
+ Misses         20250    20245       -5     
+ Partials        2714     2711       -3     

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


🚨 Try these New Features:

@t2gran t2gran added this to the 2.7 (next release) milestone Nov 12, 2024
@flaktack flaktack force-pushed the feature/edge-traverser-multiple-states branch from 24c7dc6 to 7ab8e1e Compare November 14, 2024 14:19
@flaktack flaktack marked this pull request as ready for review November 14, 2024 14:28
@flaktack flaktack requested a review from a team as a code owner November 14, 2024 14:28
@leonardehrenfried
Copy link
Member

Can you resolve the conflicts?

@flaktack flaktack force-pushed the feature/edge-traverser-multiple-states branch from 7ab8e1e to 4d11307 Compare November 14, 2024 14:36

State[] states = transferStates.toArray(new State[0]);
var graphPath = new GraphPath<>(states[states.length - 1]);
var legTransferSearchRequest = transferStreetRequest
Copy link
Member

Choose a reason for hiding this comment

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

This one didn't use the EdgeTraverser before. What is the reason for using it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Multiple states may also occur here, which need to be handled in a similar manner:

  • there could be multiple initial states
  • the edge traversal could return multiple states, of which the first one may not be the optimal

As an example, the CAR_PICKUP transfers resulted in an NPE, since the initial CAR/IN_CAR state couldn't traverse the StreetTransitLink entities.

By using EdgeTraverser traversal results in the same state as when creating the actual transfer.

);
}
if (State.isEmpty(afterTraversal)) {
var vertex = isArriveBy ? e.getToVertex() : e.getFromVertex();
Copy link
Member

Choose a reason for hiding this comment

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

Is the reason we need to care about arriveBy is that we now use the SPT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is due to the SPT which stores states by the vertex. Previously we could ignore the from/to vertex handling since the single previous state was used.

Copy link
Member

@optionsome optionsome left a comment

Choose a reason for hiding this comment

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

Do we support CAR_PICKUP in transfers? Idk how often using one would be realistic.

@@ -0,0 +1,71 @@
package org.opentripplanner.routing.algorithm.mapping;

import au.com.origin.snapshots.junit5.SnapshotExtension;
Copy link
Member

Choose a reason for hiding this comment

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

Btw how is this dependency imported into our project?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's an existing dependency:

OpenTripPlanner/pom.xml

Lines 466 to 470 in 5b5d92f

<dependency>
<groupId>io.github.origin-energy</groupId>
<artifactId>java-snapshot-testing-junit5</artifactId>
<version>2.3.0</version>
</dependency>

}

@Test
public void test_trip_planning_with_car_pickup_only() {
Copy link
Member

@optionsome optionsome Nov 19, 2024

Choose a reason for hiding this comment

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

We usually don't use the snake case in tests. I know some people like to use them since they might be slightly more readable. Is there some other reason to use them here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The existing snapshots tests follow the same format, which I built on:

Copy link
Member

Choose a reason for hiding this comment

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

We discussed this in the dev meeting today. Apparently we had made some decision a couple of years ago that snake case is not allowed in tests. But since it's used in snapshot tests, we don't think you should change it in the scope of this pr but if you could create a follow up pr where you rename all the snake case snapshot tests, that would be appreciated.

@flaktack flaktack merged commit a68bc04 into opentripplanner:dev-2.x Nov 22, 2024
5 checks passed
@flaktack flaktack deleted the feature/edge-traverser-multiple-states branch November 22, 2024 09:17
@VillePihlava
Copy link
Contributor

Related to the CAR_PICKUP transfer mode, I think it needs to be discussed more, for example, in next Thursday's dev meeting. I'm currently working on splitting the transfers for modes and I ran into this test. Either more changes need to be made to support this (see RequestModesMapper, QualifiedModeSet, and RaptorPathToItineraryMapper), the CAR or WALK mode can be used instead, or some other solution can be figured out. Also, Feature.TRANSFER should be added in the StreetMode class for CAR_PICKUP.

If this was just added for a test, I think the test can be changed to another mode, for example.

@flaktack
Copy link
Contributor Author

CAR_PICKUP was chosen since it returns multiple states. BIKE_RENTAL could be an alternative if the graph contains static rental stations.

@VillePihlava
Copy link
Contributor

I tried searching for your name in the OTP gitter chat app, but couldn't find you @flaktack. Can you join the OTP room?

Essentially, I think if this mode is used in a test, then it should also be a real-world use case. To fully implement the mode, the changes I listed in the previous comment should be made. Can CAR_PICKUP or BIKE_RENTAL modes actually be used for transfers? In this case, I can take this into account when working on splitting transfers. I'm under the impression that currently only WALK, BIKE, and CAR (recently added by me, more functionality related to this coming later) modes are valid transfer modes.

I'm not that familiar with multiple states in the transfer edge traversals, but I recall that issue #6210 was caused by the use of the BIKE mode in transfers. Maybe this test could use the BIKE mode as long as the data in the test is appropriate?

@leonardehrenfried
Copy link
Member

How about we do the following?

  • @flaktack opens the bike that adds multiple bike states again
  • @flaktack switches the snapshot test in question to bicycle

That way we don't need to have @VillePihlava straining to fix a test for behaviour that we actually don't want to support.

@flaktack
Copy link
Contributor Author

I should have something ready next week using bike with transit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BICYCLE transfer requests cause OTP to shut down with an error
5 participants