org.opentripplanner.transit.raptor.RaptorService 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;
import java.util.stream.Collectors;
import org.opentripplanner.transit.raptor.api.request.RaptorRequest;
import org.opentripplanner.transit.raptor.api.response.RaptorResponse;
import org.opentripplanner.transit.raptor.api.transit.RaptorTransitDataProvider;
import org.opentripplanner.transit.raptor.api.transit.RaptorTripSchedule;
import org.opentripplanner.transit.raptor.configure.RaptorConfig;
import org.opentripplanner.transit.raptor.rangeraptor.internalapi.Worker;
import org.opentripplanner.transit.raptor.service.HeuristicSearchTask;
import org.opentripplanner.transit.raptor.service.RangeRaptorDynamicSearch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A service for performing Range Raptor routing request.
*
* @param The TripSchedule type defined by the user of the range raptor API.
*/
public class RaptorService {
private static final Logger LOG = LoggerFactory.getLogger(RaptorService.class);
private final RaptorConfig config;
public RaptorService(RaptorConfig config) {
this.config = config;
}
public RaptorResponse route(
RaptorRequest request,
RaptorTransitDataProvider transitData
) {
LOG.debug("Original request: {}", request);
RaptorResponse response;
if (request.isDynamicSearch()) {
response = new RangeRaptorDynamicSearch<>(config, transitData, request).route();
} else {
response = routeUsingStdWorker(transitData, request);
}
if (LOG.isDebugEnabled()) {
var pathsAsText = response
.paths()
.stream()
.map(p -> "\t\n" + p.toString(transitData.stopNameResolver()))
.collect(Collectors.joining());
LOG.debug("Result: {}", pathsAsText);
}
return response;
}
/**
* TODO Add back the possibility to compare heuristics using a test - like the SpeedTest,
* but maybe better to make a separate test.
*/
@SuppressWarnings("unused")
public void compareHeuristics(
RaptorRequest r1,
RaptorRequest r2,
RaptorTransitDataProvider transitData
) {
HeuristicSearchTask fwdHeur = new HeuristicSearchTask<>(r1, config, transitData);
HeuristicSearchTask revHeur = new HeuristicSearchTask<>(r2, config, transitData);
fwdHeur.forceRun();
revHeur.forceRun();
fwdHeur.debugCompareResult(revHeur);
}
/* private methods */
private RaptorResponse routeUsingStdWorker(
RaptorTransitDataProvider transitData,
RaptorRequest request
) {
Worker worker = config.createStdWorker(transitData, request);
worker.route();
return new RaptorResponse<>(worker.paths(), worker.stopArrivals(), request, request);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy