Proofs: Ford-Fulkerson algorithm
These are the human proofs of Ford-Fulkerson algorithm, at full length.
Ford-Fulkerson returns a maximum flow and a minimum cut full
This proof shows: correctness, termination.
Let be a flow network with , and . For each edge the algorithm keeps two residual capacities: on the arc and on the arc . The residual graph has the arcs with positive residual capacity. We write , , and .
Invariant (I). Before each test of line L2:
- , and for each edge ;
- satisfies flow conservation at each ;
- if all capacities are integers, all residual capacities are integers.
Part 1 says , so with part 2, is an s-t flow.
Initialization. Line L1 sets and . Part 1 holds, conserves at every vertex, and the values are integers when is.
Maintenance. Let be the arcs of the path found in line L2, from to , and (line L3). We may take simple: a depth-first search enters each vertex at most once, so the arcs on its current path form a simple path. Then uses at most one of for each edge , because using both would visit and in both orders.
Part 1. Lines L5 and L6 lower by and raise the reverse arc by . For an edge whose arc is on , the sum does not change, and the lowered arc stays since . Arcs of other edges do not change.
Part 2. If , then rises by ; if , then falls by . Fix on ; it is the head of and the tail of for one index , since is simple. The arc enters in : either for an edge into (flow in rises by ) or for an edge out of (flow out falls by ). Both raise the excess by . In the same way leaves , and either raises the flow on an edge out of or lowers the flow on an edge into ; both lower the excess by . So the excess of stays 0. A vertex not on is touched by no arc.
Part 3. is the minimum of integers, so it is an integer, and lines L5 and L6 keep all values integral.
The value. The arc leaves and no later arc enters or leaves , since is simple. So either raises the flow on an edge out of or lowers the flow on an edge into , and rises by exactly .
Termination with integer capacities. By part 3, each , so each round raises by at least 1. For any s-t flow and the cut , , a finite integer bound. So the loop runs at most times, where is the maximum flow value (the value after the last round is at most and it starts at 0). The same argument with capacities scaled by a common denominator covers rational capacities.
The result is optimal. Suppose line L2 finds no path. Let be the set of line L7, the vertices reachable from in . Then and , so is an s-t cut.
- For an edge with and : if , the arc would make reachable. So and .
- For an edge with and : if , the arc would make reachable. So .
Summing the excess over : the excess is 0 for and for ; each edge inside cancels, so . With the two facts above, .
For any s-t flow and any s-t cut , the same sum gives . Applied to and : , so is a maximum flow. Applied to and any cut : , so is a minimum cut. Line L8 returns and .
Remark. The optimality part does not use integrality. So whenever the loop stops, for any capacities, the answer is correct; only termination needs integer or rational capacities, or a rule for choosing such as shortest paths.