-
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 #5222 from HSLdevcom/removetransitifstreetonlyisbe…
…tterfilter-costfunc Remove transit with higher cost than best on-street itinerary filter
- Loading branch information
Showing
14 changed files
with
430 additions
and
153 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
53 changes: 53 additions & 0 deletions
53
...r/routing/algorithm/filterchain/deletionflagger/RemoveTransitIfWalkingIsBetterFilter.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,53 @@ | ||
package org.opentripplanner.routing.algorithm.filterchain.deletionflagger; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.OptionalDouble; | ||
import java.util.OptionalInt; | ||
import java.util.stream.Collectors; | ||
import org.opentripplanner.framework.model.Cost; | ||
import org.opentripplanner.model.plan.Itinerary; | ||
import org.opentripplanner.model.plan.Leg; | ||
import org.opentripplanner.routing.api.request.framework.CostLinearFunction; | ||
|
||
/** | ||
* Filter itineraries which have a higher generalized-cost than a pure walk itinerary. | ||
*/ | ||
public class RemoveTransitIfWalkingIsBetterFilter implements ItineraryDeletionFlagger { | ||
|
||
/** | ||
* Required for {@link org.opentripplanner.routing.algorithm.filterchain.ItineraryListFilterChain}, | ||
* to know which filters removed | ||
*/ | ||
public static final String TAG = "transit-vs-walk-filter"; | ||
|
||
@Override | ||
public String name() { | ||
return TAG; | ||
} | ||
|
||
@Override | ||
public List<Itinerary> flagForRemoval(List<Itinerary> itineraries) { | ||
OptionalInt minWalkCost = itineraries | ||
.stream() | ||
.filter(Itinerary::isWalkingAllTheWay) | ||
.mapToInt(Itinerary::getGeneralizedCost) | ||
.min(); | ||
|
||
if (minWalkCost.isEmpty()) { | ||
return List.of(); | ||
} | ||
|
||
var limit = minWalkCost.getAsInt(); | ||
|
||
return itineraries | ||
.stream() | ||
.filter(it -> !it.isOnStreetAllTheWay() && it.getGeneralizedCost() >= limit) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@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
Oops, something went wrong.