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);
}
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;
}
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;
}
Aggregations