Max-Flow Extensions and Applications - Lecture Notes | CS 573, Study notes of Algorithms and Programming

Material Type: Notes; Class: Algorithms; Subject: Computer Science; University: University of Illinois - Urbana-Champaign; Term: Unknown 1999;

Typology: Study notes

Pre 2010

Uploaded on 03/16/2009

koofers-user-ux9-1
koofers-user-ux9-1 🇺🇸

3

(1)

9 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Algorithms Lecture 15: Max-Flow Extensions and Applications
“Who are you?" said Lunkwill, rising angrily from his seat. “What do you want?"
“I am Majikthise!" announced the older one.
“And I demand that I am Vroomfondel!" shouted the younger one.
Majikthise turned on Vroomfondel. “It’s alright," he explained angrily, “you don’t need to
demand that."
“Alright!" bawled Vroomfondel banging on an nearby desk. “I am Vroomfondel, and that is
not a demand, that is a solid fact! What we demand is solid facts!"
“No we don’t!" exclaimed Majikthise in irritation. “That is precisely what we don’t demand!"
Scarcely pausing for breath, Vroomfondel shouted, “We don’t demand solid facts! What we
demand is a total absence of solid facts. I demand that I may or may not be Vroomfondel!"
Douglas Adams, The Hitchhiker’s Guide to the Galaxy (1979)
For a long time it puzzled me how something so expensive, so leading edge,
could be so useless, and then it occurred to me that a computer is a stupid
machine with the ability to do incredibly smart things, while computer pro-
grammers are smart people with the ability to do incredibly stupid things.
They are, in short, a perfect match.
Bill Bryson, Notes from a Big Country (1999)
15 Max-Flow Extensions and Applications
15.1 Edge-Disjoint Paths
One of the easiest applications of maximum flows is computing the maximum number of edge-disjoint
paths between two specified vertices
s
and
t
in a directed graph
G
using maximum flows. A set of paths
in
G
is edge-disjoint if each edge in
G
appears in at most one of the paths; several edge-disjoint paths
may pass through the same vertex, however.
If we give each edge capacity 1, then the maxflow from
s
to
t
assigns a flow of either 0 or 1 to every
edge. Since any vertex of
G
lies on at most two saturated edges (one in and one out, or none at all),
the subgraph Sof saturated edges is the union of several edge-disjoint paths and cycles. Moreover, the
number of paths is exactly equal to the value of the flow. Extracting the actual paths from
S
is easy—just
follow any directed path in Sfrom sto t, remove that path from S, and recurse.
Conversely, we can transform any collection of
k
edge-disjoint paths into a flow by pushing one
unit of flow along each path from
s
to
t
; the value of the resulting flow is exactly
k
. It follows that the
maxflow algorithm actually computes the largest possible set of edge-disjoint paths. The overall running
time is O(V E), just like for maximum bipartite matchings.
The same algorithm can also be used to find edge-disjoint paths in undirected graphs. We simply
replace every undirected edge in
G
with a pair of directed edges, each with unit capacity, and compute a
maximum flow from
s
to
t
in the resulting directed graph
G0
using the Ford-Fulkerson algorithm. For
any edge
uv
in
G
, if our max flow saturates both directed edges
uv
and
vu
in
G0
, we can remove
both edges from the flow without changing its value. Thus, without loss of generality, the maximum flow
assigns a direction to every saturated edge, and we can extract the edge-disjoint paths by searching the
graph of directed saturated edges.
15.2 Maximum Matchings in Bipartite Graphs
Another natural application of maximum flows is finding large matchings in bipartite graphs. A matching
is a subgraph in which every vertex has degree at most one, or equivalently, a collection of edges such
that no two share a vertex. The problem is to find the matching with the maximum number of edges in
a given bipartite graph.
1
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Max-Flow Extensions and Applications - Lecture Notes | CS 573 and more Study notes Algorithms and Programming in PDF only on Docsity!

