Search in sources :

Example 1 with VertexNotFoundException

use of org.opentripplanner.routing.error.VertexNotFoundException in project OpenTripPlanner by opentripplanner.

the class BatchProcessor method buildRequest.

private RoutingRequest buildRequest(Individual i) {
    RoutingRequest req = prototypeRoutingRequest.clone();
    req.setDateTime(date, time, timeZone);
    if (searchCutoffSeconds > 0) {
        req.worstTime = req.dateTime + (req.arriveBy ? -searchCutoffSeconds : searchCutoffSeconds);
    }
    GenericLocation latLon = new GenericLocation(i.lat, i.lon);
    req.batch = true;
    if (req.arriveBy)
        req.to = latLon;
    else
        req.from = latLon;
    try {
        req.setRoutingContext(graphService.getRouter(req.routerId).graph);
        return req;
    } catch (VertexNotFoundException vnfe) {
        LOG.debug("no vertex could be created near the origin point");
        return null;
    }
}
Also used : GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) VertexNotFoundException(org.opentripplanner.routing.error.VertexNotFoundException)

Example 2 with VertexNotFoundException

use of org.opentripplanner.routing.error.VertexNotFoundException in project OpenTripPlanner by opentripplanner.

the class RepeatedRaptorTestResource method oneOrigin.

private void oneOrigin(double lat, double lon, String banAgency) {
    ProfileRequest req = new ProfileRequest();
    req.fromLat = lat;
    req.fromLon = lon;
    req.fromTime = 60 * 60 * 8;
    req.toTime = 60 * 60 * 9;
    req.walkSpeed = 2;
    req.bikeSpeed = 4;
    req.carSpeed = 8;
    req.date = new LocalDate(2015, 04, 20);
    // minutes
    req.maxWalkTime = 20;
    req.accessModes = new QualifiedModeSet("WALK");
    req.egressModes = new QualifiedModeSet("WALK");
    req.transitModes = new TraverseModeSet("TRANSIT");
    req.analyst = true;
    if (surfaceCache == null) {
        LOG.error("You must run OTP with the --analyst option to enable spatial analysis features.");
    }
    final RepeatedRaptorProfileRouter router_a = new RepeatedRaptorProfileRouter(graph, req);
    final RepeatedRaptorProfileRouter router_b = new RepeatedRaptorProfileRouter(graph, req);
    router_b.banAgency = banAgency;
    try {
        router_a.route();
        router_b.route();
    } catch (VertexNotFoundException ex) {
        LOG.error("vertex not found");
        return;
    }
    System.out.printf("stop, min_a, min_b, min_diff, max_a, max_b, max_diff\n");
    boolean decreased = false;
    // Compare the propagated results
    decreased = false;
    TimeSurface.RangeSet timeSurfaces_a = router_a.timeSurfaceRangeSet;
    TimeSurface.RangeSet timeSurfaces_b = router_b.timeSurfaceRangeSet;
    for (Vertex destVertex : timeSurfaces_a.min.times.keySet()) {
        int min_a = timeSurfaces_a.min.getTime(destVertex);
        int max_a = timeSurfaces_a.max.getTime(destVertex);
        int avg_a = timeSurfaces_a.avg.getTime(destVertex);
        int min_b = timeSurfaces_b.min.getTime(destVertex);
        int max_b = timeSurfaces_b.max.getTime(destVertex);
        int avg_b = timeSurfaces_b.avg.getTime(destVertex);
        long min_diff = (long) min_b - min_a;
        long max_diff = (long) max_b - max_a;
        long avg_diff = (long) avg_b - avg_a;
        if (min_b == TimeSurface.UNREACHABLE) {
            min_diff = Integer.MAX_VALUE;
            max_diff = Integer.MAX_VALUE;
            avg_diff = Integer.MAX_VALUE;
        }
        n_total += 1;
        if (min_diff < 0 || max_diff < 0 || avg_diff < 0) {
            n_decrease += 1;
            sum_decrease += max_diff;
            // Time decreased due to banning a route. This is bad, print it out.
            System.out.printf("\"%s\",%d,%d,%d,%d,%d,%d\n", destVertex.getName(), min_a, min_b, min_diff, max_a, max_b, max_diff);
            decreased = true;
        } else if (avg_diff > 0) {
            n_increase += 1;
        }
    }
    if (decreased) {
        LOG.error("Decreases happened at propagated street vertices for this origin!");
    }
    LOG.info("Street Vertices: {} increased, {} decreased out of {} destinations total", n_increase, n_decrease, n_total);
}
Also used : RepeatedRaptorProfileRouter(org.opentripplanner.profile.RepeatedRaptorProfileRouter) Vertex(org.opentripplanner.routing.graph.Vertex) TimeSurface(org.opentripplanner.analyst.TimeSurface) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) ProfileRequest(org.opentripplanner.profile.ProfileRequest) LocalDate(org.joda.time.LocalDate) VertexNotFoundException(org.opentripplanner.routing.error.VertexNotFoundException)

Example 3 with VertexNotFoundException

use of org.opentripplanner.routing.error.VertexNotFoundException 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)

Example 4 with VertexNotFoundException

use of org.opentripplanner.routing.error.VertexNotFoundException in project OpenTripPlanner by opentripplanner.

the class OtpsRouter method plan.

/**
 * Plan a route on the router given the various options.
 *
 * @param req The routing request options (date/time, modes, etc...)
 * @return A Shortest-path-tree (a time+various states for each vertices around the
 *         origin/destination).
 */
public OtpsSPT plan(OtpsRoutingRequest req) {
    try {
        // TODO Is this correct?
        RoutingRequest req2 = req.req.clone();
        req2.setRoutingContext(router.graph);
        // TODO verify that this is indeed the intended behavior.
        ShortestPathTree spt = new AStar().getShortestPathTree(req2);
        return new OtpsSPT(spt, router.graph.getSampleFactory());
    } catch (VertexNotFoundException e) {
        // Can happen, not really an error
        return null;
    }
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) AStar(org.opentripplanner.routing.algorithm.AStar) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) VertexNotFoundException(org.opentripplanner.routing.error.VertexNotFoundException)

Aggregations

VertexNotFoundException (org.opentripplanner.routing.error.VertexNotFoundException)4 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)3 LocalDate (org.joda.time.LocalDate)1 TimeSurface (org.opentripplanner.analyst.TimeSurface)1 QualifiedModeSet (org.opentripplanner.api.parameter.QualifiedModeSet)1 GenericLocation (org.opentripplanner.common.model.GenericLocation)1 ProfileRequest (org.opentripplanner.profile.ProfileRequest)1 RepeatedRaptorProfileRouter (org.opentripplanner.profile.RepeatedRaptorProfileRouter)1 AStar (org.opentripplanner.routing.algorithm.AStar)1 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)1 PathNotFoundException (org.opentripplanner.routing.error.PathNotFoundException)1 Vertex (org.opentripplanner.routing.graph.Vertex)1 GraphPath (org.opentripplanner.routing.spt.GraphPath)1 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)1