Search in sources :

Example 1 with MaximumNodesExceededException

use of com.graphhopper.util.exceptions.MaximumNodesExceededException in project graphhopper by graphhopper.

the class FlexiblePathCalculator method calcPaths.

private List<Path> calcPaths(int from, int to, EdgeRestrictions edgeRestrictions, RoutingAlgorithm algo) {
    StopWatch sw = new StopWatch().start();
    // edges directly without changing the graph
    for (IntCursor c : edgeRestrictions.getUnfavoredEdges()) queryGraph.unfavorVirtualEdge(c.value);
    List<Path> paths;
    if (edgeRestrictions.getSourceOutEdge() != ANY_EDGE || edgeRestrictions.getTargetInEdge() != ANY_EDGE) {
        if (!(algo instanceof BidirRoutingAlgorithm))
            throw new IllegalArgumentException("To make use of the " + Parameters.Routing.CURBSIDE + " parameter you need a bidirectional algorithm, got: " + algo.getName());
        paths = Collections.singletonList(((BidirRoutingAlgorithm) algo).calcPath(from, to, edgeRestrictions.getSourceOutEdge(), edgeRestrictions.getTargetInEdge()));
    } else {
        paths = algo.calcPaths(from, to);
    }
    // reset all direction enforcements in queryGraph to avoid influencing next path
    // todo: is this correct? aren't we taking a second look at these edges later when we calc times or
    // instructions etc.?
    queryGraph.clearUnfavoredStatus();
    if (paths.isEmpty())
        throw new IllegalStateException("Path list was empty for " + from + " -> " + to);
    if (algo.getVisitedNodes() >= algoOpts.getMaxVisitedNodes())
        throw new MaximumNodesExceededException("No path found due to maximum nodes exceeded " + algoOpts.getMaxVisitedNodes(), algoOpts.getMaxVisitedNodes());
    visitedNodes = algo.getVisitedNodes();
    debug += ", " + algo.getName() + "-routing:" + sw.stop().getMillis() + " ms";
    return paths;
}
Also used : IntCursor(com.carrotsearch.hppc.cursors.IntCursor) StopWatch(com.graphhopper.util.StopWatch) MaximumNodesExceededException(com.graphhopper.util.exceptions.MaximumNodesExceededException)

Example 2 with MaximumNodesExceededException

use of com.graphhopper.util.exceptions.MaximumNodesExceededException in project graphhopper by graphhopper.

the class CHPathCalculator method calcPaths.

private List<Path> calcPaths(int from, int to, EdgeRestrictions edgeRestrictions, BidirRoutingAlgorithm algo) {
    StopWatch sw = new StopWatch().start();
    List<Path> paths;
    if (edgeRestrictions.getSourceOutEdge() != ANY_EDGE || edgeRestrictions.getTargetInEdge() != ANY_EDGE) {
        paths = Collections.singletonList(algo.calcPath(from, to, edgeRestrictions.getSourceOutEdge(), edgeRestrictions.getTargetInEdge()));
    } else {
        paths = algo.calcPaths(from, to);
    }
    if (paths.isEmpty())
        throw new IllegalStateException("Path list was empty for " + from + " -> " + to);
    int maxVisitedNodes = algoOpts.getInt(MAX_VISITED_NODES, Integer.MAX_VALUE);
    if (algo.getVisitedNodes() >= maxVisitedNodes)
        throw new MaximumNodesExceededException("No path found due to maximum nodes exceeded " + maxVisitedNodes, maxVisitedNodes);
    visitedNodes = algo.getVisitedNodes();
    debug += ", " + algo.getName() + "-routing:" + sw.stop().getMillis() + " ms";
    return paths;
}
Also used : StopWatch(com.graphhopper.util.StopWatch) MaximumNodesExceededException(com.graphhopper.util.exceptions.MaximumNodesExceededException)

Example 3 with MaximumNodesExceededException

use of com.graphhopper.util.exceptions.MaximumNodesExceededException in project graphhopper by graphhopper.

the class GraphHopperTest method testMonacoMaxVisitedNodes.

@Test
public void testMonacoMaxVisitedNodes() {
    final String profile = "profile";
    final String vehicle = "foot";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true).importOrLoad();
    GHPoint from = new GHPoint(43.741069, 7.426854);
    GHPoint to = new GHPoint(43.744445, 7.429483);
    GHRequest req = new GHRequest(from, to).setProfile(profile);
    req.putHint(Routing.MAX_VISITED_NODES, 5);
    GHResponse rsp = hopper.route(req);
    assertTrue(rsp.hasErrors());
    Throwable throwable = rsp.getErrors().get(0);
    assertTrue(throwable instanceof MaximumNodesExceededException);
    Object nodesDetail = ((MaximumNodesExceededException) throwable).getDetails().get(MaximumNodesExceededException.NODES_KEY);
    assertEquals(5, nodesDetail);
    req = new GHRequest(from, to).setProfile(profile);
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) MaximumNodesExceededException(com.graphhopper.util.exceptions.MaximumNodesExceededException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MaximumNodesExceededException (com.graphhopper.util.exceptions.MaximumNodesExceededException)3 StopWatch (com.graphhopper.util.StopWatch)2 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)1 CHProfile (com.graphhopper.config.CHProfile)1 LMProfile (com.graphhopper.config.LMProfile)1 Profile (com.graphhopper.config.Profile)1 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)1 GHPoint (com.graphhopper.util.shapes.GHPoint)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1