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

Fix arrive by filtering for on-street/flex itineraries #6050

Merged

Conversation

leonardehrenfried
Copy link
Member

Summary

It fixes a bug in the OutsideSearchWindowFilter where on street results that were shorter than transit would be removed even though they are often the best results.

cc @daniel-heppner-ibigroup

Issue

Closes #6046

Unit tests

Added.

Documentation

Javadoc.

@leonardehrenfried leonardehrenfried requested a review from a team as a code owner September 6, 2024 13:06
Copy link

codecov bot commented Sep 6, 2024

Codecov Report

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

Project coverage is 69.90%. Comparing base (b174c25) to head (9cb2f4e).
Report is 234 commits behind head on dev-2.x.

Files with missing lines Patch % Lines
...request/preference/ItineraryFilterPreferences.java 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #6050      +/-   ##
=============================================
+ Coverage      69.84%   69.90%   +0.05%     
- Complexity     17463    17698     +235     
=============================================
  Files           1974     1996      +22     
  Lines          74606    75310     +704     
  Branches        7640     7705      +65     
=============================================
+ Hits           52109    52644     +535     
- Misses         19850    19995     +145     
- Partials        2647     2671      +24     

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

@daniel-heppner-ibigroup
Copy link
Contributor

This fixes the issues we were seeing with arriveBy, happy to see both flex direct and other flex+transit results in the same query. I'll take a look at the code now.

@leonardehrenfried leonardehrenfried changed the title Fix arrive by filtering for itineraries on-street/flex itineraries Fix arrive by filtering for on-street/flex itineraries Sep 10, 2024
@leonardehrenfried
Copy link
Member Author

I removed the enum SearchDirection and will take a look at it in another PR.

@leonardehrenfried leonardehrenfried added the IBI Developed by or important for IBI Group label Sep 12, 2024
Comment on lines 46 to 48
// arrive-by transit result are filtered by their departure time and whether they don't depart
// after the end of the computed search window which is dependent on the heuristic's minimum
// transit time.
Copy link
Member

Choose a reason for hiding this comment

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

This is slightly difficult to understand. Maybe use bullets for listing the criteria for filtering. Also, I'm a bit on the edge if this should belong here or on the javadoc for this method as this method doesn't really contain anything else.

Copy link
Member Author

Choose a reason for hiding this comment

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

I converted it to Javadoc and tried to make it more understandable.

@leonardehrenfried leonardehrenfried force-pushed the arrive-by-filtering branch 2 times, most recently from 02e481e to c61bdc5 Compare September 16, 2024 16:30
optionsome
optionsome previously approved these changes Sep 17, 2024
@t2gran
Copy link
Member

t2gran commented Sep 17, 2024

@leonardehrenfried Did you find out if the direct flex is only produced in the first page - the same way as other direct street routes - found by AStar?

I think the OutsideSearchWindowFilter should be even simpler than the implementation you have done. It should skip all Itineraries not produced by Raptor(witch uses the search-window). The AStar does not uses the search-window (as fare as I know), so the filter should not be applied to AStar results. In some cases Raptor computes the search-window, so it is impossible too know before it before Raptor returns.

To fix this we need to know if the search-window was used by the search. The simplest way to do it(I think) is to add flag to the itinerary, f.eks search-window-aware(should only be used by filtering, not exposed outside of OTP), set all raptor results to true and all direct searches to false. If we start using the search-window for FLEX, then we need to harmonize the search-window - I am not sure it is just a check on the latest-depature-time for arriveBy=true for the first page. Consult the paging README to go through all the corner cases - I am unsure if there are more cases to account for.

There is another problem here as well. I took a look at the SortOrderComparator - it uses the Itinerary#isOnStreetAllTheWay() for move all street results first - less likely to get cropped by the PagingFilter. So FLEX are not put first - not isOnStreetAllTheWay(), they are sorted together with regular transit - but they are misse when fetching the next page.

@leonardehrenfried leonardehrenfried force-pushed the arrive-by-filtering branch 3 times, most recently from 0e31b24 to a7bd6bb Compare September 17, 2024 16:02
@t2gran t2gran added this to the 2.7 (next release) milestone Sep 18, 2024
@leonardehrenfried leonardehrenfried force-pushed the arrive-by-filtering branch 4 times, most recently from 67a66f2 to 18eff27 Compare September 19, 2024 07:30
@leonardehrenfried
Copy link
Member Author

leonardehrenfried commented Sep 19, 2024

I did a deep dive on this topic, refreshed my memory on how the paging works and added a few hints in the Javadoc about how the various parts of the paging logic work with each other.

The good news is that the logic change in this PR works well for any direct itinerary that is not flex as they can always be timeshifted to the request time. Also, only the initial page creates a direct search so the other pages are not affected.

For flex we do have a change of behaviour: the direct flex router also looks at the next day (previous for arriveBy) and potentially shows results that start a long time after the search time.

Untitled-2024-09-19-1345

When you mix flex with transit then the time window (although not used by the flex router) acts as a sort of sanity check to give you results not too far into the future. If we go ahead with this approach then more results like these would show up.

Lets talk about it in the dev meeting.

@leonardehrenfried leonardehrenfried force-pushed the arrive-by-filtering branch 2 times, most recently from ff4bf13 to 36193fc Compare September 20, 2024 07:46
leonardehrenfried and others added 2 commits October 10, 2024 15:56
…n/filters/system/FlexSearchWindowFilter.java

Co-authored-by: Thomas Gran <[email protected]>
Add comment

Add comment
@@ -731,6 +732,19 @@ convenient when tuning the itinerary-filter-chain.
moving to the next page.


<h3 id="rd_if_filterDirectFlexByEarliestDeparture">filterDirectFlexByEarliestDeparture</h3>
Copy link
Member

Choose a reason for hiding this comment

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

filterDirectFlexByEarliestDepartureTime ?

Is this still correct?

Comment on lines 44 to 52
if (it.isDirectFlex() && sortOrder.isSortedByDescendingDepartureTime()) {
// arive by
var time = it.startTime().toInstant();
return time.isBefore(earliestDepartureTime);
} else if (it.isDirectFlex() && sortOrder.isSortedByAscendingArrivalTime()) {
// depart at
var time = it.startTime().toInstant();
return time.isAfter(latestArrivalTime);
} else {
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer something like:

if (it.isDirectFlex() {
  return switch(sortOrder) {
  
  }

}

optionsome
optionsome previously approved these changes Oct 11, 2024
…n/filters/system/FlexSearchWindowFilter.java

Co-authored-by: Thomas Gran <[email protected]>
@leonardehrenfried leonardehrenfried merged commit 3d9bee4 into opentripplanner:dev-2.x Oct 11, 2024
5 checks passed
t2gran pushed a commit that referenced this pull request Oct 11, 2024
@leonardehrenfried leonardehrenfried deleted the arrive-by-filtering branch October 11, 2024 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IBI Developed by or important for IBI Group
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Arrive by direct flex result filtered out because it is too short compared to transit
4 participants