Ford-Fulkerson: Difference between revisions
Line 24: | Line 24: | ||
== Induction Step == | == Induction Step == | ||
'''Abstract view:''' Find a [[Basic flow definitions|flow-augmenting path]] and increase <math>f</math> along this path by the maximal value such that the flow value of each <math>a\in A</math> remains in the interval <math>[0,...,u(a)]</math>.<br> | '''Abstract view:''' Find a [[Basic flow definitions#Flow-aufmenting path|flow-augmenting path]] and increase <math>f</math> along this path by the maximal value such that the flow value of each <math>a\in A</math> remains in the interval <math>[0,...,u(a)]</math>.<br> | ||
'''Implementation:''' | '''Implementation:''' | ||
# Apply a graph traversal algorithm from <math>s</math> as follows: | # Apply a graph traversal algorithm from <math>s</math> as follows: | ||
## If <math>f(v,w)<c(v,w)</math>, <math>(v,w)\in A</math> can be used for going forward in the direction <math>v \rightarrow w</math>; | ## If <math>f(v,w)<c(v,w)</math>, <math>(v,w)\in A</math> can be used for going forward in the direction <math>v \rightarrow w</math>; | ||
## If <math>f(v,w)>0</math>, <math>(v,w)\in A</math> can be used for going forward in the direction <math> w\rightarrow v</math>; . | ## If <math>f(v,w)>0</math>, <math>(v,w)\in A</math> can be used for going forward in the direction <math> w\rightarrow v</math>; . | ||
# Terminate this graph traversal once either | # Terminate this graph traversal once either <math>t</math> is seen or all reachable nodes were seen (whatever occurs first). | ||
# In the latter case, the break condition | # In the latter case, the break condition applies and the loop is terminated. | ||
# Otherwise, | # Otherwise, | ||
## Let <math>p</math> denote the current path of the traversal (which is an <math>(s,t)</math>-path in this case) | ## Let <math>p</math> denote the current path of the traversal (which is an <math>(s,t)</math>-path in this case). | ||
## Let <math>x</math> denote the minimum of the values <math>c(a)-f(a)</math> on all forward arcs of <math>p</math> | ## Let <math>x</math> denote the minimum of the values <math>c(a)-f(a)</math> on all forward arcs of <math>p</math>. | ||
## Let <math>y</math> denote the minimum of the values <math>f(a)</math> on all backward arcs of <math>p</math>. | ## Let <math>y</math> denote the minimum of the values <math>f(a)</math> on all backward arcs of <math>p</math>. | ||
## For each arc <math>a \in A</math> on <math>p</math>, increase the flow value by <math>\min \{x,y \}</math> if <math>a</math> is a forward arc on <math>p</math>, otherwise, decrease the flow value by <math>\min \{x,y \}</math>. | ## For each arc <math>a \in A</math> on <math>p</math>, increase the flow value by <math>\min \{x,y \}</math> if <math>a</math> is a forward arc on <math>p</math>, otherwise, decrease the flow value by <math>\min \{x,y \}</math>. | ||
''' | '''Proof:''' If the graph traversal does not hit <math>t</math>, the break condition is fulfilled, so nothing is to show. So consider the case that the graph traversal does hit <math>t</math>. Then <math>p</math> is an <math>(s,t)</math>-path. By definition of <math>x</math> and <math>y</math>, the capacity constraints are preserved. To see that the flow conservation conditions are preserved as well, only the internal nodes of <math>p</math> are relevant. Let <math>v</math> be such an internal node, and let <math>u</math> and <math>w</math> denote the immediate predecessor and successor of <math>v</math> on <math>p</math>, respectively. Basically, there are four cases: | ||
*Either <math>(u,v)</math> is on <math>p</math> as a forward arc or <math>(v,u)</math> is on <math>p</math> as a backward arc. | *Either <math>(u,v)</math> is on <math>p</math> as a forward arc or <math>(v,u)</math> is on <math>p</math> as a backward arc. | ||
*Either <math>(v,w)</math> is on <math>p</math> as a forward arc or <math>(w,v)</math> is on <math>p</math> as a backward arc. | *Either <math>(v,w)</math> is on <math>p</math> as a forward arc or <math>(w,v)</math> is on <math>p</math> as a backward arc. |
Revision as of 08:56, 19 October 2014
General Information
Algorithmic problem: Max-flow problems (standard version)
Type of algorithm: loop
Abstract View
Invariant: After [math]\displaystyle{ i \ge 0 }[/math] iterations:
- The flow [math]\displaystyle{ f }[/math] is a fleasible flow.
- If all upper bounds are integral, [math]\displaystyle{ f }[/math] is integral as well.
Variant: The value of [math]\displaystyle{ f }[/math] increases.
Break condition: There is no flow-augumenting path.
Induction Basis
Abstract view: We start with some feasible flow, for example, the zero flow.
Implementation: Obvious.
Proof: Obvious.
Induction Step
Abstract view: Find a flow-augmenting path and increase [math]\displaystyle{ f }[/math] along this path by the maximal value such that the flow value of each [math]\displaystyle{ a\in A }[/math] remains in the interval [math]\displaystyle{ [0,...,u(a)] }[/math].
Implementation:
- Apply a graph traversal algorithm from [math]\displaystyle{ s }[/math] as follows:
- If [math]\displaystyle{ f(v,w)\lt c(v,w) }[/math], [math]\displaystyle{ (v,w)\in A }[/math] can be used for going forward in the direction [math]\displaystyle{ v \rightarrow w }[/math];
- If [math]\displaystyle{ f(v,w)\gt 0 }[/math], [math]\displaystyle{ (v,w)\in A }[/math] can be used for going forward in the direction [math]\displaystyle{ w\rightarrow v }[/math]; .
- Terminate this graph traversal once either [math]\displaystyle{ t }[/math] is seen or all reachable nodes were seen (whatever occurs first).
- In the latter case, the break condition applies and the loop is terminated.
- Otherwise,
- Let [math]\displaystyle{ p }[/math] denote the current path of the traversal (which is an [math]\displaystyle{ (s,t) }[/math]-path in this case).
- Let [math]\displaystyle{ x }[/math] denote the minimum of the values [math]\displaystyle{ c(a)-f(a) }[/math] on all forward arcs of [math]\displaystyle{ p }[/math].
- Let [math]\displaystyle{ y }[/math] denote the minimum of the values [math]\displaystyle{ f(a) }[/math] on all backward arcs of [math]\displaystyle{ p }[/math].
- For each arc [math]\displaystyle{ a \in A }[/math] on [math]\displaystyle{ p }[/math], increase the flow value by [math]\displaystyle{ \min \{x,y \} }[/math] if [math]\displaystyle{ a }[/math] is a forward arc on [math]\displaystyle{ p }[/math], otherwise, decrease the flow value by [math]\displaystyle{ \min \{x,y \} }[/math].
Proof: If the graph traversal does not hit [math]\displaystyle{ t }[/math], the break condition is fulfilled, so nothing is to show. So consider the case that the graph traversal does hit [math]\displaystyle{ t }[/math]. Then [math]\displaystyle{ p }[/math] is an [math]\displaystyle{ (s,t) }[/math]-path. By definition of [math]\displaystyle{ x }[/math] and [math]\displaystyle{ y }[/math], the capacity constraints are preserved. To see that the flow conservation conditions are preserved as well, only the internal nodes of [math]\displaystyle{ p }[/math] are relevant. Let [math]\displaystyle{ v }[/math] be such an internal node, and let [math]\displaystyle{ u }[/math] and [math]\displaystyle{ w }[/math] denote the immediate predecessor and successor of [math]\displaystyle{ v }[/math] on [math]\displaystyle{ p }[/math], respectively. Basically, there are four cases:
- Either [math]\displaystyle{ (u,v) }[/math] is on [math]\displaystyle{ p }[/math] as a forward arc or [math]\displaystyle{ (v,u) }[/math] is on [math]\displaystyle{ p }[/math] as a backward arc.
- Either [math]\displaystyle{ (v,w) }[/math] is on [math]\displaystyle{ p }[/math] as a forward arc or [math]\displaystyle{ (w,v) }[/math] is on [math]\displaystyle{ p }[/math] as a backward arc.
It is easy to check preservation of the flow conservation conditions for each of these four cases.
Pseudocode
FORD-FULKERSON(G,s,t)
1 for each edge (u,v) ∈ G.E
2 (u,v).f = 0
3 while there exists a path p from s to t in the residual Network Gf
4 cf(p) = min{cf(u,v) : (u,v) is in p}
5 for each each edge (u,v) in p
6 if (u,v) ∈ E
7 (u,v).f = (v,u).f + cf(p)
8 else (v,u).f = (v,u).f - cf(p)
Complexity
Statement: If all capacity values are integral, the asymptotic worst-case complexity is [math]\displaystyle{ \mathcal{O} (m\cdot F) }[/math], where [math]\displaystyle{ m = |A| }[/math] and [math]\displaystyle{ F }[/math] is the maximum total flow value.
Proof: A graph search from [math]\displaystyle{ s }[/math] requires [math]\displaystyle{ \Omicron (m) }[/math] . Obviously, determining [math]\displaystyle{ x }[/math] and [math]\displaystyle{ y }[/math] and changing the flow values along [math]\displaystyle{ p }[/math] requires [math]\displaystyle{ \mathcal{O}(m) }[/math] as well. It is also evident that, after iterations, the flow values on all arcs are integral. In particular, the total flow value is integral. The variant implies that, in case of integral capacity values, the total flow value increases by at least one unit in every iteration. Since the total flow value is always in the interval [math]\displaystyle{ [0...F] }[/math], this may happen at most [math]\displaystyle{ F }[/math] times.