0% found this document useful (0 votes)
4 views

Lecture 16

The document discusses the max flow problem in directed graphs, focusing on finding the maximum flow from a source node s to a sink node t while adhering to edge capacities. It introduces the concepts of flow, cuts, and the max flow/min cut theorem, which states that the value of the max flow equals the size of the min cut. The Ford Fulkerson method is presented as a technique to compute the maximum flow, utilizing residual networks and path augmentation until no more paths exist from s to t.

Uploaded by

Valy Valy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lecture 16

The document discusses the max flow problem in directed graphs, focusing on finding the maximum flow from a source node s to a sink node t while adhering to edge capacities. It introduces the concepts of flow, cuts, and the max flow/min cut theorem, which states that the value of the max flow equals the size of the min cut. The Ford Fulkerson method is presented as a technique to compute the maximum flow, utilizing residual networks and path augmentation until no more paths exist from s to t.

Uploaded by

Valy Valy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Lecture 16 – Max Flow Jessica Su (some parts copied from CLRS / last quarter’s notes)

1 Max flow
Consider a directed graph G with positive edge weights c that define the “capacity” of each
edge. We can identify two special nodes in G: the source node s and the sink node t. We
want to find a max flow from s to t (we will explain what that is in a bit).
Real-life example: Suppose we want to send trucks from city s to city t, and the capacity
of each edge represents the number of trucks that can go on that road every hour. What is
the maximum number of trucks that we can send from s to t every hour?

1.0.1 Formal definition of flow

A flow f is a function defined on the edges of a graph, where


1. For all edges, the flow on that edge is at least 0, and no greater than the capacity of
the edge. That is, 0 ≤ f (u, v) ≤ c(u, v) for all edges (u, v).
2. For all vertices (other than s and t), the flow into the vertex has to equal the flow out
of the vertex. That is, X X
f (x, v) = f (v, y)
x∈Nin (v) y∈Nout (v)

where Nin is the set of nodes that have edges pointing to v, and Nout is the set of nodes
that v points to.
In the truck example, this means that we cannot have any more trucks on a road than the
road can hold, and the number of trucks going into a city has to equal the number of trucks
coming out of the city (which makes sense because otherwise the city would run out of trucks
or the trucks would build up).

1
Lecture 16 – Max Flow Jessica Su (some parts copied from CLRS / last quarter’s notes)

The value |f | of the flow is defined as the total flow coming out of the source (which is the
same as the total flow coming into the sink). That is,
X X
|f | = f (s, x) − f (y, s)
x∈Nout (s) y∈Nin (s)

In the max-flow problem, our goal is to find the flow with the maximum value. That is, we
want to find the best way to send trucks from s to t.

2 Max flow / min cut


An s-t cut is a partition of the vertices into two disjoint sets S and T , such that s ∈ S and
t ∈ T . The size (or cost) of the cut is the sum of the capacities of the edges:
X
||S, T || = c(x, y)
x∈S,y∈T

Note that when computing the size of a cut, we only consider edges going from S to T , not
the other way around.
The min s-t cut is the s-t cut with the smallest size.

2.1 Max flow min cut lemma

Theorem: For any graph G, source s, and destination t, the value of the max flow is equal
to the size of the min cut.
First we will prove that the value of the max flow is less than or equal to the size of the min
cut. Then we will find an algorithm that finds a flow whose value is equal to the size of the
min cut, proving the theorem.

2
Lecture 16 – Max Flow Jessica Su (some parts copied from CLRS / last quarter’s notes)

Lemma: For any flow f and any s-t cut (S, T ), we have |f | ≤ ||S, T ||. (This proves that
the value of the max flow is less than or equal to the size of the min cut.)
Proof: By definition, we have
X X
|f | = f (s, x) − f (y, s)
x∈Nout (s) y∈Nin (s)

To simplify this expression, we can add a bunch of extraneous terms that sum to zero, to
get  
X X X
 f (v, x) − f (y, v)
v∈S x∈Nout (v) y∈Nin (v)

Now we can separate out vertices in S and T , getting


   
X X X X X X
 f (v, x) − f (y, v) +  f (v, x) − f (y, v)
v∈S x∈Nout (v)∩S y∈Nin (v)∩S v∈S x∈Nout (v)∩T y∈Nin (v)∩T

Observe that the first two sums cancel out, because we are summing over all vertices in S,
and each edgePfromPa vertex in S to another vertex in S is represented
P P exactly twice: once
in the term v∈S x∈Nout (v)∩S f (v, x), and once in the term v∈S x∈Nin (v)∩S f (y, v). So
this actually just equals
 