“Who are you?" said Lunkwill, rising angrily from his seat. “What do you want?" “I am Majikthise!" announced the older one. “And I demand that I am Vroomfondel!" shouted the younger one. Majikthise turned on Vroomfondel. “It’s alright," he explained angrily, “you don’t need to demand that." “Alright!" bawled Vroomfondel banging on an nearby desk. “I am Vroomfondel, and that is not a demand, that is a solid fact! What we demand is solid facts!" “No we don’t!" exclaimed Majikthise in irritation. “That is precisely what we don’t demand!" Scarcely pausing for breath, Vroomfondel shouted, “We don’t demand solid facts! What we demand is a total absence of solid facts. I demand that I may or may not be Vroomfondel!" — Douglas Adams, The Hitchhiker’s Guide to the Galaxy (1979) For a long time it puzzled me how something so expensive, so leading edge, could be so useless, and then it occurred to me that a computer is a stupid machine with the ability to do incredibly smart things, while computer pro- grammers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match. — Bill Bryson, Notes from a Big Country (1999)

15 Max-Flow Extensions and Applications

15.1 Edge-Disjoint Paths

One of the easiest applications of maximum flows is computing the maximum number of edge-disjoint paths between two specified vertices s and t in a directed graph G using maximum flows. A set of paths in G is edge-disjoint if each edge in G appears in at most one of the paths; several edge-disjoint paths may pass through the same vertex, however. If we give each edge capacity 1, then the maxflow from s to t assigns a flow of either 0 or 1 to every edge. Since any vertex of G lies on at most two saturated edges (one in and one out, or none at all), the subgraph S of saturated edges is the union of several edge-disjoint paths and cycles. Moreover, the number of paths is exactly equal to the value of the flow. Extracting the actual paths from S is easy—just follow any directed path in S from s to t , remove that path from S , and recurse. Conversely, we can transform any collection of k edge-disjoint paths into a flow by pushing one unit of flow along each path from s to t ; the value of the resulting flow is exactly k. It follows that the maxflow algorithm actually computes the largest possible set of edge-disjoint paths. The overall running time is O ( V E ), just like for maximum bipartite matchings. The same algorithm can also be used to find edge-disjoint paths in undirected graphs. We simply replace every undirected edge in G with a pair of directed edges, each with unit capacity, and compute a maximum flow from s to t in the resulting directed graph G ′^ using the Ford-Fulkerson algorithm. For

any edge uv in G , if our max flow saturates both directed edges u  v and v  u in G ′, we can remove

both edges from the flow without changing its value. Thus, without loss of generality, the maximum flow assigns a direction to every saturated edge, and we can extract the edge-disjoint paths by searching the graph of directed saturated edges.

15.2 Maximum Matchings in Bipartite Graphs

Another natural application of maximum flows is finding large matchings in bipartite graphs. A matching is a subgraph in which every vertex has degree at most one, or equivalently, a collection of edges such that no two share a vertex. The problem is to find the matching with the maximum number of edges in a given bipartite graph.

We can solve this problem by reducing it to a maximum flow problem as follows. Let G be the given bipartite graph with vertex set UW , such that every edge joins a vertex in U to a vertex in W. We create a new directed graph G ′^ by (1) orienting each edge from U to W , (2) adding two new vertices s and t , (3) adding edges from s to every vertex in U , and (4) adding edges from each vertex in W to t. Finally, we assign every edge in G ′^ a capacity of 1. Any matching M in G can be transformed into a flow fM in G ′^ as follows: For each edge uw in M ,

push one unit of flow along the path s  u  w  t. These paths are disjoint except at s and t , so the

resulting flow satisfies the capacity constraints. Moreover, the value of the resulting flow is equal to the number of edges in M. Conversely, consider any ( s , t )-flow f in G ′^ computed using the Ford-Fulkerson augmenting path algorithm. Because the edge capacities are integers, the Ford-Fulkerson algorithm assigns an integer flow to every edge. (This is easy to verify by induction, hint, hint.) Moreover, since each edge has unit capacity, the computed flow either saturates ( f ( e ) = 1) or avoids ( f ( e ) = 0) every edge in G ′. Finally, since at most one unit of flow can enter any vertex in U or leave any vertex in W , the saturated edges from U to W form a matching in G. The size of this matching is exactly | f |. Thus, the size of the maximum matching in G is equal to the value of the maximum flow in G ′, and provided we compute the maxflow using augmenting paths, we can convert the actual maxflow into a maximum matching. The maximum flow has value at most min{| U |, | W |} = O ( V ), so the Ford-Fulkerson

algorithm runs in O ( V E ) time.

s t

A maximum matching in a bipartite graph G , and the corresponding maximum flow in G ′.

15.3 Maximum-Weight Matchings

Now suppose we want to find the matching with maximum weight in a bipartite graph with weighted edges. Given a bipartite graph G = ( U × W , E ) and a non-negative weight function w : E → IR, the goal is to compute a matching M whose total weight w ( M ) =

uwM w ( uw )^ is as large as possible. Max-weight matchings can’t be found directly using standard max-flow algorithms^1 , but we can modify the algorithm for maximum-cardinality matchings described above. It will be helpful to reinterpret the behavior of our earlier algorithm directly in terms of the original bipartite graph instead of the derived flow network. Our algorithm maintains a matching M , which is initially empty. We say that a vertex is matched if it is an endpoint of an edge in M. At each iteration, we find an alternating path π that starts and ends at unmatched vertices and alternates between edges in E \ M and edges in M. Equivalently, let GM be the directed graph obtained by orienting every edge in M from W to U , and every edge in E \ M from U to W. An alternating path is just a directed path in GM between two unmatched vertices. Any alternating path has odd length and has exactly one more edge in

(^1) However, max-flow algorithms can be modified to compute maximum weighted flows, where every edge has both a capacity and a weight, and the goal is to maximize

u  v w ( u  v )^ f^ ( u  v ).

Finally, since the number of red edges in Mi + 1 ⊕ Mi is one more than the number of blue edges, the number of paths that start with a red edge is exactly one more than the number of paths that start with a blue edge. The same reasoning as above implies that Mi + 1 ⊕ Mi does not contain a blue-first path, because we can pair it up with a red-first path. We conclude that Mi + 1 ⊕ Mi consists of a single alternating path π whose first edge is red. Since w ( Mi + 1 ) = w ( Mi ) − wi ( π ), the path π must be the one with minimum weight wi ( π ). É

We can find the alternating path πi using a single-source shortest path algorithm. Modify the residual graph Gi by adding zero-weight edges from a new source vertex s to every unmatched node in U , and from every unmatched node in W to a new target vertex t , exactly as in out unweighted matching algorithm. Then πi is the shortest path from s to t in this modified graph. Since Mi is the maximum-weight matching with i vertices, Gi has no negative cycles, so this shortest path is well-defined. We can compute the shortest path in Gi in O ( V E ) time using Shimbel’s algorithm, so the overall running time our algorithm is O ( V^2 E ). The residual graph Gi has negative-weight edges, so we can’t speed up the algorithm by replacing Shimbel’s algorithm with Dijkstra’s. However, we can use a variant of Johnson’s all-pairs shortest path algorithm to improve the running time to O ( V E + V^2 log V ). Let di ( v ) denote the distance from s to v in the residual graph Gi , using the distance function wi. Let w ˜ i denote the modified distance function

w ˜ i ( u  v ) = di − 1 ( u ) + wi ( u  v ) − di − 1 ( v ). As we argued in the discussion of Johnson’s algorithm, shortest

paths with respect to wi are still shortest paths with respect to w ˜ i. Moreover, w ˜ i ( u  v ) > 0 for every

edge u  v in Gi :

  • If u  v is an edge in Gi − 1 , then wi ( u  v ) = wi − 1 ( u  v ) and di − 1 ( v ) ≤ di − 1 ( u ) + wi − 1 ( u  v ).
  • If u  v is not in Gi − 1 , then wi ( u  v ) = − wi − 1 ( v  u ) and v  u is an edge in the shortest path πi − 1 ,

so di − 1 ( u ) = di − 1 ( v ) + wi − 1 ( v  u ).

Let d ˜ i ( v ) denote the shortest path distance from s to v with respect to the distance function w ˜ i. Because w ˜ i is positive everywhere, we can quickly compute d ˜ i ( v ) for all v using Dijkstra’s algorithm. This gives us both the shortest alternating path πi and the distances di ( v ) = d ˜ i ( v ) + di − 1 ( v ) needed for the next iteration.

15.4 Maximum Flows with Edge Demands

Now suppose each directed edge e in has both a capacity c ( e ) and a demand d ( e ) ≤ c ( e ), and we want a maximum flow that satisfies d ( e ) ≤ f ( e ) ≤ c ( e ). We call a flow that satisfies these constraints an admissible (or feasible ) flow. In our original setting, where d ( e ) = 0 for every edge e , the zero flow is admissible; however, in this more general setting, even determining whether an admissible flow exists is a nontrivial task. Perhaps the easiest way to find an admissible flow (or determine that none exists) is to reduce the problem to a standard maximum flow problem, as follows. The input consists of a directed graph G = ( V , E ), nodes s and t , demand function d : E → IR, and capacity function c : E → IR. Let D denote the sum of all edge demands in G : D :=

u  vE

d ( u  v ).

We construct a new graph G ′^ = ( V ′, E ′) from G by adding new source and target vertices s ′^ and t ′, adding edges from s ′^ to each vertex in V , adding edges from each vertex in V to t ′, and finally adding an edge from t to s. We also define a new capacity function c ′^ : E ′^ → IR as follows:

  • For each vertex vV , we set c ′( s ′ v ) =

u ∈ V d ( u  v )^ and^ c

′( v  t ′) = ∑

w ∈ V d ( v  w ).

  • For each edge u  vE , we set c ′( u  v ) = c ( u  v ) − d ( u  v ).
  • Finally, we set c ′( s  t ) = ∞.

Intuitively, we construct G ′^ by replacing any edge u  v in G with three edges: an edge u  v with

capacity c ( u  v ) − d ( u  v ), an edge s ′ v with capacity d ( u  v ), and an edge u  t ′^ with capacity d ( u  v ).

If this construction produces multiple edges from s ′^ to the same vertex v (or to t ′^ from the same vertex v ), we merge them into a single edge with the same total capacity.

s t

6..

4..

5..

0..

3..

2.. 5.. 7..

0..

s t

13

6

5

5

7

13

6 14

s'^14 t'

4 7

10 3

5 3

10 3

8 11

A flow network G with demands and capacities (written d .. c ), and the transformed network G ′.

In G ′, the total capacity out of s ′^ and the total capacity into t ′^ are both equal to D. We call a flow with value exactly D a saturating flow, since it saturates all the edges leaving s ′^ or entering t ′. If G ′^ has a saturating flow, it must be a maximum flow, so we can find it using any max-flow algorithm.

Lemma 2. G has an admissible ( s , t )-flow if and only if G ′^ has a saturating ( s ′, t ′)-flow.

Proof: Let f : E → IR be an admissible ( s , t )-flow in the original graph G. Consider the following function f ′^ : E ′^ → IR:

f ′( u  v ) = f ( u  v ) − d ( u  v ) for all u  v ∈ E

f ′( s ′ v ) =

uV

d ( u  v ) for all v ∈ V

f ′( v  t ′) =

wV

d ( uw ) for all vV

f ′( t  s ) = | f |

We easily verify that f ′^ is a saturating ( s ′, t ′)-flow in G. The admissibility of f implies that f ( e ) ≥ d ( e ) for every edge eE , so f ′( e ) ≥ 0 everywhere. Admissibility also implies f ( e ) ≤ c ( e ) for every edge eE , so f ′( e ) ≤ c ′( e ) everywhere. Tedious algebra implies that ∑

uV

f ′( u  v ) =

wV

f ( v  w )

for every vertex vV (including s and t ). Thus, f ′^ is a legal ( s ′, t ′)-flow, and every edge out of s

or into t ′^ is clearly saturated. Intuitively, f ′^ diverts d ( u  v ) units of flow from u directly to the new

target t ′, and injects the same amount of flow into v directly from the new source s ′. The same tedious algebra implies that for any saturating ( s ′, t ′)-flow f ′^ : E ′^ → IR for G ′, the function f = f ′| E + d is an admissible ( s , t )-flow in G. É

To simplify the transformation, let us assume without loss of generality that the total excess in the network is zero:

v x ( v ) =^ 0. If the total excess is positive, we add an infinite capacity edge^ t ˜ t ,

where ˜ t is a new target node, and set x ( t ) = −

v x ( v ). Similarly, if the total excess is negative, we add

an infinite capacity edge ˜ s  s , where ˜ s is a new source node, and set x ( s ) = −

v x ( v ). In both cases, every admissible flow in the modified graph corresponds to an admissible flow in the original graph. As before, we modify G to obtain a new graph G ′^ by adding a new source s ′, a new target t ′, an

infinite-capacity edge t  s from the old target to the old source, and several edges from s ′^ and to t ′.

Specifically, for each vertex v , if x ( v ) > 0, we add a new edge s ′ v with capacity x ( v ), and if x ( v ) < 0,

