@Test public void testSimpleDelete2() { graph = createGraph(); NodeAccess na = graph.getNodeAccess(); assertEquals(-1, getIdOf(graph, 12)); na.setNode(9, 9, 1); assertEquals(-1, getIdOf(graph, 12)); na.setNode(11, 11, 1); na.setNode(12, 12, 1); // mini subnetwork which gets completely removed: graph.edge(5, 10, 510, true); graph.markNodeRemoved(5); graph.markNodeRemoved(10); PointList pl = new PointList(); pl.add(1, 2, Double.NaN); pl.add(1, 3, Double.NaN); graph.edge(9, 11, 911, true).setWayGeometry(pl); graph.edge(9, 12, 912, true).setWayGeometry(pl); assertEquals(13, graph.getNodes()); assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph)); // perform deletion graph.optimize(); assertEquals(11, graph.getNodes()); assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph)); int id11 = getIdOf(graph, 11); // is now 10 int id12 = getIdOf(graph, 12); // is now 5 int id9 = getIdOf(graph, 9); // is now 9 assertEquals( GHUtility.asSet(id12, id11), GHUtility.getNeighbors(carAllExplorer.setBaseNode(id9))); assertEquals(GHUtility.asSet(id9), GHUtility.getNeighbors(carAllExplorer.setBaseNode(id11))); assertEquals(GHUtility.asSet(id9), GHUtility.getNeighbors(carAllExplorer.setBaseNode(id12))); EdgeIterator iter = carAllExplorer.setBaseNode(id9); assertTrue(iter.next()); assertEquals(id12, iter.getAdjNode()); assertEquals(2, iter.fetchWayGeometry(0).getLongitude(0), 1e-7); assertTrue(iter.next()); assertEquals(id11, iter.getAdjNode()); assertEquals(2, iter.fetchWayGeometry(0).getLongitude(0), 1e-7); }
public static void assertPList(PointList expected, PointList list) { assertEquals("size of point lists is not equal", expected.getSize(), list.getSize()); for (int i = 0; i < expected.getSize(); i++) { assertEquals(expected.getLatitude(i), list.getLatitude(i), 1e-4); assertEquals(expected.getLongitude(i), list.getLongitude(i), 1e-4); } }
@Override public GHResponse route(GHRequest request) { request.check(); StopWatch sw = new StopWatch().start(); GHResponse rsp = new GHResponse(); if (!setSupportsVehicle(request.getVehicle())) { rsp.addError( new IllegalArgumentException( "Vehicle " + request.getVehicle() + " unsupported. Supported are: " + getEncodingManager())); return rsp; } EdgeFilter edgeFilter = new DefaultEdgeFilter(encodingManager.getEncoder(request.getVehicle())); int from = index .findClosest(request.getFrom().lat, request.getFrom().lon, edgeFilter) .getClosestNode(); int to = index.findClosest(request.getTo().lat, request.getTo().lon, edgeFilter).getClosestNode(); String debug = "idLookup:" + sw.stop().getSeconds() + "s"; if (from < 0) rsp.addError(new IllegalArgumentException("Cannot find point 1: " + request.getFrom())); if (to < 0) rsp.addError(new IllegalArgumentException("Cannot find point 2: " + request.getTo())); if (from == to) rsp.addError(new IllegalArgumentException("Point 1 is equal to point 2")); sw = new StopWatch().start(); RoutingAlgorithm algo = null; if (chUsage) { if (request.getAlgorithm().equals("dijkstrabi")) algo = prepare.createAlgo(); else if (request.getAlgorithm().equals("astarbi")) algo = ((PrepareContractionHierarchies) prepare).createAStar(); else rsp.addError( new IllegalStateException( "Only dijkstrabi and astarbi is supported for LevelGraph (using contraction hierarchies)!")); } else { prepare = NoOpAlgorithmPreparation.createAlgoPrepare( graph, request.getAlgorithm(), encodingManager.getEncoder(request.getVehicle()), request.getType()); algo = prepare.createAlgo(); } if (rsp.hasErrors()) { return rsp; } debug += ", algoInit:" + sw.stop().getSeconds() + "s"; sw = new StopWatch().start(); Path path = algo.calcPath(from, to); debug += ", " + algo.getName() + "-routing:" + sw.stop().getSeconds() + "s" + ", " + path.getDebugInfo(); PointList points = path.calcPoints(); simplifyRequest = request.getHint("simplifyRequest", simplifyRequest); if (simplifyRequest) { sw = new StopWatch().start(); int orig = points.getSize(); double minPathPrecision = request.getHint("douglas.minprecision", 1d); if (minPathPrecision > 0) { new DouglasPeucker().setMaxDistance(minPathPrecision).simplify(points); } debug += ", simplify (" + orig + "->" + points.getSize() + "):" + sw.stop().getSeconds() + "s"; } enableInstructions = request.getHint("instructions", enableInstructions); if (enableInstructions) { sw = new StopWatch().start(); rsp.setInstructions(path.calcInstructions()); debug += ", instructions:" + sw.stop().getSeconds() + "s"; } return rsp.setPoints(points) .setDistance(path.getDistance()) .setTime(path.getTime()) .setDebugInfo(debug); }