@Test public void testSimpleDelete() { 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); graph.edge(3, 0, 21, true); graph.edge(5, 0, 22, true); graph.edge(5, 3, 23, true); graph.markNodeRemoved(0); graph.markNodeRemoved(3); assertEquals(6, graph.getNodes()); assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph)); // now actually perform deletion graph.optimize(); assertEquals(4, graph.getNodes()); assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph)); // shouldn't change anything graph.optimize(); assertEquals(4, graph.getNodes()); assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph)); }
@Test public void testGetAllEdgesWithDelete() { graph = createGraph(); NodeAccess na = graph.getNodeAccess(); na.setNode(0, 0, 5); na.setNode(1, 1, 5); na.setNode(2, 2, 5); na.setNode(3, 3, 5); graph.edge(0, 1, 1, true); graph.edge(0, 2, 1, true); graph.edge(1, 2, 1, true); graph.edge(2, 3, 1, true); AllEdgesIterator iter = graph.getAllEdges(); assertEquals(4, GHUtility.count(iter)); assertEquals(4, iter.getMaxId()); // delete graph.markNodeRemoved(1); graph.optimize(); iter = graph.getAllEdges(); assertEquals(2, GHUtility.count(iter)); assertEquals(4, iter.getMaxId()); iter = graph.getAllEdges(); iter.next(); EdgeIteratorState eState = iter.detach(false); assertEquals(iter.toString(), eState.toString()); iter.next(); assertNotEquals(iter.toString(), eState.toString()); EdgeIteratorState eState2 = iter.detach(true); assertEquals(iter.getAdjNode(), eState2.getBaseNode()); iter.next(); assertNotEquals(iter.getAdjNode(), eState2.getBaseNode()); }
@Test public void testSimpleDelete3() { graph = createGraph(); NodeAccess na = graph.getNodeAccess(); na.setNode(7, 7, 1); na.setNode(8, 8, 1); na.setNode(9, 9, 1); na.setNode(11, 11, 1); // mini subnetwork which gets completely removed: graph.edge(5, 10, 510, true); graph.markNodeRemoved(3); graph.markNodeRemoved(4); graph.markNodeRemoved(5); graph.markNodeRemoved(10); graph.edge(9, 11, 911, true); graph.edge(7, 9, 78, true); graph.edge(8, 9, 89, true); // perform deletion graph.optimize(); assertEquals(Arrays.<String>asList(), GHUtility.getProblems(graph)); assertEquals(3, GHUtility.count(carAllExplorer.setBaseNode(getIdOf(graph, 9)))); assertEquals(1, GHUtility.count(carAllExplorer.setBaseNode(getIdOf(graph, 7)))); assertEquals(1, GHUtility.count(carAllExplorer.setBaseNode(getIdOf(graph, 8)))); assertEquals(1, GHUtility.count(carAllExplorer.setBaseNode(getIdOf(graph, 11)))); }
@Test public void testDeleteNodeForUnidir() { graph = createGraph(); NodeAccess na = graph.getNodeAccess(); na.setNode(10, 10, 1); na.setNode(6, 6, 1); na.setNode(20, 20, 1); na.setNode(21, 21, 1); graph.edge(10, 20, 10, false); graph.edge(21, 6, 10, false); graph.markNodeRemoved(0); graph.markNodeRemoved(7); assertEquals(22, graph.getNodes()); graph.optimize(); assertEquals(20, graph.getNodes()); assertEquals(1, GHUtility.count(carInExplorer.setBaseNode(getIdOf(graph, 20)))); assertEquals(0, GHUtility.count(carOutExplorer.setBaseNode(getIdOf(graph, 20)))); assertEquals(1, GHUtility.count(carOutExplorer.setBaseNode(getIdOf(graph, 10)))); assertEquals(0, GHUtility.count(carInExplorer.setBaseNode(getIdOf(graph, 10)))); assertEquals(1, GHUtility.count(carInExplorer.setBaseNode(getIdOf(graph, 6)))); assertEquals(0, GHUtility.count(carOutExplorer.setBaseNode(getIdOf(graph, 6)))); assertEquals(1, GHUtility.count(carOutExplorer.setBaseNode(getIdOf(graph, 21)))); assertEquals(0, GHUtility.count(carInExplorer.setBaseNode(getIdOf(graph, 21)))); }
@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 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 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); }
@Test public void testEdgeProperties() { graph = createGraph(); EdgeIteratorState iter1 = graph.edge(0, 1, 10, true); EdgeIteratorState iter2 = graph.edge(0, 2, 20, true); int edgeId = iter1.getEdge(); EdgeIteratorState iter = graph.getEdgeProps(edgeId, 0); assertEquals(10, iter.getDistance(), 1e-5); edgeId = iter2.getEdge(); iter = graph.getEdgeProps(edgeId, 0); assertEquals(2, iter.getBaseNode()); assertEquals(0, iter.getAdjNode()); assertEquals(20, iter.getDistance(), 1e-5); iter = graph.getEdgeProps(edgeId, 2); assertEquals(0, iter.getBaseNode()); assertEquals(2, iter.getAdjNode()); assertEquals(20, iter.getDistance(), 1e-5); iter = graph.getEdgeProps(edgeId, Integer.MIN_VALUE); assertFalse(iter == null); assertEquals(0, iter.getBaseNode()); assertEquals(2, iter.getAdjNode()); iter = graph.getEdgeProps(edgeId, 1); assertTrue(iter == null); // delete graph.markNodeRemoved(1); graph.optimize(); // throw exception if accessing deleted edge try { graph.getEdgeProps(iter1.getEdge(), -1); assertTrue(false); } catch (Exception ex) { } }