we add an edge v  t ′^ with capacity − x ( v ). As before, we call an ( s ′, t ′)-flow in G ′^ saturating if every

edge leaving s ′^ or entering t ′^ is saturated; any saturating flow is a maximum flow. It is easy to check that saturating flows in G ′^ are in direct correspondence with admissible flows in G ; we leave details as an exercise (hint, hint).

Similar reductions allow us to solve several other variants of the maximum flow problem using the same path-augmentation algorithms. For example, we could associate capacities and lower bounds with the vertices instead of (or in addition to) the edges. We could associate a range of excesses with every node, instead of a single excess value. We can associate a cost c ( e ) with each edge, and then ask for the maximum-value flow f whose total cost

e c ( e )^ ·^ f^ ( e )^ is as small as possible. We could even apply all of these extensions at once: upper bounds, lower bounds, and cost functions for the flow through each edge, into each vertex, and out of each vertex.

Exercises

  1. You are given an n × n grid, some of whose cells are marked; the grid is represented by an array M [ 1 .. n , 1 .. n ] of booleans, where M [ i , j ] = TRUE if and only if cell ( i , j ) is marked. A monotone path through the grid starts at the top-left cell, moves only right or down at each step, and ends at the bottom-right cell. Our goal is to cover the marked cells with as few monotone paths as possible.

Greedily covering the marked cells in a grid with four monotone paths.

(a) Describe an algorithm to find a monotone path that covers the largest number of marked cells. (b) There is a natural greedy heuristic to find a small cover by monotone paths: If there are any marked cells, find a monotone path π that covers the largest number of marked cells, unmark any cells covered by π those marked cells, and recurse. Show that this algorithm does not always compute an optimal solution. (c) Describe and analyze an efficient algorithm to compute the smallest set of monotone paths that covers every marked cell.

  1. Suppose we are given a directed graph G = ( V , E ), two vertices s an t , and a capacity function c : V → IR+. A flow f is feasible if the total flow into every vertex v is at most c ( v ): ∑

u

f ( u  v ) ≤ c ( v ) for every vertex v.

Describe and analyze an efficient algorithm to compute a feasible flow of maximum value.

  1. Given an undirected graph G = ( V , E ), with three vertices u , v , and w , describe and analyze an algorithm to determine whether there is a path from u to w that passes through v.
  2. Consider a directed graph G = ( V , E ) with multiple source vertices s 1 , s 2 ,... , and multiple target vertices t 1 , t 1 ,... , , where no vertex is both a source and a target. A multiterminal flow is a function f : E → IR≥ 0 that satisfies the flow conservation constraint at every vertex that is neither a source nor a target. The value | f | of a multiterminal flow is the total excess flow out of all the source vertices: | f | :=

∑^ σ

i = 1

w

f ( si  w ) −

u

f ( u  si )

As usual, we are interested in finding flows with maximum value, subject to capacity constraints on the edges. (In particular, we don’t care how much flow moves from any particular source to any particular target.)

  1. Let G = ( V , E ) be a directed graph where for each vertex v , the in-degree and out-degree of v are equal. Let u and v be two vertices G, and suppose G contains k edge-disjoint paths from u to v. Under these conditions, must G also contain k edge-disjoint paths from v to u? Give a proof or a counterexample with explanation.

? 8. A rooted tree is a directed acyclic graph, in which every vertex has exactly one incoming edge,

except for the root , which has no incoming edges. Equivalently, a rooted tree consists of a root vertex, which has edges pointing to the roots of zero or more smaller rooted trees. Describe a polynomial-time algorithm to compute, given two rooted trees A and B , the largest common rooted subtree of A and B. [Hint: Let LC S ( u , v ) denote the largest common subtree whose root in A is u and whose root in B is v. Your algorithm should compute LC S ( u , v ) for all vertices u and v using dynamic programming. This would be easy if every vertex had O ( 1 ) children, and still straightforward if the children of each node were ordered from left to right and the common subtree had to respect that ordering. But for unordered trees with large degree, you need another trick to combine recursive subproblems efficiently. Don’t waste your time trying to reduce the polynomial running time.]

© c Copyright 2008 Jeff Erickson. Released under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License (http://creativecommons.org/licenses/by-nc-sa/3.0/). Free distribution is strongly encouraged; commercial distribution is expressly forbidden. See http://www.cs.uiuc.edu/~jeffe/teaching/algorithms for the most recent revision.