@Test
 public void testCLRS() {
   Object[][] data = {
     {"0", "1", 16},
     {"0", "2", 13},
     {"1", "2", 10},
     {"1", "3", 12},
     {"2", "1", 4},
     {"2", "4", 14},
     {"3", "2", 9},
     {"3", "5", 20},
     {"4", "3", 7},
     {"4", "5", 4}
   };
   Graph<String, CapacityEdge<String, Integer>> g = TestGraphFactory.createCapacityGraphNew(data);
   Assert.assertEquals(23, (int) algorithm.calc(g, "0", "5", NS2).calcTotalFlow());
 }
예제 #2
0
  @Test
  public void testTraverse() {
    String[][] data = {{"A", "B"}, {"B", "C"}, {"A", "C"}, {"B", "D"}};
    Graph<String, DirectedEdge<String>> g = TestGraphFactory.createDirectedNew(data);
    final DynamicArray<String> log = DynamicArray.create();
    BFS.traverse(
        g,
        VarargsIterable.create("A"),
        new BFSVisitor<String, DirectedEdge<String>>() {
          @Override
          public void onDiscover(String vertex, int depth, VisitorStopper stopper) {
            log.addToLast(vertex + "(" + depth + ")");
          }

          @Override
          public void onWalk(DirectedEdge<String> e) {
            log.addToLast(e.toString());
          }
        });
    assertEquals("(A(0),A->B,B(1),A->C,C(1),B->D,D(2))", log.toString());
  }