Skip to content

Commit

Permalink
Add RaptorRouter interface for to allow top level instrumentation
Browse files Browse the repository at this point in the history
This also includes a little naming cleanup.
  • Loading branch information
t2gran committed Sep 23, 2024
1 parent ff643d1 commit 68e8867
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/opentripplanner/raptor/RaptorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ private RaptorResponse<T> routeUsingStdWorker(
RaptorTransitDataProvider<T> transitData,
RaptorRequest<T> request
) {
var worker = config.createStdWorker(transitData, request);
var result = worker.route();
var rangeRaptorRouter = config.createRangeRaptorWithStdWorker(transitData, request);
var result = rangeRaptorRouter.route();
var arrivals = new DefaultStopArrivals(result);
return new RaptorResponse<>(result.extractPaths(), arrivals, request, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.opentripplanner.raptor.rangeraptor.internalapi.Heuristics;
import org.opentripplanner.raptor.rangeraptor.internalapi.PassThroughPointsService;
import org.opentripplanner.raptor.rangeraptor.internalapi.RangeRaptorWorker;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorRouterResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerState;
import org.opentripplanner.raptor.rangeraptor.internalapi.RoutingStrategy;
import org.opentripplanner.raptor.rangeraptor.multicriteria.McStopArrivals;
Expand Down Expand Up @@ -58,7 +58,7 @@ public SearchContext<T> context(RaptorTransitDataProvider<T> transit, RaptorRequ
return SearchContext.of(request, tuningParameters, transit, acceptC2AtDestination).build();
}

public RangeRaptor<T> createStdWorker(
public RangeRaptor<T> createRangeRaptorWithStdWorker(
RaptorTransitDataProvider<T> transitData,
RaptorRequest<T> request
) {
Expand All @@ -70,7 +70,7 @@ public RangeRaptor<T> createStdWorker(
);
}

public RangeRaptor<T> createMcWorker(
public RangeRaptor<T> createRangeRaptorWithMcWorker(
RaptorTransitDataProvider<T> transitData,
RaptorRequest<T> request,
Heuristics heuristics
Expand All @@ -97,17 +97,17 @@ public RangeRaptor<T> createMcWorker(
return createRangeRaptor(context, worker);
}

public RangeRaptor<T> createHeuristicSearch(
public RangeRaptor<T> createRangeRaptorWithHeuristicSearch(
RaptorTransitDataProvider<T> transitData,
RaptorRequest<T> request
) {
return createStdWorker(transitData, request);
return createRangeRaptorWithStdWorker(transitData, request);
}

public Heuristics createHeuristic(
RaptorTransitDataProvider<T> transitData,
RaptorRequest<T> request,
RaptorWorkerResult<T> results
RaptorRouterResult<T> results
) {
var context = context(transitData, request);
return new StdRangeRaptorConfig<>(context).createHeuristics(results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.opentripplanner.raptor.api.model.RaptorConstants;
import org.opentripplanner.raptor.api.model.RaptorTripSchedule;
import org.opentripplanner.raptor.rangeraptor.internalapi.RangeRaptorWorker;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorRouterResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerState;
import org.opentripplanner.raptor.rangeraptor.internalapi.RoutingStrategy;
import org.opentripplanner.raptor.rangeraptor.internalapi.SlackProvider;
Expand Down Expand Up @@ -110,7 +110,7 @@ public DefaultRangeRaptorWorker(
}

@Override
public RaptorWorkerResult<T> results() {
public RaptorRouterResult<T> results() {
return state.results();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import org.opentripplanner.raptor.api.model.RaptorConstants;
import org.opentripplanner.raptor.api.model.RaptorTripSchedule;
import org.opentripplanner.raptor.rangeraptor.internalapi.RangeRaptorWorker;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorRouter;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorRouterResult;
import org.opentripplanner.raptor.rangeraptor.lifecycle.LifeCycleEventPublisher;
import org.opentripplanner.raptor.rangeraptor.transit.AccessPaths;
import org.opentripplanner.raptor.rangeraptor.transit.RaptorTransitCalculator;
Expand Down Expand Up @@ -43,7 +44,7 @@
* @param <T> The TripSchedule type defined by the user of the raptor API.
*/
@SuppressWarnings("Duplicates")
public final class RangeRaptor<T extends RaptorTripSchedule> {
public final class RangeRaptor<T extends RaptorTripSchedule> implements RaptorRouter<T> {

private final RangeRaptorWorker<T> worker;

Expand Down Expand Up @@ -84,13 +85,7 @@ public RangeRaptor(
this.lifeCycle = lifeCyclePublisher;
}

/**
* For each iteration (minute), calculate the minimum travel time to each transit stop in
* seconds.
* <p/>
* Run the scheduled search, round 0 is the street search.
*/
public RaptorWorkerResult<T> route() {
public RaptorRouterResult<T> route() {
timers.route(() -> {
int iterationDepartureTime = RaptorConstants.TIME_NOT_SET;
lifeCycle.notifyRouteSearchStart(calculator.searchForward());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import javax.annotation.Nullable;
import org.opentripplanner.raptor.api.model.RaptorTripSchedule;
import org.opentripplanner.raptor.rangeraptor.internalapi.RangeRaptorWorker;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorRouterResult;
import org.opentripplanner.raptor.util.composite.CompositeUtil;

/**
Expand Down Expand Up @@ -37,7 +37,7 @@ public static <T extends RaptorTripSchedule> RangeRaptorWorker<T> of(
}

@Override
public RaptorWorkerResult<T> results() {
public RaptorRouterResult<T> results() {
return tail().results();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface RangeRaptorWorker<T extends RaptorTripSchedule> {
/**
* Fetch the result after the search is performed.
*/
RaptorWorkerResult<T> results();
RaptorRouterResult<T> results();

/**
* Check if the RangeRaptor should continue with a new round.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.opentripplanner.raptor.rangeraptor.internalapi;

import org.opentripplanner.raptor.api.model.RaptorTripSchedule;

/**
* Interface for Raptor Router. Allow instrumentation/wrapping the router. This is not
* currently used in the main branch of OTP, but it is used in Entur fork to extend the
* router functionality.
*/
public interface RaptorRouter<T extends RaptorTripSchedule> {
/**
* Perform the routing request and return the result. A range-raptor request will
* iterate over the minutes in the search-window, while a plain raptor search will
* just do one iteration.
*/
RaptorRouterResult<T> route();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* This is the result of a RangeRaptor route call.
*/
public interface RaptorWorkerResult<T extends RaptorTripSchedule> {
public interface RaptorRouterResult<T extends RaptorTripSchedule> {
/**
* Return all paths found.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ public interface RaptorWorkerState<T extends RaptorTripSchedule> {
*/
void transferToStops(int fromStop, Iterator<? extends RaptorTransfer> transfers);

RaptorWorkerResult<T> results();
RaptorRouterResult<T> results();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.opentripplanner.raptor.api.model.RaptorAccessEgress;
import org.opentripplanner.raptor.api.model.RaptorTransfer;
import org.opentripplanner.raptor.api.model.RaptorTripSchedule;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorRouterResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerState;
import org.opentripplanner.raptor.rangeraptor.internalapi.WorkerLifeCycle;
import org.opentripplanner.raptor.rangeraptor.multicriteria.arrivals.McStopArrival;
Expand Down Expand Up @@ -110,9 +110,9 @@ public void transferToStops(int fromStop, Iterator<? extends RaptorTransfer> tra
}

@Override
public RaptorWorkerResult<T> results() {
public RaptorRouterResult<T> results() {
arrivals.debugStateInfo();
return new McRaptorWorkerResult<T>(arrivals, paths);
return new McRaptorRouterResult<T>(arrivals, paths);
}

Iterable<? extends McStopArrival<T>> listStopArrivalsPreviousRound(int stop) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import java.util.Collection;
import org.opentripplanner.raptor.api.model.RaptorTripSchedule;
import org.opentripplanner.raptor.api.path.RaptorPath;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorRouterResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.SingleCriteriaStopArrivals;
import org.opentripplanner.raptor.rangeraptor.path.DestinationArrivalPaths;

public class McRaptorWorkerResult<T extends RaptorTripSchedule> implements RaptorWorkerResult<T> {
public class McRaptorRouterResult<T extends RaptorTripSchedule> implements RaptorRouterResult<T> {

private final McStopArrivals<T> stopArrivals;
private final DestinationArrivalPaths<T> paths;

public McRaptorWorkerResult(McStopArrivals<T> arrivals, DestinationArrivalPaths<T> paths) {
public McRaptorRouterResult(McStopArrivals<T> arrivals, DestinationArrivalPaths<T> paths) {
stopArrivals = arrivals;
this.paths = paths;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.opentripplanner.raptor.api.model.RaptorTransfer;
import org.opentripplanner.raptor.api.model.RaptorTripSchedule;
import org.opentripplanner.raptor.api.model.TransitArrival;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorRouterResult;
import org.opentripplanner.raptor.rangeraptor.standard.besttimes.BestTimes;
import org.opentripplanner.raptor.rangeraptor.standard.internalapi.ArrivedAtDestinationCheck;
import org.opentripplanner.raptor.rangeraptor.standard.internalapi.BestNumberOfTransfers;
Expand Down Expand Up @@ -209,8 +209,8 @@ private void transferToStop(int arrivalTimeTransit, int fromStop, RaptorTransfer
}

@Override
public RaptorWorkerResult<T> results() {
return new StdRaptorWorkerResult<>(
public RaptorRouterResult<T> results() {
return new StdRaptorRouterResult<>(
bestTimes,
stopArrivalsState::extractPaths,
bestNumberOfTransfers::extractBestNumberOfTransfers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import java.util.function.Supplier;
import org.opentripplanner.raptor.api.model.RaptorTripSchedule;
import org.opentripplanner.raptor.api.path.RaptorPath;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorRouterResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.SingleCriteriaStopArrivals;
import org.opentripplanner.raptor.rangeraptor.standard.besttimes.BestTimes;

/**
* Result for Standard Range Raptor route call.
*/
public class StdRaptorWorkerResult<T extends RaptorTripSchedule> implements RaptorWorkerResult<T> {
public class StdRaptorRouterResult<T extends RaptorTripSchedule> implements RaptorRouterResult<T> {

private final BestTimes bestTimes;
private final Supplier<Collection<RaptorPath<T>>> pathSupplier;
Expand All @@ -23,7 +23,7 @@ public class StdRaptorWorkerResult<T extends RaptorTripSchedule> implements Rapt
*/
private Collection<RaptorPath<T>> paths = null;

public StdRaptorWorkerResult(
public StdRaptorRouterResult(
BestTimes bestTimes,
Supplier<Collection<RaptorPath<T>>> pathSupplier,
Supplier<SingleCriteriaStopArrivals> bestNumberOfTransfersSupplier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.opentripplanner.raptor.rangeraptor.context.SearchContext;
import org.opentripplanner.raptor.rangeraptor.internalapi.Heuristics;
import org.opentripplanner.raptor.rangeraptor.internalapi.ParetoSetCost;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorRouterResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerState;
import org.opentripplanner.raptor.rangeraptor.internalapi.RoutingStrategy;
import org.opentripplanner.raptor.rangeraptor.path.DestinationArrivalPaths;
Expand Down Expand Up @@ -69,7 +69,7 @@ public RoutingStrategy<T> strategy() {
return strategy;
}

public Heuristics createHeuristics(RaptorWorkerResult<T> results) {
public Heuristics createHeuristics(RaptorRouterResult<T> results) {
return oneOf(
new HeuristicsAdapter(
ctx.nStops(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/**
* Round tracker to keep track of round index and when to stop exploring new rounds.
* <p>
* In round 0 the access paths with one leg are added. In round 1 the first transit and transfers is
* added, ...
* In round zero(0), the access paths with one leg are added. In round one(1) the first transit and
* transfers is added, ...
*/
public class RoundTracker {

Expand All @@ -30,7 +30,7 @@ public class RoundTracker {
* This is default set to the maximum number of rounds limit, but as soon as the destination is
* reach the {@link #numberOfAdditionalTransfers} is used to update the limit.
* <p/>
* The limit is inclusive, indicating the the last round to process.
* The limit is inclusive, indicating the last round to process.
*/
private int roundMaxLimit;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.opentripplanner.raptor.service;

import org.opentripplanner.raptor.api.response.StopArrivals;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorRouterResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.SingleCriteriaStopArrivals;

/**
Expand All @@ -13,9 +13,9 @@ public class DefaultStopArrivals implements StopArrivals {
private SingleCriteriaStopArrivals bestTransitArrivalTime = null;
private SingleCriteriaStopArrivals bestNumberOfTransfers = null;

private final RaptorWorkerResult<?> results;
private final RaptorRouterResult<?> results;

public DefaultStopArrivals(RaptorWorkerResult<?> results) {
public DefaultStopArrivals(RaptorRouterResult<?> results) {
this.results = results;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.opentripplanner.raptor.configure.RaptorConfig;
import org.opentripplanner.raptor.rangeraptor.RangeRaptor;
import org.opentripplanner.raptor.rangeraptor.internalapi.Heuristics;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorWorkerResult;
import org.opentripplanner.raptor.rangeraptor.internalapi.RaptorRouterResult;
import org.opentripplanner.raptor.spi.RaptorTransitDataProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -36,7 +36,7 @@ public class HeuristicSearchTask<T extends RaptorTripSchedule> {
private RangeRaptor<T> search = null;
private RaptorRequest<T> originalRequest;
private RaptorRequest<T> heuristicRequest;
private RaptorWorkerResult<T> result = null;
private RaptorRouterResult<T> result = null;

public HeuristicSearchTask(
RaptorRequest<T> request,
Expand Down Expand Up @@ -144,7 +144,7 @@ private void createHeuristicSearchIfNotExist(RaptorRequest<T> request) {
);

heuristicRequest = builder.build();
search = config.createHeuristicSearch(transitData, heuristicRequest);
search = config.createRangeRaptorWithHeuristicSearch(transitData, heuristicRequest);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,18 @@ private void runHeuristics() {

private RaptorResponse<T> createAndRunDynamicRRWorker(RaptorRequest<T> request) {
LOG.debug("Main request: {}", request);
RangeRaptor<T> raptorWorker;
RangeRaptor<T> rangeRaptorRouter;

// Create worker
if (request.profile().is(MULTI_CRITERIA)) {
raptorWorker = config.createMcWorker(transitData, request, getDestinationHeuristics());
rangeRaptorRouter =
config.createRangeRaptorWithMcWorker(transitData, request, getDestinationHeuristics());
} else {
raptorWorker = config.createStdWorker(transitData, request);
rangeRaptorRouter = config.createRangeRaptorWithStdWorker(transitData, request);
}

// Route
var result = raptorWorker.route();
var result = rangeRaptorRouter.route();

// create and return response
return new RaptorResponse<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,18 @@ private void runHeuristics() {

private RaptorResponse<T> createAndRunDynamicRRWorker(RaptorRequest<T> request) {
LOG.debug("Main request: {}", request);
RangeRaptor<T> raptorWorker;
RangeRaptor<T> rangeRaptorRouter;

// Create worker
if (request.profile().is(MULTI_CRITERIA)) {
raptorWorker = config.createMcWorker(transitData, request, getDestinationHeuristics());
rangeRaptorRouter =
config.createRangeRaptorWithMcWorker(transitData, request, getDestinationHeuristics());
} else {
raptorWorker = config.createStdWorker(transitData, request);
rangeRaptorRouter = config.createRangeRaptorWithStdWorker(transitData, request);
}

// Route
var result = raptorWorker.route();
var result = rangeRaptorRouter.route();

// create and return response
return new RaptorResponse<>(
Expand Down

0 comments on commit 68e8867

Please sign in to comment.