Search in sources :

Example 1 with RaptorRoutingRequestTransitData

use of org.opentripplanner.routing.algorithm.raptor.transit.request.RaptorRoutingRequestTransitData 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;
}
Also used : RaptorPathToItineraryMapper(org.opentripplanner.routing.algorithm.mapping.RaptorPathToItineraryMapper) ArrayList(java.util.ArrayList) TripSchedule(org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule) FareService(org.opentripplanner.routing.services.FareService) RoutingValidationException(org.opentripplanner.routing.error.RoutingValidationException) RoutingError(org.opentripplanner.routing.api.response.RoutingError) Itinerary(org.opentripplanner.model.plan.Itinerary) RaptorRoutingRequestTransitData(org.opentripplanner.routing.algorithm.raptor.transit.request.RaptorRoutingRequestTransitData) AccessEgress(org.opentripplanner.routing.algorithm.raptor.transit.AccessEgress) TransitLayer(org.opentripplanner.routing.algorithm.raptor.transit.TransitLayer)

Aggregations

ArrayList (java.util.ArrayList)1 Itinerary (org.opentripplanner.model.plan.Itinerary)1 RaptorPathToItineraryMapper (org.opentripplanner.routing.algorithm.mapping.RaptorPathToItineraryMapper)1 AccessEgress (org.opentripplanner.routing.algorithm.raptor.transit.AccessEgress)1 TransitLayer (org.opentripplanner.routing.algorithm.raptor.transit.TransitLayer)1 TripSchedule (org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule)1 RaptorRoutingRequestTransitData (org.opentripplanner.routing.algorithm.raptor.transit.request.RaptorRoutingRequestTransitData)1 RoutingError (org.opentripplanner.routing.api.response.RoutingError)1 RoutingValidationException (org.opentripplanner.routing.error.RoutingValidationException)1 FareService (org.opentripplanner.routing.services.FareService)1