Proofs: Cost scaling min-cost flow algorithm
These are the human proofs of Cost scaling min-cost flow algorithm, at full length.
Cost scaling returns a maximum flow of least cost full
This proof shows: correctness, termination.
Let have integer capacities and integer costs . Self-loops are set aside at the start: a self-loop is full if its cost is negative and empty otherwise, which is optimal for it alone, and since a self-loop does not change any balance, this choice is independent of the rest. All arcs below are arcs of edges that are not self-loops. Costs are multiplied by ; we write for the scaled costs. For potentials , the reduced cost of a residual arc is , and for the reverse arc . A pseudoflow is -optimal for if every residual arc has .
Line L1. Edmonds-Karp returns a maximum s-t flow of value ; see the page on Edmonds-Karp. From then on, for a pseudoflow let be the net flow into under minus that under the flow at the start of the current refine. Every push moves an amount from the excess of one vertex to another, so the sum of excesses is 0.
Invariant. At the start of each refine, satisfies the capacity bounds, conserves flow at every vertex other than , , has value , and is -optimal for the current , where is the value set by line L4. Before the first refine, and every residual arc has , and the first satisfies . Later refines start from the result of the previous refine with , which is -optimal by Claim 1 below, and .
Claim 1 (-optimality is kept within refine). After line L5, every residual arc has : an arc with was saturated and left the residual graph, and its reverse has . A push in line L8 is along an admissible arc , ; it may add to the residual graph, with . A relabel in line L9 happens when has no admissible arc, so every residual arc has , that is . The new value gives every residual arc out of a reduced cost at least , with equality for the maximizer, and . Lowering raises the reduced costs of arcs into . The maximum exists: see Claim 2. So the pseudoflow stays -optimal.
Claim 2 (paths to a deficit). Let be the flow at the start of the refine and the current pseudoflow. If , there is a vertex with and a path from to in whose reversed path lies in . Proof. Let as a function on edges. Where , the forward arc of is residual for (as ) and the backward arc is residual for ; where , the backward arc of is residual for and the forward arc for . Orient each edge with in the direction in which is positive, as an arc of . The net outflow of at each vertex is . Decompose into paths and cycles: a path starts at a vertex of positive and ends at one of negative . Since , some path starts at . In particular an active vertex has a residual arc, so the maximum in line L9 is over a nonempty set.
Claim 3 (relabel bound). During a refine with , each potential drops by at most in total. Proof. A vertex is relabeled only while active, and a vertex never pushes more than its excess, so a vertex with was never active in this refine and still has its potential from the start. For the path of Claim 2 from to such a , -optimality gives , and -optimality of for along the reversed path gives . Adding, with : .
Termination of refine. By Claim 1 each relabel lowers by at least , so by Claim 3 each vertex is relabeled at most times. Between two relabels of , an arc out of that a push saturates becomes residual again only after a push along , which needs , so must be relabeled in between; this bounds saturating pushes by . The admissible graph stays acyclic: after line L5 it is empty, a push adds no admissible arc, and a relabel of makes every arc into have , so it creates no cycle through . Let be the sum, over active vertices , of the number of vertices reachable from in the admissible graph. A non-saturating push along makes inactive and may make active, and reaches fewer vertices than by acyclicity, so drops by at least 1. Relabels and saturating pushes raise by at most each, so there are non-saturating pushes. So line L6 stops after finitely many steps, with no active vertex. Since excesses sum to 0 and none is positive, all are 0.
After refine. All excesses are 0, so has the same net flow at every vertex as : it conserves flow at every vertex other than , and has value . Every push respects residual capacities, so . By Claim 1, is -optimal, which is -optimal for the next . So the invariant holds at the next refine.
Termination of the outer loop. While , , so reaches 1 after finitely many refines, and line L10 stops after the refine with .
Optimality. At the end is a maximum flow and 1-optimal for the scaled costs. Let be a cycle of with arcs. The potentials cancel around a cycle, so its scaled cost is . Its scaled cost is times its original cost, an integer, so the original cost is at least , hence at least 0. So has no negative cycle. Any other maximum flow differs from by a circulation in , which splits into cycles of , each of nonnegative cost; so costs at least as much as . With the self-loops set as above, is a maximum flow of least cost.