-
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.
Add filter just for direct flex itineraries
- Loading branch information
1 parent
b20f947
commit 36193fc
Showing
5 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
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
46 changes: 46 additions & 0 deletions
46
.../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,46 @@ | ||
package org.opentripplanner.routing.algorithm.filterchain.filters.system; | ||
|
||
import java.time.Instant; | ||
import java.util.function.Predicate; | ||
import org.opentripplanner.model.plan.Itinerary; | ||
import org.opentripplanner.routing.algorithm.filterchain.framework.spi.RemoveItineraryFlagger; | ||
|
||
/** | ||
* The flex router doesn't use the transit router's time 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 do it you could get yesterday's or tomorrow's results where you would not expect it. | ||
*/ | ||
public class FlexSearchWindowFilter implements RemoveItineraryFlagger { | ||
|
||
public static final String TAG = "outside-flex-window"; | ||
|
||
private final Instant earliestDepartureTime; | ||
|
||
public FlexSearchWindowFilter(Instant earliestDepartureTime) { | ||
this.earliestDepartureTime = earliestDepartureTime; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return TAG; | ||
} | ||
|
||
@Override | ||
public Predicate<Itinerary> shouldBeFlaggedForRemoval() { | ||
return it -> { | ||
if (it.isFlexAndWalkOnly()) { | ||
var time = it.startTime().toInstant(); | ||
return time.isBefore(earliestDepartureTime); | ||
} 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