use of com.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.
the class EdgeBasedRoutingAlgorithmTest method testBlockANode.
@ParameterizedTest
@ArgumentsSource(FixtureProvider.class)
public void testBlockANode(String algoStr) {
GraphHopperStorage g = createStorage(createEncodingManager(true));
initGraph(g, carEncoder);
blockNode3(g);
for (int i = 0; i <= 7; i++) {
if (i == 3)
continue;
for (int j = 0; j <= 7; j++) {
if (j == 3)
continue;
Path p = calcPath(g, i, j, algoStr);
// We can go from everywhere to everywhere else without using node 3
assertTrue(p.isFound());
for (IntCursor node : p.calcNodes()) {
assertNotEquals(3, node.value, p.calcNodes().toString());
}
}
}
}
use of com.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.
the class Router method route.
public GHResponse route(GHRequest request) {
try {
checkNoLegacyParameters(request);
checkAtLeastOnePoint(request);
checkIfPointsAreInBounds(request.getPoints());
checkHeadings(request);
checkPointHints(request);
checkCurbsides(request);
checkNoBlockAreaWithCustomModel(request);
Solver solver = createSolver(request);
solver.checkRequest();
solver.init();
if (ROUND_TRIP.equalsIgnoreCase(request.getAlgorithm())) {
if (!(solver instanceof FlexSolver))
throw new IllegalArgumentException("algorithm=round_trip only works with a flexible algorithm");
return routeRoundTrip(request, (FlexSolver) solver);
} else if (ALT_ROUTE.equalsIgnoreCase(request.getAlgorithm())) {
return routeAlt(request, solver);
} else {
return routeVia(request, solver);
}
} catch (MultiplePointsNotFoundException ex) {
GHResponse ghRsp = new GHResponse();
for (IntCursor p : ex.getPointsNotFound()) {
ghRsp.addError(new PointNotFoundException("Cannot find point " + p.value + ": " + request.getPoints().get(p.value), p.value));
}
return ghRsp;
} catch (IllegalArgumentException ex) {
GHResponse ghRsp = new GHResponse();
ghRsp.addError(ex);
return ghRsp;
}
}
use of com.carrotsearch.hppc.cursors.IntCursor 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.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.
the class NodeBasedWitnessPathSearcher method reset.
private void reset() {
for (IntCursor c : changedNodes) weights[c.value] = Double.POSITIVE_INFINITY;
changedNodes.elementsCount = 0;
heap.clear();
ignoreNode = -1;
settledNodes = 0;
}
use of com.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.
the class EdgeBasedTarjanSCCTest method smallGraphWithLoops.
@Test
public void smallGraphWithLoops() {
GraphHopperStorage g = new GraphBuilder(em).create();
// 3<-0->2-1o
// o
// edge-keys 0,1
GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 0).setDistance(1));
// edge-keys 2,3
GHUtility.setSpeed(60, true, false, encoder, g.edge(0, 2).setDistance(1));
// edge-keys 4,5
GHUtility.setSpeed(60, true, false, encoder, g.edge(0, 3).setDistance(1));
// edge-keys 6,7
GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 1).setDistance(1));
// edge-keys 8,9
GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 1).setDistance(1));
ConnectedComponents result = EdgeBasedTarjanSCC.findComponentsRecursive(g, fwdAccessFilter, false);
assertEquals(10, result.getEdgeKeys());
assertEquals(6, result.getTotalComponents());
assertEquals(2, result.getComponents().size());
assertEquals(result.getComponents().get(0), result.getBiggestComponent());
assertEquals(IntArrayList.from(7, 9, 8, 6), result.getComponents().get(0));
assertEquals(IntArrayList.from(1, 0), result.getComponents().get(1));
assertEquals(4, result.getSingleEdgeComponents().cardinality());
for (IntCursor c : IntArrayList.from(2, 3, 4, 5)) {
assertTrue(result.getSingleEdgeComponents().get(c.value));
}
}
Aggregations