private void checkNoShortcuts() { checkShortcuts(); }
@Test public void testContractNode_directed_shortcutRequired_reverse() { // 0 <-- 1 <-- 2 final EdgeIteratorState edge1 = graph.edge(2, 1, 1, false); final EdgeIteratorState edge2 = graph.edge(1, 0, 2, false); graph.freeze(); setMaxLevelOnAllNodes(); createNodeContractor().contractNode(1); checkShortcuts(expectedShortcut(0, 2, edge1, edge2, false, true)); }
@Test public void testContractNode_directed_shortcutRequired() { // 0 --> 1 --> 2 final EdgeIteratorState edge1 = graph.edge(0, 1, 1, false); final EdgeIteratorState edge2 = graph.edge(1, 2, 2, false); graph.freeze(); setMaxLevelOnAllNodes(); createNodeContractor().contractNode(1); checkShortcuts(expectedShortcut(0, 2, edge1, edge2, true, false)); }
@Test public void testContractNode_bidirected_shortcutsRequired() { // 0 -- 1 -- 2 final EdgeIteratorState edge1 = graph.edge(0, 1, 1, true); final EdgeIteratorState edge2 = graph.edge(1, 2, 2, true); graph.freeze(); setMaxLevelOnAllNodes(); createNodeContractor().contractNode(1); checkShortcuts(expectedShortcut(0, 2, edge2, edge1, true, true)); }
@Test public void testShortcutMergeBug() { // We refer to this real world situation http://www.openstreetmap.org/#map=19/52.71205/-1.77326 // assume the following graph: // // ---1---->----2-----3 // \--------/ // // where there are two roads from 1 to 2 and the directed road has a smaller weight // leading to two shortcuts sc1 (unidir) and sc2 (bidir) where the second should NOT be rejected due to the larger weight final EdgeIteratorState edge1to2bidirected = graph.edge(1, 2, 1, true); final EdgeIteratorState edge1to2directed = graph.edge(1, 2, 1, false); final EdgeIteratorState edge2to3 = graph.edge(2, 3, 1, true); graph.freeze(); setMaxLevelOnAllNodes(); NodeContractor nodeContractor = createNodeContractor(); nodeContractor.contractNode(2); checkShortcuts( expectedShortcut(1, 3, edge2to3, edge1to2bidirected, false, true), expectedShortcut(1, 3, edge1to2directed, edge2to3, true, false) ); }
@Test public void testDirectedGraph() { //5 6 7 // \|/ //4-3_1<-\ 10 // \_|/ // 0___2_11 graph.edge(0, 2, 2, true); graph.edge(10, 2, 2, true); graph.edge(11, 2, 2, true); // create a longer one directional edge => no longish one-dir shortcut should be created final EdgeIteratorState edge2to1bidirected = graph.edge(2, 1, 2, true); final EdgeIteratorState edge2to1directed = graph.edge(2, 1, 10, false); final EdgeIteratorState edge1to3 = graph.edge(1, 3, 2, true); graph.edge(3, 4, 2, true); graph.edge(3, 5, 2, true); graph.edge(3, 6, 2, true); graph.edge(3, 7, 2, true); graph.freeze(); setMaxLevelOnAllNodes(); // find all shortcuts if we contract node 1 NodeContractor nodeContractor = createNodeContractor(); nodeContractor.contractNode(1); checkShortcuts( expectedShortcut(2, 3, edge1to3, edge2to1bidirected, true, true), expectedShortcut(2, 3, edge2to1directed, edge1to3, true, false) ); }
Shortcut manualSc2 = expectedShortcut(4, 6, iter4to5, iter5to6, true, false); Shortcut manualSc3 = expectedShortcut(4, 6, iter6to8, iter8to4, false, true); checkShortcuts(manualSc1, manualSc2, manualSc3); checkShortcuts(manualSc1, manualSc2, manualSc3,