X X X
 f (v, x) − f (y, v)
v∈S x∈Nout (v)∩T y∈Nin (v)∩T

which is less than or equal to X


f (v, x)
v∈S,x∈Nout (v)∩T

which is less than or equal to


X
c(v, x) = ||S, T ||
v∈S,x∈Nout (v)∩T

3 Ford Fulkerson
This is the method we will use to find a flow whose value equals the value of a cut (i.e. the
max flow). Key to this method is the notion of a “residual graph”, which is based on the
flow that is currently going through the graph, and says how much more flow can be pushed
through the graph on each edge.

3
Lecture 16 – Max Flow Jessica Su (some parts copied from CLRS / last quarter’s notes)

3.1 Residual networks

Specifically, the residual network Gf is defined as follows:


Assume that our graph does not have edges pointing in opposite directions between the same
two vertices. That is, if (u, v) is an edge, (v, u) must not be an edge. (If (u, v) and (v, u) are
both edges, we can split the edge (u, v) by introducing a new node x, and replacing (u, v)
with edges (u, x) and (x, v). This makes the number of nodes at most m + n.)

Let the residual capacity cf be defined on each edge as



c(u, v) − f (u, v) if (u, v) is an edge in the original graph

cf (u, v) = f (v, u) if (v, u) is an edge in the original graph

0 otherwise

The logic behind this definition is that if u → v is an edge in the original graph, and
we are only pushing f (u, v) units of flow through it right now, we can potentially push
c(u, v) − f (u, v) more units through that edge. However, if the edge points from v → u, we
can push f (u, v) more units in the u → v direction by just removing the flow in the v → u
direction.
We define Gf as the graph that contains the same vertices as the original graph, but only
contains the edges where cf > 0.

3.2 Ford Fulkerson approach

First we will show that if t is not reachable from s in Gf , then f is a maximum flow. Then,
if Gf has a path from s to t, we will show how to “augment” f to get a flow f 0 with greater
value.

4
Lecture 16 – Max Flow Jessica Su (some parts copied from CLRS / last quarter’s notes)

Based on this, we know that we can find a maximum flow by repeatedly augmenting the
flow until we can no longer find a path in the residual graph from s to t.

3.2.1 If t is not reachable from s in Gf , then f is a maximum flow

Proof: Define an s-t cut S ∪ T in the original graph G, where S is the set of nodes that are
reachable from s in Gf , and T is the set of nodes that are not. Observe that there are no
edges in Gf between nodes in S and nodes in T , because otherwise one of the nodes in T
would be reachable from s. So for all u ∈ S, v ∈ T , we have cf (u, v) = 0.
This means there are three cases:
1. If (u, v) is an edge in the original graph, then cf (u, v) = c(u, v) − f (u, v) = 0, so
c(u, v) = f (u, v).
2. If (v, u) is an edge in the original graph, then cf (u, v) = f (v, u) = 0.
3. If neither (u, v) nor (v, u) are edges, we can completely disregard this pair of vertices
since they do not appear in any flow or cut.
Therefore,
 
X X X
|f | =  f (u, x) − f (y, u) (from the previous proof)
u∈S x∈Nout (u)∩T y∈Nin (u)∩T
 
X X X
=  c(u, x) − 0
u∈S x∈Nout (u)∩T y∈Nin (u)∩T

= ||S, T ||

Since the flow is equal to the cut, by the previous lemma, f must be a max flow.

3.2.2 If Gf has a path from s to t, we can augment the path

Let P = x0 → x1 → · · · → xk be the path from s to t in the residual graph (note that this may
not necessarily correspond to a path in the real graph), and consider the edge of minimum
capacity in the residual graph. Let F be the weight of this edge, i.e. mini cf (xi , xi+1 ).
We may increase the overall flow in the graph by augmenting the flow by F . That is, if there
is an edge from xi → xi+1 in the original graph, we increase the flow on that edge by F . If
there is an edge from xi+1 to xi , we decrease the flow on that edge by F . Note that we can
always do this because of the definition of capacity in the residual graph.

5
Lecture 16 – Max Flow Jessica Su (some parts copied from CLRS / last quarter’s notes)

That is, define a new flow f 0 where



f (u, v) + F
 if (u, v) ∈ P
0
f (u, v) = f (u, v) − F if (v, u) ∈ P

f (u, v) otherwise

