Docsity

Network Flow III-Applications - Fundamental Algorithms | CS 473, Study notes of Algorithms and Programming

Toggle sidebar
bg1
8: Network Flow III - Applications
Sariel Har-Peled
February 9, 2006
473G - Algorithms
Version: 0.1
This is an early version of the class notes. There are no guar-
antees that there are no mistakes or typos. A better version
would be hopefully released in the near future.
1 Edge disjoint paths
1.1 Edge-disjoint paths in a directed graphs
Question 1.1 Given a graph G (either directed or undirected), two vertices s and t, and a parameter k, find
k paths from s to t in G, such that they do not share an edge.
To solve this problem, we will convert G(assume Gis a directed graph for the time being) into a network
flow graph H, such that every edge has capacity 1. Find the maximum flow in G. We claim that the value of
the maximum flow in the network H, is equal to the number of edge disjoint paths in G.
Lemma 1.2 If there are k edge disjoint paths in G between s and t, then the maximum flow in H is at least
k.
Proof: Just push flow 1 along each such path.
Definition 1.3 (0/1-flow) A flow fis 0/1-flow if every edge has either no flow on it, or one unit of flow.
Lemma 1.4 Let f be a 0/1flow in a network H with flow value being µ. Then there are µedge disjoint
paths between s and t in H.
Proof: By induction on the number of edges in Hthat has one unit of flow assigned to them by f. If
µ=0 then there is nothing to prove.
Otherwise, start traversing the graph Hfrom straveling only along edges with flow 1 assigned to them
by f. We mark such an edge as used, and do not allow one to travel on such an edge again. There are two
possibilities:
(i) We reached the target vertex t. In this case, we take this path, add it to the set of output paths, and
reduce the flow along the edges of the generated path πto 0. Let H0be the resulting flow network and f0
the resulting flow. |f0|=µ−1, H0has less edges, and by induction, it has µ−1 edge disjoint paths in H0
between sand t. Together with πthis forms µsuch paths.
(ii) We visit a vertex vfor the second time. In this case, our traversal contains a cycle C, of edges in
Hthat have flow 1 on them. We set the flow along the edges of Cto 0 and use induction on the remaining
graph (since it has less edges with flow 1 on them). The value of the flow fdid not change by removing C,
and as such it follows by induction that there are µedge disjoint paths between sand tin H.
Since the graph Gis simple, there are at most n=|V(H)|edges that leave s. As such, the maximum flow
in His n. Thus, applying the Ford-Fulkerson algorithm, takes O(mn) time. The extraction of the paths can
also be done in linear time by applying the algorithm in the proof of Lemma 1.4. As such, we get:
1
pf3
pf4
pf5

Partial preview of the text

Download Network Flow III-Applications - Fundamental Algorithms | CS 473 and more Study notes Algorithms and Programming in PDF only on Docsity!

8: Network Flow III - Applications

Sariel Har-Peled

February 9, 2006

473G - Algorithms

Version: 0. This is an early version of the class notes. There are no guar- antees that there are no mistakes or typos. A better version would be hopefully released in the near future.

1 Edge disjoint paths

1.1 Edge-disjoint paths in a directed graphs

Question 1.1 Given a graph G (either directed or undirected), two vertices s and t, and a parameter k, find k paths from s to t in G, such that they do not share an edge.

To solve this problem, we will convert G (assume G is a directed graph for the time being) into a network flow graph H, such that every edge has capacity 1. Find the maximum flow in G. We claim that the value of the maximum flow in the network H, is equal to the number of edge disjoint paths in G.

Lemma 1.2 If there are k edge disjoint paths in G between s and t, then the maximum flow in H is at least k.

Proof: Just push flow 1 along each such path.

Definition 1.3 ( 0 / 1 -flow) A flow f is 0/ 1 -flow if every edge has either no flow on it, or one unit of flow.

Lemma 1.4 Let f be a 0 / 1 flow in a network H with flow value being μ. Then there are μ edge disjoint paths between s and t in H.

