Negative cycle-canceling

From Algowiki
Revision as of 18:49, 22 October 2014 by Weihe (talk | contribs) (→‎Correctness)
Jump to navigation Jump to search

Abstract view

Algorithmic problem: Min-cost flow problem

Type of algorithm: loop

Invariant: The flow is feasible.

Variant: The cost of the flow decreases.

Definition: A cycle is negative if the sum of the cost values on all of its arcs is negative.

Break condition: There is no more negative cycle in the residual network.

Induction basis

Abstract view: Start with an arbitrary feasible flow, for example, the zero flow.

Induction step

Abstract view:

  1. Find a cycle of negative cost in the residual network.
  2. Augment the flow on all arcs of this cycle by the minmum residual capacity of all arcs on this cycle.

Implementation:

  1. Run an all-pairs shortest-paths algorithm on the residual network, where the length of an arc [math]\displaystyle{ (v,w)in A }[/math] is defined as the minimum of [math]\displaystyle{ c(v,w) }[/math] and [math]\displaystyle{ -c(w,v) }[/math]. The number of all
  2. If the distance [math]\displaystyle{ v\rightarrow v }[/math] is 0 for all [math]\displaystyle{ v\in V }[/math], the break condition applies.
  3. Otherwise (that is, the distances [math]\displaystyle{ v\rightarrow v }[/math] of some nodes [math]\displaystyle{ v\in V }[/math] are negative):
    1. Reconstruct one negative cycle [math]\displaystyle{ C }[/math] from the output of step 1.
    2. Augment the flow on all arcs of [math]\displaystyle{ C }[/math] (in the [Basic flow definitions#Residual network|residual network]]) by the minimum residual capacity of all arcs of [math]\displaystyle{ C }[/math].

Proof: The invariant and the variant are obviously fulfilled.

Correctness

First we will show a general fact: For two feasible flows, [math]\displaystyle{ f_1 }[/math] and [math]\displaystyle{ f_2 }[/math], there are generalized cycles [math]\displaystyle{ C_1,\ldots,C_k }[/math] in [math]\displaystyle{ G }[/math] and [math]\displaystyle{ \varepsilon_1,\ldots,\varepsilon_k }[/math] such that:

  1. Decomposition of [math]\displaystyle{ f_2-f_1 }[/math]: It is [math]\displaystyle{ f_2=f_1+\varepsilon_1\cdot C_1+\cdots+\varepsilon_k\cdot C_k }[/math].
  2. Consistency: For each arc [math]\displaystyle{ a\in A }[/math] and [math]\displaystyle{ i,j\in\{1,\ldots,k\} }[/math]: If [math]\displaystyle{ a }[/math] belongs to [math]\displaystyle{ C_i }[/math] and [math]\displaystyle{ C_j }[/math], then [math]\displaystyle{ a }[/math] is a forward arc on both cycles, or [math]\displaystyle{ a }[/math] is a backward arc in both cycles.

To prove that, we apply an induction on the number [math]\displaystyle{ d }[/math] of arcs on which [math]\displaystyle{ f_1 }[/math] and [math]\displaystyle{ f_2 }[/math] differ. For [math]\displaystyle{ d=0 }[/math], nothing is to show. So suppose [math]\displaystyle{ d\gt 0 }[/math]. Let [math]\displaystyle{ (v_1,v_2) }[/math] be an arc on which [math]\displaystyle{ f_1 }[/math] and [math]\displaystyle{ f_2 }[/math] differ, say [math]\displaystyle{ f_1(v_1,v_2)\lt f_2(v_1,v_2) }[/math]. Then there is either an arc [math]\displaystyle{ (v_2,v_3) }[/math] with [math]\displaystyle{ f_1(v_2,v_3)\lt f_2(v_2,v_3) }[/math] or [math]\displaystyle{ (v_3,v_2) }[/math] with [math]\displaystyle{ f_1(v_3,v_2)\gt f_2(v_3,v_2) }[/math].

We have to show that a feasible flow is minimum if it admits no negative cycle. So assume a feasible flow [math]\displaystyle{ f }[/math] is not minimum. Then there is a feasible flow [math]\displaystyle{ \tilde{f} }[/math] such that [math]\displaystyle{ c\tilde{f})\lt c(f) }[/math]. There are [math]\displaystyle{ C_1,\ldots,C_k }[/math] and [math]\displaystyle{ \varepsilon_1,\ldots,\varepsilon_k }[/math] as described above. Since [math]\displaystyle{ c(\tilde{f})\lt c(f) }[/math], at least one of the cycles must be a negative one,say [math]\displaystyle{ C_i }[/math]. It is easy to see that the cycles may be permuted in the decomposition, so [math]\displaystyle{ f+\varepsilon_i\cdot C_i }[/math] is feasible (consistenc< is essential for that). This proves the claim.