Search in sources :

Example 1 with DebugOutput

use of org.opentripplanner.api.resource.DebugOutput in project OpenTripPlanner by opentripplanner.

the class GraphPathFinder method getGraphPathsConsideringIntermediates.

/**
 * Break up a RoutingRequest with intermediate places into separate requests, in the given order.
 *
 * If there are no intermediate places, issue a single request. Otherwise process the places
 * list [from, i1, i2, ..., to] either from left to right (if {@code request.arriveBy==false})
 * or from right to left (if {@code request.arriveBy==true}). In the latter case the order of
 * the requested subpaths is (i2, to), (i1, i2), and (from, i1) which has to be reversed at
 * the end.
 */
private List<GraphPath> getGraphPathsConsideringIntermediates(RoutingRequest request) {
    if (request.hasIntermediatePlaces()) {
        List<GenericLocation> places = Lists.newArrayList(request.from);
        places.addAll(request.intermediatePlaces);
        places.add(request.to);
        long time = request.dateTime;
        List<GraphPath> paths = new ArrayList<>();
        DebugOutput debugOutput = null;
        int placeIndex = (request.arriveBy ? places.size() - 1 : 1);
        while (0 < placeIndex && placeIndex < places.size()) {
            RoutingRequest intermediateRequest = request.clone();
            intermediateRequest.setNumItineraries(1);
            intermediateRequest.dateTime = time;
            intermediateRequest.from = places.get(placeIndex - 1);
            intermediateRequest.to = places.get(placeIndex);
            intermediateRequest.rctx = null;
            intermediateRequest.setRoutingContext(router.graph);
            if (debugOutput != null) {
                // Restore the previous debug info accumulator
                intermediateRequest.rctx.debugOutput = debugOutput;
            } else {
                // Store the debug info accumulator
                debugOutput = intermediateRequest.rctx.debugOutput;
            }
            List<GraphPath> partialPaths = getPaths(intermediateRequest);
            if (partialPaths.size() == 0) {
                return partialPaths;
            }
            GraphPath path = partialPaths.get(0);
            paths.add(path);
            time = (request.arriveBy ? path.getStartTime() : path.getEndTime());
            placeIndex += (request.arriveBy ? -1 : +1);
        }
        request.setRoutingContext(router.graph);
        request.rctx.debugOutput = debugOutput;
        if (request.arriveBy) {
            Collections.reverse(paths);
        }
        return Collections.singletonList(joinPaths(paths));
    } else {
        return getPaths(request);
    }
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) DebugOutput(org.opentripplanner.api.resource.DebugOutput) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Aggregations

DebugOutput (org.opentripplanner.api.resource.DebugOutput)1 GenericLocation (org.opentripplanner.common.model.GenericLocation)1 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)1 GraphPath (org.opentripplanner.routing.spt.GraphPath)1