Search in sources :

Example 76 with GraphPath

use of org.opentripplanner.routing.spt.GraphPath in project OpenTripPlanner by opentripplanner.

the class GraphPathFinder method graphPathFinderEntryPoint.

/* Try to find N paths through the Graph */
public List<GraphPath> graphPathFinderEntryPoint(RoutingRequest request) {
    // We used to perform a protective clone of the RoutingRequest here.
    // There is no reason to do this if we don't modify the request.
    // Any code that changes them should be performing the copy!
    List<GraphPath> paths = null;
    try {
        paths = getGraphPathsConsideringIntermediates(request);
        if (paths == null && request.wheelchairAccessible) {
            // There are no paths that meet the user's slope restrictions.
            // Try again without slope restrictions, and warn the user in the response.
            RoutingRequest relaxedRequest = request.clone();
            relaxedRequest.maxSlope = Double.MAX_VALUE;
            request.rctx.slopeRestrictionRemoved = true;
            paths = getGraphPathsConsideringIntermediates(relaxedRequest);
        }
        request.rctx.debugOutput.finishedCalculating();
    } catch (VertexNotFoundException e) {
        LOG.info("Vertex not found: " + request.from + " : " + request.to);
        throw e;
    }
    // Removing paths might result in an empty list, so do this check before the empty list check.
    if (paths != null) {
        Iterator<GraphPath> gpi = paths.iterator();
        while (gpi.hasNext()) {
            GraphPath graphPath = gpi.next();
            // TODO check, is it possible that arriveBy and time are modifed in-place by the search?
            if (request.arriveBy) {
                if (graphPath.states.getLast().getTimeSeconds() > request.dateTime) {
                    LOG.error("A graph path arrives after the requested time. This implies a bug.");
                    gpi.remove();
                }
            } else {
                if (graphPath.states.getFirst().getTimeSeconds() < request.dateTime) {
                    LOG.error("A graph path leaves before the requested time. This implies a bug.");
                    gpi.remove();
                }
            }
        }
    }
    if (paths == null || paths.size() == 0) {
        LOG.debug("Path not found: " + request.from + " : " + request.to);
        // make sure we still report full search time
        request.rctx.debugOutput.finishedRendering();
        throw new PathNotFoundException();
    }
    return paths;
}
Also used : GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) PathNotFoundException(org.opentripplanner.routing.error.PathNotFoundException) VertexNotFoundException(org.opentripplanner.routing.error.VertexNotFoundException)

Aggregations

GraphPath (org.opentripplanner.routing.spt.GraphPath)76 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)56 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)47 Vertex (org.opentripplanner.routing.graph.Vertex)39 State (org.opentripplanner.routing.core.State)25 Test (org.junit.Test)18 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)18 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)17 Edge (org.opentripplanner.routing.graph.Edge)15 Graph (org.opentripplanner.routing.graph.Graph)13 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)11 Stop (org.onebusaway.gtfs.model.Stop)10 HashSet (java.util.HashSet)9 Trip (org.onebusaway.gtfs.model.Trip)9 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)9 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)8 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)6 File (java.io.File)5 TransitBoardAlight (org.opentripplanner.routing.edgetype.TransitBoardAlight)5 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)5