Proof: By induction on the number of edges in H that has one unit of flow assigned to them by f. If μ = 0 then there is nothing to prove. Otherwise, start traversing the graph H from s traveling only along edges with flow 1 assigned to them by f. We mark such an edge as used, and do not allow one to travel on such an edge again. There are two possibilities: (i) We reached the target vertex t. In this case, we take this path, add it to the set of output paths, and reduce the flow along the edges of the generated path π to 0. Let H′^ be the resulting flow network and f ′ the resulting flow. | f ′| = μ − 1, H′^ has less edges, and by induction, it has μ − 1 edge disjoint paths in H′ between s and t. Together with π this forms μ such paths. (ii) We visit a vertex v for the second time. In this case, our traversal contains a cycle C, of edges in H that have flow 1 on them. We set the flow along the edges of C to 0 and use induction on the remaining graph (since it has less edges with flow 1 on them). The value of the flow f did not change by removing C, and as such it follows by induction that there are μ edge disjoint paths between s and t in H. Since the graph G is simple, there are at most n = |V(H)| edges that leave s. As such, the maximum flow in H is n. Thus, applying the Ford-Fulkerson algorithm, takes O(mn) time. The extraction of the paths can also be done in linear time by applying the algorithm in the proof of Lemma 1.4. As such, we get:

Theorem 1.5 Given a directed graph G with n vertices and m edges, and two vertices s and t, one can compute the maximum number of edge disjoint paths between s and t in H, in O(mn) time.

As a consequence we get the following cute result:

Lemma 1.6 In a directed graph G with nodes s and t the maximum number of edge disjoint s − t paths is equal to the minimum number of edges whose removal separates s from t.

Proof: Let U be a collection of edge-disjoint paths from s to t in G. If we remove a set F of edges from G and separate s from t, then it must be that every path in U uses at least one edge of F. Thus, the number of edge-disjoint paths is bounded by the number of edges needed to be removed to separate s and t. Namely, |U| ≤ |F|. As for the other direction, let F be a set of edges thats its removal separates s and t. We claim that the set F form a cut in G between s and t. Indeed, let S be the set of all vertices in G that are reachable from s without using an edge of F. Clearly, if F is minimal then it must be all the edges of the cut (S , T ) (in particular, if F contains some edge which is not in (S , T ) we can remove it and get a smaller separating set of edges). In particular, the smallest set F with this separating property has the same size as the minimum cut between s and t in G, which is by the max-flow min-cut theorem, also the maximum flow in the graph G (where every edge has capacity 1). But then, by Theorem 1.5, there are |F| edge disjoint paths in G (since |F| is the amount of the maximum flow).

1.2 Edge-disjoint paths in undirected graphs

We would like to solve the s-t disjoint path problem for an undirected graph.

Problem 1.7 Given undirected graph G, s and t, find the maximum number of edge-disjoint paths in G between s and t.

The natural approach is to duplicate every edge in the undirected graph G, and get a (new) directed graph H. Next, apply the algorithm of Section 1.1 to H. So compute for H the maximum flow f (where every edge has capacity 1). The problem is the the flow f might use simultaneously the two edges −→uv and −→vu. Observe, however, that in such case we can remove both edges from the flow f. In the resulting flow is legal and has the same value. As such, if we repeatedly remove those “double edges” from the flow f , the resulting flow f ′^ has the same value. Next, we extract the edge disjoint paths from the graph, and the resulting paths are now edge disjoint in the original graph.

Lemma 1.8 There are k edge-disjoint paths in an undirected graph G from s to t if and only if the maximum value of an s − t flow in the directed version H of G is at least k. Furthermore, the Ford-Fulkerson algorithm can be used to find the maximum set of disjoint s-t paths in G in O(mn) time.

2 Circulations with demands

2.1 Circulations with demands

  • We have a usual network flow network H. Compute maximum flow on H from s to t. If it is equal to D, then there is a valid circulation, and it is the flow restricted to the original graph. Otherwise, there is no valid circulation.

Theorem 2.4 There is a feasible circulation with demands {dv} in G and and only if the maximum s-t flow in H has value D. If all capacities and demands in G are integers, and there is a feasible circulation, then there is a feasible circulation that is integer valued.

3 Circulations with demands and lower bounds

