public void testDeleteNodes(int fillToSize) { graph = createGraph(); NodeAccess na = graph.getNodeAccess(); na.setNode(0, 12, 23); na.setNode(1, 38.33f, 135.3f); na.setNode(2, 3, 3); na.setNode(3, 78, 89); na.setNode(4, 2, 1); na.setNode(5, 2.5f, 1); int deleted = 2; for (int i = 6; i < fillToSize; i++) { na.setNode(i, i * 1.5, i * 1.6); if (i % 3 == 0) { graph.markNodeRemoved(i); deleted++; } else { // connect to // ... a deleted node graph.edge(i, 0, 10 * i, true); // ... a non-deleted and non-moved node graph.edge(i, 2, 10 * i, true); // ... a moved node graph.edge(i, fillToSize - 1, 10 * i, true); } } graph.edge(0, 1, 10, true); graph.edge(0, 3, 20, false); graph.edge(3, 5, 20, true); graph.edge(1, 5, 20, false); graph.markNodeRemoved(0); graph.markNodeRemoved(2); // no deletion happend assertEquals(fillToSize, graph.getNodes()); assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph)); // now actually perform deletion graph.optimize(); assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph)); assertEquals(fillToSize - deleted, graph.getNodes()); int id1 = getIdOf(graph, 38.33f); assertEquals(135.3f, na.getLongitude(id1), 1e-4); assertTrue(containsLatitude(graph, carAllExplorer.setBaseNode(id1), 2.5)); assertFalse(containsLatitude(graph, carAllExplorer.setBaseNode(id1), 12)); int id3 = getIdOf(graph, 78); assertEquals(89, na.getLongitude(id3), 1e-4); assertTrue(containsLatitude(graph, carAllExplorer.setBaseNode(id3), 2.5)); assertFalse(containsLatitude(graph, carAllExplorer.setBaseNode(id3), 12)); }
@Test public void testDeleteAndOptimize() { graph = createGraph(); NodeAccess na = graph.getNodeAccess(); na.setNode(20, 10, 10); na.setNode(21, 10, 11); graph.markNodeRemoved(20); graph.optimize(); assertEquals(11, na.getLongitude(20), 1e-5); }
public static int getIdOf(Graph g, double latitude, double longitude) { int s = g.getNodes(); NodeAccess na = g.getNodeAccess(); for (int i = 0; i < s; i++) { if (Math.abs(na.getLatitude(i) - latitude) < 1e-4 && Math.abs(na.getLongitude(i) - longitude) < 1e-4) { return i; } } return -1; }
protected void checkGraph(Graph g) { NodeAccess na = g.getNodeAccess(); assertTrue(na.is3D()); assertTrue(g.getBounds().isValid()); assertEquals(new BBox(10, 20, 10, 12, 0, 1), g.getBounds()); assertEquals(10, na.getLatitude(0), 1e-2); assertEquals(10, na.getLongitude(0), 1e-2); EdgeExplorer explorer = g.createEdgeExplorer(carOutFilter); assertEquals(2, GHUtility.count(explorer.setBaseNode(0))); assertEquals(GHUtility.asSet(2, 1), GHUtility.getNeighbors(explorer.setBaseNode(0))); EdgeIterator iter = explorer.setBaseNode(0); assertTrue(iter.next()); assertEquals(Helper.createPointList3D(3.5, 4.5, 0, 5, 6, 0), iter.fetchWayGeometry(0)); assertTrue(iter.next()); assertEquals(Helper.createPointList3D(1.5, 1, 0, 2, 3, 0), iter.fetchWayGeometry(0)); assertEquals(Helper.createPointList3D(10, 10, 0, 1.5, 1, 0, 2, 3, 0), iter.fetchWayGeometry(1)); assertEquals(Helper.createPointList3D(1.5, 1, 0, 2, 3, 0, 11, 20, 1), iter.fetchWayGeometry(2)); assertEquals(11, na.getLatitude(1), 1e-2); assertEquals(20, na.getLongitude(1), 1e-2); assertEquals(2, GHUtility.count(explorer.setBaseNode(1))); assertEquals(GHUtility.asSet(2, 0), GHUtility.getNeighbors(explorer.setBaseNode(1))); assertEquals(12, na.getLatitude(2), 1e-2); assertEquals(12, na.getLongitude(2), 1e-2); assertEquals(1, GHUtility.count(explorer.setBaseNode(2))); assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(explorer.setBaseNode(2))); EdgeIteratorState eib = GHUtility.getEdge(g, 1, 2); assertEquals(Helper.createPointList3D(), eib.fetchWayGeometry(0)); assertEquals(Helper.createPointList3D(11, 20, 1), eib.fetchWayGeometry(1)); assertEquals(Helper.createPointList3D(12, 12, 0.4), eib.fetchWayGeometry(2)); assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(explorer.setBaseNode(2))); }
private void checkExampleGraph(Graph graph) { NodeAccess na = graph.getNodeAccess(); assertEquals(12f, na.getLatitude(0), 1e-6); assertEquals(23f, na.getLongitude(0), 1e-6); assertEquals(38.33f, na.getLatitude(1), 1e-6); assertEquals(135.3f, na.getLongitude(1), 1e-6); assertEquals(6, na.getLatitude(2), 1e-6); assertEquals(139, na.getLongitude(2), 1e-6); assertEquals(78, na.getLatitude(3), 1e-6); assertEquals(89, na.getLongitude(3), 1e-6); assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(carOutExplorer.setBaseNode((1)))); assertEquals( GHUtility.asSet(5, 4, 3, 2, 1), GHUtility.getNeighbors(carOutExplorer.setBaseNode(0))); try { assertEquals(0, count(carOutExplorer.setBaseNode(6))); // for now return empty iterator // assertFalse(true); } catch (Exception ex) { } }
@Test public void testGrid() { Graph g = createSampleGraph(new EncodingManager("car")); int locs = g.getNodes(); idx = createIndex(g, -1); // if we would use less array entries then some points gets the same key so avoid that for this // test // e.g. for 16 we get "expected 6 but was 9" i.e 6 was overwritten by node j9 which is a bit // closer to the grid center // go through every point of the graph if all points are reachable NodeAccess na = g.getNodeAccess(); for (int i = 0; i < locs; i++) { double lat = na.getLatitude(i); double lon = na.getLongitude(i); assertEquals("nodeId:" + i + " " + (float) lat + "," + (float) lon, i, findID(idx, lat, lon)); } // hit random lat,lon and compare result to full index Random rand = new Random(12); LocationIndex fullIndex; if (hasEdgeSupport()) fullIndex = new Location2IDFullWithEdgesIndex(g); else fullIndex = new Location2IDFullIndex(g); DistanceCalc dist = new DistanceCalcEarth(); for (int i = 0; i < 100; i++) { double lat = rand.nextDouble() * 5; double lon = rand.nextDouble() * 5; int fullId = findID(fullIndex, lat, lon); double fullLat = na.getLatitude(fullId); double fullLon = na.getLongitude(fullId); float fullDist = (float) dist.calcDist(lat, lon, fullLat, fullLon); int newId = findID(idx, lat, lon); double newLat = na.getLatitude(newId); double newLon = na.getLongitude(newId); float newDist = (float) dist.calcDist(lat, lon, newLat, newLon); if (testGridIgnore(i)) { continue; } assertTrue( i + " orig:" + (float) lat + "," + (float) lon + " full:" + fullLat + "," + fullLon + " fullDist:" + fullDist + " found:" + newLat + "," + newLon + " foundDist:" + newDist, Math.abs(fullDist - newDist) < 50000); } fullIndex.close(); Helper.close((Closeable) g); }