org.opentripplanner.transit.raptor.rangeraptor.multicriteria.configure.McRangeRaptorConfig 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.multicriteria.configure;
import java.util.function.BiFunction;
import org.opentripplanner.transit.raptor.api.transit.RaptorTripSchedule;
import org.opentripplanner.transit.raptor.api.view.Heuristics;
import org.opentripplanner.transit.raptor.api.view.Worker;
import org.opentripplanner.transit.raptor.rangeraptor.RoutingStrategy;
import org.opentripplanner.transit.raptor.rangeraptor.WorkerState;
import org.opentripplanner.transit.raptor.rangeraptor.multicriteria.McRangeRaptorWorkerState;
import org.opentripplanner.transit.raptor.rangeraptor.multicriteria.MultiCriteriaRoutingStrategy;
import org.opentripplanner.transit.raptor.rangeraptor.multicriteria.StopArrivals;
import org.opentripplanner.transit.raptor.rangeraptor.multicriteria.heuristic.HeuristicsProvider;
import org.opentripplanner.transit.raptor.rangeraptor.path.DestinationArrivalPaths;
import org.opentripplanner.transit.raptor.rangeraptor.path.configure.PathConfig;
import org.opentripplanner.transit.raptor.rangeraptor.transit.SearchContext;
/**
* Configure and create multicriteria worker, state and child classes.
*
* @param The TripSchedule type defined by the user of the raptor API.
*/
public class McRangeRaptorConfig {
private final SearchContext context;
private final PathConfig pathConfig;
private DestinationArrivalPaths paths;
public McRangeRaptorConfig(SearchContext context) {
this.context = context;
this.pathConfig = new PathConfig<>(context);
}
/**
* Create new multi-criteria worker with optional heuristics.
*/
public Worker createWorker(
Heuristics heuristics,
BiFunction, RoutingStrategy, Worker> createWorker
) {
McRangeRaptorWorkerState state = createState(heuristics);
return createWorker.apply(state, createTransitWorkerStrategy(state));
}
/* private factory methods */
private RoutingStrategy createTransitWorkerStrategy(McRangeRaptorWorkerState state) {
return new MultiCriteriaRoutingStrategy<>(
state,
context.slackProvider(),
context.costCalculator(),
context.debugFactory()
);
}
private McRangeRaptorWorkerState createState(Heuristics heuristics) {
return new McRangeRaptorWorkerState<>(
createStopArrivals(),
createDestinationArrivalPaths(),
createHeuristicsProvider(heuristics),
context.costCalculator(),
context.calculator(),
context.lifeCycle()
);
}
private StopArrivals createStopArrivals() {
return new StopArrivals<>(
context.nStops(),
context.egressPaths(),
createDestinationArrivalPaths(),
context.debugFactory()
);
}
private HeuristicsProvider createHeuristicsProvider(Heuristics heuristics) {
if (heuristics == null) {
return new HeuristicsProvider<>();
} else {
return new HeuristicsProvider<>(
heuristics,
context.roundProvider(),
createDestinationArrivalPaths(),
context.costCalculator(),
context.debugFactory()
);
}
}
private DestinationArrivalPaths createDestinationArrivalPaths() {
if (paths == null) {
paths = pathConfig.createDestArrivalPaths(true);
}
return paths;
}
}