The Max-Flow problem. Ford-Fulkerson Algorithm

The Max-Flow problem. Ford-Fulkerson Algorithm
Jesús Omar Ocegueda González
Abstract— In this homework I introduce the Max-Flow problem
as an LP problem and deduce the Ford-Fulkerson’s Augmented
Path algorithm from the construction of the Dual of the Restricted
Primal. Finally I show a simple strategy to implement the FordFulkerson Algorithm and show some experimental results.
I. T HE P RIMAL - D UAL A LGORITHM
C
ONSIDER the standard Linear Programming problem
biven by
min cT x
subject to
Âx̂ + xa = b
x̂ ≥ 0
xa ≥ 0
where e is the vector whose components are 1’s. We can write
this problem in standard form by defining
h
i
0
x̂
c=
,x =
, A = Â, I
a
e
x
then the problem is in standard form:
min cT x
subject to
subject to
Ax ≥ b
x≥0
Ax = b
x≥0
max π T b
and its dual problem, known as the Dual of the Restricted
Primal (DRP) is
max π T b
its dual form is given by
subject to
subject to
T
A π≤c
it is easy to see that the K.K.T. conditions are identical. Given
two feaseible points x, π for the primal and dual problems,
respectively, the only condition they need to be optimal is the
complementarity condition of the dual KKT conditions
AT π ≤ c
this condition is equivalent to
ÂT π ≤ 0
π≤e
(cj − π Aj )xj = 0
This expression has an useful interpretation in the case of
Max-Flow problem as we will see in the next section.
Now, given a feasible π some of the conditions π T Aj ≤ cj
will be satisfied strictly. Define J as the index set
The Primal-Dual method consists on iterate between the
primal and dual problems maintaining π feasible.
J = j : π T Aj = cj
II. T HE M AX -F LOW PROBLEM
T
if k ∈
/ J then the complementarity condition tells us that xk
must be zero. The other xi ’s are “free variables”. These “free
variables” in the dual problem are not “free” in the primal
problem because of the restrictions Ax = b. Define the new
matrix  as the matrix A without the columns that correspond
to the indexes that are not in J, that is, Â = [Aj ]j∈J , and set
x̂ == [xj ]j∈J , xi = 0, i ∈
/ J. If it were possible to find a
solution to
Âx̂ = b
x̂ ≥ 0
the KKT will be satisfied (note that the vector b does not
change). The problem is that the system above may have no
solution, then instead of looking for an exact solution we
formulate the Restricted Primal problem as
min eT xa
A Flow Network N is a weighted graph with two special
nodes denoted by {s, t}, N = (s, t, V, E, b) where V is the set
of vertices, E is the set of edges and b is the set of edge-costs,
these costs represent the capacities of each edge. Figure (1)
shows a Flow Network in the case in which the edges are
directed.
The Max-Flow problem is defined as maximize the flow
from s to t without overflow the capacities of the edges.
We can write the Max-Flow problem in the form of a Linear
Programming problem by constructing the Incidence matrix of
the graph G = (V, E, b), which is defined by

 1 if the j-th edge is (i, x), x ∈ N
−1 if the j-th edge is (x, i), x ∈ N
A = ai,j =

0 otherwise
III. I MPLEMENTATION
Fig. 1.
An easy way to implement the Ford-Fulkerson algorithm is
by using Breadth First Search for graphs. A feasible starting
flow is zero. Given a flow we can mark the valid edges with
the conditions given above. Then we find a path from s to t
using only valid edges, if such a path does not exist then we
are done, otherwise we determine the maximum amount of
flow that can be transported through the path. We iterate in
this way until no augmented path can be found.
Flow Network.
clearly, the matrix A depends on the way we numerate the
nodes and edges. A is a n×m matrix, where n = |V |, m = |E|.
The Max-Flow problem can be written as:
max v
subject to f ≥ 0, f ≤ b

 v
−v
Af =

0
Row s
Row t
other
now, defining the vector d by

 −1 i = s
1 i=t
di =

0 otherwise
IV. E XPERIMENTAL RESULTS
I implemented the Ford-Fulkerson algorithm for graphs
in general, this is not the most efficient way to implement
the algorithm for these experiments but it is useful for other
problems.
The problem to solve is to find the Max-Flow for the graph
defined by a binary image with additive noise. We construct the
graph taking as nodes the pixels of the image, the edge weights
are defined as
wr,s =
+ (f (r) − f (s))2
where f is the normalized image. To this graph we add the
our problem becomes
max v
subject to
Af + dv ≤ 0
f ≤b
−f ≤ 0
Following the steps of the previous section we obtain the
expression of the DRP for this problem:
max v
subject to
Af + dv ≤ 0
f ≤0
f orrowswheref = b
−f ≤ 0
f orrowswheref = 0
f ≤1
v≤1
a solution f ∗ represents a path from s to t that uses only
saturated arcs in the backward direction or zero flow edges in
the forward direction or other arcs in either direction. This path
is known as Augmented path in the Ford-Fulkerson algorithm
that consists on finding an augmented path given an initial flow
and augment the flow using such a path until the maximum
amount of flow that can be augmented is zero.
Fig. 2.
Graph defined by an image.
nodes s and t as pixels of value f (s) = 1, f (t) = 0. Given
this deffinition, we are ready to proceede.
We are interested on the edges from s that are saturated, we
saw that these edges are related with the cut of minimum cost
to separate the nodes into two clases. In the following figures I
show the original image that was perturbed with gaussian noise
of different variances. In each experiment I show the edges from
s to the pixels that were saturated (white pixels in the first
image) and the edges from the pixels to t that were saturated
(white pixels in the second image). Black pixels indicate that
those edges were not saturated.
V. C ONCLUSION
I introduced the Primal-Dual algorithm and applied it to
the Max-Flow problem. The interpretation of the Dual of the
Restricted Primal gave us the key idea of the Ford-Fulkerson
algorithm that consists on iteratively find augmented paths.
This augmented paths were found using Breadth First Search
algorithm for graphs in which the valid edges were selected in
Fig. 3.
σ = 0.1. = 0.1.
Fig. 4.
σ = 0.3. = 0.1.
base of the constraints of the DRP. The final implementation is
not the most effitient one but is general enough to be applied
to any (small enough) graph. The experiments were done over
images of 50 × 50 pixels with run time of around 2 seconds
(too slow!!).
I found in the literature that the Ford-Fulkerson algorithm
is the most simple one, other methods should have a better
performance. My conclusion is that the deduction of the
method is difficult to understand and the Ford-Fulkerson
algorithm can be deduced without using Linear Programming
arguments. I think that this method is not a good choice to
solve the segmentation problem but the interesting think of
studing it are the theoretical results that could lead us to
interesting optimizations methods. Finally, even if the method
does not work well for segmentation, in fact it solves the
Max-Flow problem.
ACKNOWLEDGMENT
I would like to thank Tere for help me to understand the
relationship between the lagrange multipliers of the Max-Flow
problem and the segmentation of the image...
Fig. 5.
σ = 0.3. = 0.9.