use of org.opentripplanner.routing.algorithm.mapping.RaptorPathToItineraryMapper in project OpenTripPlanner by opentripplanner.
the class RoutingWorker method routeTransit.
private Collection<Itinerary> routeTransit(Router router) {
request.setRoutingContext(router.graph);
if (request.modes.transitModes.isEmpty()) {
return Collections.emptyList();
}
if (!router.graph.transitFeedCovers(request.dateTime)) {
throw new RoutingValidationException(List.of(new RoutingError(RoutingErrorCode.OUTSIDE_SERVICE_PERIOD, InputField.DATE_TIME)));
}
TransitLayer transitLayer = request.ignoreRealtimeUpdates ? router.graph.getTransitLayer() : router.graph.getRealtimeTransitLayer();
RaptorRoutingRequestTransitData requestTransitDataProvider;
requestTransitDataProvider = new RaptorRoutingRequestTransitData(transitLayer, request.getDateTime().toInstant(), ADDITIONAL_SEARCH_DAYS_BEFORE_TODAY, ADDITIONAL_SEARCH_DAYS_AFTER_TODAY, request.modes.transitModes, request.rctx.bannedRoutes, request.walkSpeed);
this.debugAggregator.finishedPatternFiltering();
// Prepare access/egress transfers
Collection<AccessEgress> accessTransfers = AccessEgressRouter.streetSearch(request, false, 2000, transitLayer.getStopIndex());
Collection<AccessEgress> egressTransfers = AccessEgressRouter.streetSearch(request, true, 2000, transitLayer.getStopIndex());
verifyEgressAccess(accessTransfers, egressTransfers);
this.debugAggregator.finishedAccessEgress();
// Prepare transit search
RaptorRequest<TripSchedule> raptorRequest = RaptorRequestMapper.mapRequest(request, requestTransitDataProvider.getStartOfTime(), accessTransfers, egressTransfers);
// Route transit
RaptorResponse<TripSchedule> transitResponse = raptorService.route(raptorRequest, requestTransitDataProvider);
LOG.debug("Found {} transit itineraries", transitResponse.paths().size());
LOG.debug("Transit search params used: {}", transitResponse.requestUsed().searchParams());
this.debugAggregator.finishedRaptorSearch();
// Create itineraries
RaptorPathToItineraryMapper itineraryMapper = new RaptorPathToItineraryMapper(transitLayer, requestTransitDataProvider.getStartOfTime(), request);
FareService fareService = request.getRoutingContext().graph.getService(FareService.class);
List<Itinerary> itineraries = new ArrayList<>();
for (Path<TripSchedule> path : transitResponse.paths()) {
// Convert the Raptor/Astar paths to OTP API Itineraries
Itinerary itinerary = itineraryMapper.createItinerary(path);
// fare calculation. We derive the fares from the internal Path objects and add them to the itinerary.
if (fareService != null) {
itinerary.fare = fareService.getCost(path, transitLayer);
}
itineraries.add(itinerary);
}
checkIfTransitConnectionExists(transitResponse);
// Filter itineraries away that depart after the latest-departure-time for depart after
// search. These itineraries is a result of time-shifting the access leg and is needed for
// the raptor to prune the results. These itineraries are often not ideal, but if they
// pareto optimal for the "next" window, they will appear when a "next" search is performed.
searchWindowUsedInSeconds = transitResponse.requestUsed().searchParams().searchWindowInSeconds();
if (!request.arriveBy && searchWindowUsedInSeconds > 0) {
filterOnLatestDepartureTime = Instant.ofEpochSecond(request.dateTime + searchWindowUsedInSeconds);
}
this.debugAggregator.finishedItineraryCreation();
return itineraries;
}
Aggregations