(Note that f 0 is only defined on edges that were in the original graph, so the (v, u) ∈ P case is
the case where the edge in the residual graph points in the opposite direction of the original
edge, and the (u, v) ∈ P case is the case where they are pointing in the same direction.)
We need to show that f 0 is a flow with greater value than f .
Capacity constraints:
1. If (u, v) ∈ P , then 0 ≤ f (u, v) + F ≤ f (u, v) + cf (u, v) = f (u, v) + c(u, v) − f (u, v) =
c(u, v).
2. If (v, u) ∈ P , then f (u, v)−F ≤ f (u, v) ≤ c(u, v) and f (u, v)−F ≥ f (u, v)−cf (u, v) =
0.
3. Otherwise, f 0 (u, v) = f (u, v), which is between 0 and c(u, v).
Conservation constraints: Suppose that P is a simple path. Then for every vertex v
other than s and t, v either touches 0 edges of P or 2 edges of P . If it touches 0 edges, the

6
Lecture 16 – Max Flow Jessica Su (some parts copied from CLRS / last quarter’s notes)

flow is conserved. If it touches 2 edges, then we consider four cases, depending on whether
the edge in Gf is the same direction as the corresponding edge in G, or whether it is in the
opposite direction.
Exercise: Verify that in all these cases, the flow is conserved.
Finally, |f 0 | > f because we are increasing our flow by F , which is greater than 0.

3.3 Ford Fulkerson pseudocode

Therefore, we can create a maximum flow by repeatedly augmenting paths in the flow network
until there is no longer any path from s to t in the residual network. We can find the path
in the residual network using some path finding method, like breadth-first search.

Runtime for arbitrary path finding method: If all the capacities are integers, we must
augment the flow by at least 1 every time, so the runtime is bounded by O(m|f |), where |f |
is the value of the maximum flow. However, this is inefficient when the flow is large (see the
figure), or the capacities are not integers. In fact, if the capacities are irrational numbers,
the algorithm is not guaranteed to terminate.
Good path finding method: However, if we choose the path using breadth-first search
(each time choosing the shortest unweighted path from s to t in the residual network), the
algorithm is guaranteed to run in polynomial time. Specifically, it runs in O(nm2 ) time.
When the Ford Fulkerson method is implemented using breadth-first search, it is called the
Edmonds-Karp algorithm.

7
Lecture 16 – Max Flow Jessica Su (some parts copied from CLRS / last quarter’s notes)

4 Bipartite perfect matching


Let G be an undirected, unweighted bipartite graph. That is, we may partition the vertices
into sets V1 and V2 , where there are no edges with two endpoints entirely in V1 or entirely
in V2 . A matching in G is a collection of edges M , no two of which share an endpoint.
For example, G might represent a set of people, where the nodes in V1 are women and the
nodes in V2 are men. A matching on G would pair women with men in such a way that no
woman can be paired with more than one man, or vice versa.
A perfect matching is a matching that includes all the vertices of the graph. So in the
example, all men and women would be paired.
Given a bipartite graph G with n nodes on each side, how can we tell if it has a perfect
matching? We can solve the problem as follows:
Convert G into a directed graph, where all the edges between V1 and V2 now point from V1
to V2 . Add a source s that points to all the nodes in V1 , and a sink t that all the nodes in V2
point to. Let all the edge capacities be 1, and run the Ford Fulkerson method to compute
the max flow. If the value of the max flow is n, then G has a perfect matching; otherwise it
doesn’t.
Proof: If G has a perfect matching M , then we can set all the edges in M to have flow
1, and all the edges out of s and into t also have flow 1. All other flow values are 0. This
produces a flow of value n.
The flow conservation constraints are satisfied since for every x ∈ V1 there is exactly one
edge (s, x) into x that has flow 1, and exactly one edge (x, y) ∈ M with flow 1. Similarly,
for every y ∈ V2 there is exactly one edge (x, y) ∈ M into y with flow 1 and exactly one edge
(y, t) out of y with flow 1. The capacity constraints are satisfied since all edges have flow
≤ 1.

8
Lecture 16 – Max Flow Jessica Su (some parts copied from CLRS / last quarter’s notes)

Now suppose Ford-Fulkerson returns a flow of value n, so that f (s, x) = f (y, t) = 1 for all
x ∈ V1 and y ∈ V2 . Since Ford-Fulkerson causes all flow values on the edges to be integers
(when the capacities are all integers), the flow values on all edges are either 1 or 0. Therefore,
every node x ∈ V1 gets a flow of 1 going into it and a flow of 1 needs to come out, so there
is a single edge (x, y) that has flow value 1 and all other edges out of x have flow value 0.
Similarly, for every y ∈ V2 there is a unique edge into y with positive flow value 1. Then the
edges in V1 ∪ V2 with positive flow form a perfect matching.

You might also like