Algorithm Search⌘K

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 NN have integer capacities c≥0c \ge 0 and integer costs ww. 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 n+1n + 1; we write ww for the scaled costs. For potentials pp, the reduced cost of a residual arc x=(v,u)x = (v, u) is cp(x)=w(x)+p(v)−p(u)c_p(x) = w(x) + p(v) - p(u), and w(xˉ)=−w(x)w(\bar x) = -w(x) for the reverse arc xˉ\bar x. A pseudoflow is ε\varepsilon-optimal for pp if every residual arc has cp≥−εc_p \ge -\varepsilon.

Line L1. Edmonds-Karp returns a maximum s-t flow f∗f^* of value FF; see the page on Edmonds-Karp. From then on, for a pseudoflow ff let ef(v)e_f(v) be the net flow into vv under ff 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, ff satisfies the capacity bounds, conserves flow at every vertex other than ss, tt, has value FF, and is 2ε2\varepsilon-optimal for the current pp, where ε\varepsilon is the value set by line L4. Before the first refine, p=0p = 0 and every residual arc has cp(x)=w(x)≥−max⁡∣w∣c_p(x) = w(x) \ge -\max|w|, and the first ε=⌈max⁡∣w∣/2⌉\varepsilon = \lceil \max|w| / 2 \rceil satisfies 2ε≥max⁡∣w∣2\varepsilon \ge \max|w|. Later refines start from the result of the previous refine with εold\varepsilon_{\text{old}}, which is εold\varepsilon_{\text{old}}-optimal by Claim 1 below, and 2⌈εold/2⌉≥εold2 \lceil \varepsilon_{\text{old}}/2 \rceil \ge \varepsilon_{\text{old}}.

Claim 1 (ε\varepsilon-optimality is kept within refine). After line L5, every residual arc has cp≥0c_p \ge 0: an arc with cp<0c_p < 0 was saturated and left the residual graph, and its reverse has cp>0c_p > 0. A push in line L8 is along an admissible arc xx, cp(x)<0c_p(x) < 0; it may add xˉ\bar x to the residual graph, with cp(xˉ)=−cp(x)>0c_p(\bar x) = -c_p(x) > 0. A relabel in line L9 happens when vv has no admissible arc, so every residual arc x=(v,u)x = (v, u) has cp(x)≥0c_p(x) \ge 0, that is p(v)≥p(u)−w(x)p(v) \ge p(u) - w(x). The new value p′(v)=max⁡x(p(u)−w(x))−εp'(v) = \max_x (p(u) - w(x)) - \varepsilon gives every residual arc out of vv a reduced cost at least −ε-\varepsilon, with equality for the maximizer, and p′(v)≤p(v)−εp'(v) \le p(v) - \varepsilon. Lowering p(v)p(v) raises the reduced costs of arcs into vv. The maximum exists: see Claim 2. So the pseudoflow stays ε\varepsilon-optimal.

Claim 2 (paths to a deficit). Let f0f_0 be the flow at the start of the refine and ff the current pseudoflow. If ef(v)>0e_f(v) > 0, there is a vertex uu with ef(u)<0e_f(u) < 0 and a path from vv to uu in GfG_f whose reversed path lies in Gf0G_{f_0}. Proof. Let g=f0−fg = f_0 - f as a function on edges. Where g(e)>0g(e) > 0, the forward arc of ee is residual for ff (as f(e)<f0(e)≤c(e)f(e) < f_0(e) \le c(e)) and the backward arc is residual for f0f_0; where g(e)<0g(e) < 0, the backward arc of ee is residual for ff and the forward arc for f0f_0. Orient each edge with g(e)≠0g(e) \ne 0 in the direction in which gg is positive, as an arc of GfG_f. The net outflow of gg at each vertex xx is ef(x)e_f(x). Decompose gg into paths and cycles: a path starts at a vertex of positive efe_f and ends at one of negative efe_f. Since ef(v)>0e_f(v) > 0, some path starts at vv. □\square 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 ε\varepsilon, each potential drops by at most 3(n−1)ε3(n - 1)\varepsilon in total. Proof. A vertex is relabeled only while active, and a vertex never pushes more than its excess, so a vertex with ef(u)<0e_f(u) < 0 was never active in this refine and still has its potential p0(u)p_0(u) from the start. For the path PP of Claim 2 from vv to such a uu, ε\varepsilon-optimality gives w(P)+p(v)−p(u)≥−(n−1)εw(P) + p(v) - p(u) \ge -(n - 1)\varepsilon, and 2ε2\varepsilon-optimality of f0f_0 for p0p_0 along the reversed path gives −w(P)+p0(u)−p0(v)≥−2(n−1)ε-w(P) + p_0(u) - p_0(v) \ge -2(n - 1)\varepsilon. Adding, with p(u)=p0(u)p(u) = p_0(u): p0(v)−p(v)≤3(n−1)εp_0(v) - p(v) \le 3(n - 1)\varepsilon. □\square

Termination of refine. By Claim 1 each relabel lowers p(v)p(v) by at least ε\varepsilon, so by Claim 3 each vertex is relabeled at most 3(n−1)3(n - 1) times. Between two relabels of vv, an arc xx out of vv that a push saturates becomes residual again only after a push along xˉ\bar x, which needs cp(xˉ)<0c_p(\bar x) < 0, so uu must be relabeled in between; this bounds saturating pushes by O(nm)O(nm). The admissible graph stays acyclic: after line L5 it is empty, a push adds no admissible arc, and a relabel of vv makes every arc into vv have cp≥0c_p \ge 0, so it creates no cycle through vv. Let Φ\Phi be the sum, over active vertices xx, of the number of vertices reachable from xx in the admissible graph. A non-saturating push along (v,u)(v, u) makes vv inactive and may make uu active, and uu reaches fewer vertices than vv by acyclicity, so Φ\Phi drops by at least 1. Relabels and saturating pushes raise Φ\Phi by at most nn each, so there are O(n⋅n2+n⋅nm)=O(n2m)O(n \cdot n^2 + n \cdot nm) = O(n^2 m) 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 ff has the same net flow at every vertex as f0f_0: it conserves flow at every vertex other than ss, tt and has value FF. Every push respects residual capacities, so 0≤f≤c0 \le f \le c. By Claim 1, ff is ε\varepsilon-optimal, which is 2ε′2\varepsilon'-optimal for the next ε′=⌈ε/2⌉\varepsilon' = \lceil \varepsilon / 2 \rceil. So the invariant holds at the next refine.

Termination of the outer loop. While ε>1\varepsilon > 1, ⌈ε/2⌉<ε\lceil \varepsilon / 2 \rceil < \varepsilon, so ε\varepsilon reaches 1 after finitely many refines, and line L10 stops after the refine with ε=1\varepsilon = 1.

Optimality. At the end ff is a maximum flow and 1-optimal for the scaled costs. Let ZZ be a cycle of GfG_f with k≤nk \le n arcs. The potentials cancel around a cycle, so its scaled cost is ∑x∈Zcp(x)≥−k≥−n\sum_{x \in Z} c_p(x) \ge -k \ge -n. Its scaled cost is n+1n + 1 times its original cost, an integer, so the original cost is at least −n/(n+1)>−1-n/(n + 1) > -1, hence at least 0. So GfG_f has no negative cycle. Any other maximum flow gg differs from ff by a circulation g−fg - f in GfG_f, which splits into cycles of GfG_f, each of nonnegative cost; so gg costs at least as much as ff. With the self-loops set as above, ff is a maximum flow of least cost. ■\blacksquare

Back to Cost scaling min-cost flow algorithm