Search in sources :

Example 1 with RoutingError

use of org.opentripplanner.routing.api.response.RoutingError in project OpenTripPlanner by opentripplanner.

the class RoutingWorker method verifyEgressAccess.

private void verifyEgressAccess(Collection<?> access, Collection<?> egress) {
    boolean accessExist = !access.isEmpty();
    boolean egressExist = !egress.isEmpty();
    if (accessExist && egressExist) {
        return;
    }
    List<RoutingError> routingErrors = new ArrayList<>();
    if (!accessExist) {
        routingErrors.add(new RoutingError(RoutingErrorCode.NO_STOPS_IN_RANGE, InputField.FROM_PLACE));
    }
    if (!egressExist) {
        routingErrors.add(new RoutingError(RoutingErrorCode.NO_STOPS_IN_RANGE, InputField.TO_PLACE));
    }
    throw new RoutingValidationException(routingErrors);
}
Also used : RoutingError(org.opentripplanner.routing.api.response.RoutingError) RoutingValidationException(org.opentripplanner.routing.error.RoutingValidationException) ArrayList(java.util.ArrayList)

Example 2 with RoutingError

use of org.opentripplanner.routing.api.response.RoutingError in project OpenTripPlanner by opentripplanner.

the class TransmodelGraphQLPlanner method plan.

public PlanResponse plan(DataFetchingEnvironment environment) {
    PlanResponse response = new PlanResponse();
    RoutingRequest request = null;
    try {
        TransmodelRequestContext ctx = environment.getContext();
        Router router = ctx.getRouter();
        request = createRequest(environment);
        RoutingResponse res = ctx.getRoutingService().route(request, router);
        response.plan = res.getTripPlan();
        response.metadata = res.getMetadata();
        for (RoutingError routingError : res.getRoutingErrors()) {
            response.messages.add(PlannerErrorMapper.mapMessage(routingError).message);
        }
        response.debugOutput = res.getDebugAggregator().finishedRendering();
    } catch (Exception e) {
        LOG.warn("System error");
        LOG.error("Root cause: " + e.getMessage(), e);
        PlannerError error = new PlannerError();
        error.setMsg(Message.SYSTEM_ERROR);
        response.messages.add(error.message);
    }
    return response;
}
Also used : RoutingError(org.opentripplanner.routing.api.response.RoutingError) PlanResponse(org.opentripplanner.ext.transmodelapi.model.PlanResponse) Router(org.opentripplanner.standalone.server.Router) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) PlannerError(org.opentripplanner.api.model.error.PlannerError) RoutingResponse(org.opentripplanner.routing.api.response.RoutingResponse) ParameterException(org.opentripplanner.api.common.ParameterException)

Example 3 with RoutingError

use of org.opentripplanner.routing.api.response.RoutingError 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

RoutingError (org.opentripplanner.routing.api.response.RoutingError)3 ArrayList (java.util.ArrayList)2 RoutingValidationException (org.opentripplanner.routing.error.RoutingValidationException)2 ParameterException (org.opentripplanner.api.common.ParameterException)1 PlannerError (org.opentripplanner.api.model.error.PlannerError)1 PlanResponse (org.opentripplanner.ext.transmodelapi.model.PlanResponse)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 RoutingRequest (org.opentripplanner.routing.api.request.RoutingRequest)1 RoutingResponse (org.opentripplanner.routing.api.response.RoutingResponse)1 FareService (org.opentripplanner.routing.services.FareService)1 Router (org.opentripplanner.standalone.server.Router)1