use of com.graphhopper.routing.RoutingAlgorithm in project graphhopper by graphhopper.
the class CHTurnCostTest method testRouteViaVirtualNode_withAlternative.
@ParameterizedTest
@ValueSource(strings = { DIJKSTRA_BI, ASTAR_BI })
public void testRouteViaVirtualNode_withAlternative(String algo) {
// 3
// 0-x-1
// \ |
// \-2
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 0).setDistance(1));
updateDistancesFor(graph, 0, 0.01, 0.00);
updateDistancesFor(graph, 1, 0.01, 0.02);
updateDistancesFor(graph, 2, 0.00, 0.02);
graph.freeze();
automaticPrepareCH();
LocationIndexTree index = new LocationIndexTree(graph, new RAMDirectory());
index.prepareIndex();
Snap snap = index.findClosest(0.01, 0.01, EdgeFilter.ALL_EDGES);
QueryGraph queryGraph = QueryGraph.create(graph, snap);
assertEquals(3, snap.getClosestNode());
assertEquals(0, snap.getClosestEdge().getEdge());
QueryRoutingCHGraph routingCHGraph = new QueryRoutingCHGraph(chGraph, queryGraph);
RoutingAlgorithm chAlgo = new CHRoutingAlgorithmFactory(routingCHGraph).createAlgo(new PMap().putObject(ALGORITHM, algo));
Path path = chAlgo.calcPath(1, 0);
assertEquals(IntArrayList.from(1, 3, 0), path.calcNodes());
}
use of com.graphhopper.routing.RoutingAlgorithm in project graphhopper by graphhopper.
the class CHTurnCostTest method findPathUsingCH.
private Path findPathUsingCH(int from, int to, int[] contractionOrder) {
prepareCH(contractionOrder);
RoutingAlgorithm chAlgo = createAlgo();
return chAlgo.calcPath(from, to);
}
use of com.graphhopper.routing.RoutingAlgorithm in project graphhopper by graphhopper.
the class CHTurnCostTest method compareCHQueryWithDijkstra.
private void compareCHQueryWithDijkstra(int from, int to) {
Path dijkstraPath = findPathUsingDijkstra(from, to);
RoutingAlgorithm chAlgo = createAlgo();
Path chPath = chAlgo.calcPath(from, to);
boolean algosDisagree = Math.abs(dijkstraPath.getWeight() - chPath.getWeight()) > 1.e-2;
if (checkStrict) {
algosDisagree = algosDisagree || Math.abs(dijkstraPath.getDistance() - chPath.getDistance()) > 1.e-2 || Math.abs(dijkstraPath.getTime() - chPath.getTime()) > 1;
}
if (algosDisagree) {
System.out.println("Graph that produced error:");
GHUtility.printGraphForUnitTest(graph, encoder);
fail("Dijkstra and CH did not find equal shortest paths for route from " + from + " to " + to + "\n" + " dijkstra: weight: " + dijkstraPath.getWeight() + ", distance: " + dijkstraPath.getDistance() + ", time: " + dijkstraPath.getTime() + ", nodes: " + dijkstraPath.calcNodes() + "\n" + " ch: weight: " + chPath.getWeight() + ", distance: " + chPath.getDistance() + ", time: " + chPath.getTime() + ", nodes: " + chPath.calcNodes());
}
}
use of com.graphhopper.routing.RoutingAlgorithm in project graphhopper by graphhopper.
the class PrepareContractionHierarchiesTest method checkPath.
private void checkPath(GraphHopperStorage g, CHConfig c, int expShortcuts, double expDistance, IntIndexedContainer expNodes, int[] nodeOrdering) {
PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, c);
useNodeOrdering(prepare, nodeOrdering);
PrepareContractionHierarchies.Result result = prepare.doWork();
assertEquals(expShortcuts, result.getShortcuts(), c.toString());
RoutingCHGraph lg = g.createCHGraph(result.getCHStorage(), result.getCHConfig());
RoutingAlgorithm algo = new CHRoutingAlgorithmFactory(lg).createAlgo(new PMap());
Path path = algo.calcPath(3, 12);
assertEquals(expDistance, path.getDistance(), 1e-5, path.toString());
assertEquals(expNodes, path.calcNodes(), path.toString());
}
Aggregations