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