Assume that in addition to specifying a circulation and demands on a network G, we also specify for each edge a lower bound on how much flow should be on each edge. Namely, for every edge e ∈ E(G), we specify (e) ≤ c(e), which is a lower bound to how much flow must be on this edge. As before we assume all numbers are integers. We need now to compute a flow f that fill all the demands on the vertices, and that for any edge e, we have(e) ≤ f (e) ≤ c(e). The question is how to compute such a flow? Let use start from the most naive flow, which transfer on every edge, exactly its lower bound. This is a valid flow as far as capacities and lower bounds, but of course, it might violate the demands. Formally, let f 0 (e) = `(e), for all e ∈ E(G). Note that f 0 does not even satisfy the the conservation rule:

Lv = f 0 in (v) − f 0 out (v) =

e into v

`(e) −

e out o f v

`(e).

If Lv = dv, then we are happy, since this flow satisfies the required demand. Otherwise, there is imbal- ance at v, and we need to fix it. Formally, we set a new demand d′ v = dv − Lv for every node v, and the capacity of every edge e to be c′(e) = c(e) − `(e). Let G′^ denote the new network with those capacities and demands (note, that the lower bounds had “disappeared”). If we can find a circulation f ′^ on G′^ that satisfies the new demands, then clearly, the flow f = f 0 + f ′, is a legal circulation, it satisfies the demands and the lower bounds. But finding such a circulation, is something we already know how to do, using the algorithm of Theo- rem 2.4. Thus, it follows that we can compute a circulation with lower bounds.

Lemma 3.1 There is a feasible circulation in G if and only if there is a feasible circulation in G′. If all demands, capacities, and lower bounds in G are integers, and there is a feasible circulation, then there is a feasible circulation that is integer valued.

Proof: Let f ′^ be a circulation in G′. Let f (e) = f 0 (e) + f ′(e). Clearly, f satisfies the capacity condition in G, and the lower bounds. Furthermore,

f in(v) − f out(v) =

e into v

(`(e) + f ′(e)) −

e out o f v

`(e) + f ′(e)

= Lv +(dv − Lv) = dv.

As such f satisfies the demand conditions on G. Similarly, let f be a valid circulation in G. Then it is easy to check that f ′(e) = f (e) − `(e) is a valid circulation for G′.

4 Applications

4.1 Survey design

We would like to design a survey of products used by consumers (i.e., “Consumer i: what did you think of product j?”). The ith consumer agreed in advance to answer a certain number of questions in the range [ci, c′ i ]. Similarly, for each product j we would like to have at least p (^) j opinions about it, but not more than p′j. Each consumer can be asked about a subset of the products which they consumed. In particular, we assume that we know in advance all the products each consumer used, and the above constraints. The question is how to assign questions to consumers, so that we get all the information we want to get, and every consumer is being asked a valid number of questions. The idea of our solution is to reduce the design of the survey to the problem of computing a circulation in graph. First, we build a bipartite graph having consumers on one side, and products on the other side. Next, we insert the edge between consumer i and product j if the product was used by this consumer. The capacity of this edge is going to be 1. Intuitively, we are going to compute a flow in this network which is going to be an integer number. As such, every edge would be assigned either 0 or 1, where 1 is interpreted as asking the consumer about this product.

s

ci, c′ i

t

pj, p′ j

The next step, is to connect a source to all the consumers, where the edge

si has lower bound ci and upper bound c′ i. Sim-

ilarly, we connect all the products to the destination t, where

jt has lower bound p (^) j and upper bound p′j. We would like to com- pute a flow from s to t in this network that comply with the con- straints. However, we only know how to compute a circulation on such a network. To overcome this, we create an edge with in- finite capacity between t and s. Now, we are only looking for a valid circulation in the resulting graph G which complies with the aforementioned constraints. See figure on the right for an example of G. Given a circulation f in G it is straightforward to interpret it as a survey design (i.e., all middle edges with flow 1 are questions to be asked in the survey). Similarly, one can verify that given a valid survey, it can be interpreted as a valid circulation in G. Thus, computing circulation in G indeed solves our problem. We summarize:

Lemma 4.1 Given n consumers and u products with their constraints c 1 , c′ 1 , c 2 , c′ 2 ,... , cn, c′ n, p 1 , p′ 1 ,... , pu, p′ u and a list of length m of which products where used by which consumers. An algorithm can compute a valid survey under these constraints, if such a survey exists, in time O((n + u)m^2 ).