-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6050 from ibi-group/arrive-by-filtering
Fix arrive by filtering for on-street/flex itineraries
- Loading branch information
Showing
25 changed files
with
653 additions
and
256 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
.../opentripplanner/routing/algorithm/filterchain/filters/system/FlexSearchWindowFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.opentripplanner.routing.algorithm.filterchain.filters.system; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.function.Predicate; | ||
import org.opentripplanner.model.plan.Itinerary; | ||
import org.opentripplanner.model.plan.SortOrder; | ||
import org.opentripplanner.routing.algorithm.filterchain.framework.spi.RemoveItineraryFlagger; | ||
|
||
/** | ||
* The flex router doesn't use the transit router's search-window, but nevertheless using it | ||
* for filtering is useful when combining flex with transit. | ||
* <p> | ||
* The flex router also searches the previous day (arrive by) or the next one (depart after). | ||
* If you didn't filter the flex results by something you could get yesterday's or tomorrow's | ||
* trips where you would not expect it. | ||
*/ | ||
public class FlexSearchWindowFilter implements RemoveItineraryFlagger { | ||
|
||
public static final String TAG = "flex-outside-search-window"; | ||
|
||
private final Instant earliestDepartureTime; | ||
private final Instant latestArrivalTime; | ||
private final SortOrder sortOrder; | ||
|
||
public FlexSearchWindowFilter( | ||
Instant earliestDepartureTime, | ||
Duration searchWindow, | ||
SortOrder sortOrder | ||
) { | ||
this.earliestDepartureTime = earliestDepartureTime; | ||
this.latestArrivalTime = earliestDepartureTime.plus(searchWindow); | ||
this.sortOrder = sortOrder; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return TAG; | ||
} | ||
|
||
@Override | ||
public Predicate<Itinerary> shouldBeFlaggedForRemoval() { | ||
return it -> { | ||
if (it.isDirectFlex()) { | ||
return switch (sortOrder) { | ||
case STREET_AND_DEPARTURE_TIME -> { | ||
var time = it.startTime().toInstant(); | ||
yield time.isBefore(earliestDepartureTime); | ||
} | ||
case STREET_AND_ARRIVAL_TIME -> { | ||
var time = it.startTime().toInstant(); | ||
yield time.isAfter(latestArrivalTime); | ||
} | ||
}; | ||
} else { | ||
return false; | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public boolean skipAlreadyFlaggedItineraries() { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.