org.opentripplanner.transit.raptor.rangeraptor.path.PathParetoSetComparators Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.transit.raptor.rangeraptor.path;
import org.opentripplanner.transit.raptor.api.path.Path;
import org.opentripplanner.transit.raptor.api.transit.RaptorTripSchedule;
import org.opentripplanner.transit.raptor.util.paretoset.ParetoComparator;
/**
* List of different pareto set comparators. Earlier we created these dynamically,
* but that affect the performance, so it is better to have one function for each
* use case.
*
* All comparators include the "standard" set of criteria:
*
* - Arrival Time
* - Number of transfers
* - Total travel duration time
*
* The {@code travelDuration} is added as a criteria to the pareto comparator in addition to the parameters
* used for each stop arrivals. The {@code travelDuration} is only needed at the destination because Range Raptor
* works in iterations backwards in time.
*/
public class PathParetoSetComparators {
/** Prevent this utility class from instantiation. */
private PathParetoSetComparators() { }
public static ParetoComparator> comparatorStandard() {
return (l, r) ->
l.endTime() < r.endTime() ||
l.numberOfTransfers() < r.numberOfTransfers() ||
l.travelDurationInSeconds() < r.travelDurationInSeconds();
}
public static ParetoComparator> comparatorWithTimetable() {
return (l, r) ->
l.rangeRaptorIterationDepartureTime() > r.rangeRaptorIterationDepartureTime() ||
l.endTime() < r.endTime() ||
l.numberOfTransfers() < r.numberOfTransfers() ||
l.travelDurationInSeconds() < r.travelDurationInSeconds();
}
public static ParetoComparator> comparatorWithTimetableAndCost() {
return (l, r) ->
l.rangeRaptorIterationDepartureTime() > r.rangeRaptorIterationDepartureTime() ||
l.endTime() < r.endTime() ||
l.numberOfTransfers() < r.numberOfTransfers() ||
l.travelDurationInSeconds() < r.travelDurationInSeconds() ||
l.cost() < r.cost();
}
public static ParetoComparator> comparatorWithTimetableAndRelaxedCost(
double relaxCostAtDestinationArrival
) {
return (l, r) ->
l.rangeRaptorIterationDepartureTime() > r.rangeRaptorIterationDepartureTime() ||
l.endTime() < r.endTime() ||
l.numberOfTransfers() < r.numberOfTransfers() ||
l.travelDurationInSeconds() < r.travelDurationInSeconds() ||
l.cost() < Math.round(r.cost() * relaxCostAtDestinationArrival);
}
public static ParetoComparator> comparatorWithCost() {
return (l, r) ->
l.endTime() < r.endTime() ||
l.numberOfTransfers() < r.numberOfTransfers() ||
l.travelDurationInSeconds() < r.travelDurationInSeconds() ||
l.cost() < r.cost();
}
public static ParetoComparator> comparatorWithRelaxedCost(
double relaxCostAtDestinationArrival
) {
return (l, r) ->
l.endTime() < r.endTime() ||
l.numberOfTransfers() < r.numberOfTransfers() ||
l.travelDurationInSeconds() < r.travelDurationInSeconds() ||
l.cost() < Math.round(r.cost() * relaxCostAtDestinationArrival);
}
}