Пример #1
0
  public static void maxFlow(ListGraph g) {
    ListGraph residualG = g.residualGraph();

    LinkedList<DirEdge> path = residualG.getFlowPath();
    while (path != null) {
      // System.out.println("Got path");
      int minCapacity = ListGraph.minCapacityInPath(path);

      assert minCapacity > 0;
      // augment every edge on the path in the original graph
      int head = g.getSource();
      ListIterator it = path.listIterator();
      while (it.hasNext()) {
        DirEdge rEdge = (DirEdge) it.next();
        int tail = rEdge.end;

        DirEdge e = g.getEdge(head, tail);
        e.flow += minCapacity;

        // System.out.println("Augmenting (" + head + "," + tail + ") to be " + e.flow);

        head = tail;
      }

      residualG = g.residualGraph();

      // System.out.println("g:");
      // g.print();

      // System.out.println("Residual graph:");
      // residualG.print();

      path = residualG.getFlowPath();
    }
  }