1 max flow jose rolim university of geneva. max flowjose rolim2 graph models graphs (used as models...
Post on 18-Dec-2015
217 views
TRANSCRIPT
1
Max Flow
Jose RolimUniversity of Geneva
Max Flow Jose Rolim 2
Graph Models
Graphs (used as models of "transportation" networks) have the following components:
Links / edges: carrier of some sort of traffic and have capacities
Nodes:- source nodes: generate traffic- sink nodes: absorb/demand traffic- intermediate nodes: "switches" which pass traffic between different edges
Description of the traffic itself
Max Flow Jose Rolim 3
Examples
Example Edges Nodes
Highway system Roads Interchanges
Comp. Communication Networks
Communication links
Routers
Oil/gas distribution networks
Pipes Junctions with pumps
Max Flow Jose Rolim 4
Example Graph
-
Max. capacity of edgeActual flow through this edge
Source node
Sink node
Max Flow Jose Rolim 5
Simplified Model
The network is modeled simply asa) a directed graph G = (V,E) withb) non-negative capacity on each
edge,c) a single source node, s, andd) a single sink node, t
Max Flow Jose Rolim 6
Some assumptions…
We will simplify our discussion by assuming the following:
(i) No edge enters s, the source(ii) No edge leaves t, the sink(iii)At least one edge is incident to
each node(iv)All capacities are integers
Max Flow Jose Rolim 7
Definition of Flow
Flow will be our abstract term for the traffic; as an entity originating at the source node and absorbed at the sink node
An (s,t) flow is a function f that assigns a non-negative number to each edge e in the graph G = (V,E)
The value of a flow is
Max Flow Jose Rolim 8
Intuitive definition
f(e) intuitively is the “flow” on edge e subject to two conditions:
(i) capacity constraint: 0 ≤ f(e) ≤ c(e), where c(e) is the capacity of edge
e
(ii) conservation property: for each node v, other than s and t,
∑ f(e) = ∑ f(e) e into v v into e
Max Flow Jose Rolim 9
Max Flow Problem
What is the maximum amount of flow that can be sustained in G?
Clearly, the only obstacle to the flow are the capacities of the edges in G. The bottleneck doesn’t necessarily occur from the edges originating at s, or those terminating at t. It can arise from a complicated interaction among the edges, as flow snakes through G.
Max Flow Jose Rolim 10
Max Flow Problem
Given a flow network G = (V,E,c), a source s, and a sink t,
(1) What is the max flow that can be sustained in G (between s and t)?
(2) Then, find an algorithm to best assign f values to the edges in G to answer (1)
Max Flow Jose Rolim 11
Sample Applications
The Max Flow problem shows up in many places, some less intuitive than others.
For instance, consider a shipping company seeking to ship as many units of a product (hockey pucks) as possible Product starts at a source factory in
Vancouver and ends in Winnipeg The problem may be represented
graphically as show in the following slide…
Max Flow Jose Rolim 12
Transportation
(1). Let the capacity of an edge be the number of units that can be shipped between two cities by a shipping company
(2). Let the current number of units being shipped between cities be denoted as flow between those cities.
The following graph can therefore represent the problem:Nodes denote cities
Can be interpreted as 4 units being shipped out of 4 possible
Max Flow Jose Rolim 13
Matrix Rounding
A p x q matrix of decimals may be summed along the rows and columns
Rounding each entry up or down between ceil(a) and floor(a) may cause the sums to change.
Trying to keep the sum consistent along rows does not necessarily keep the sum consistent along cols and vice-versa (see fig.)
3.1 6.8 7.3 17.2
9.6 2.4 0.7 12.7
3.6 1.2 6.5 11.3
16.3
10.4
14.53 7 7 17
9 2 1 12
3 1 7 11.3
15 10 15
Max Flow Jose Rolim 14
Max Flow as a Solution
(1). Create a node, i, for each row, and a node, j, for each col in the matrix, and two additional nodes, s (source) and t (sink)
(2). For each entry in the matrix, create an edge with cost (floor(Mij), ceil(Mij)) corresponding to rounding up or rounding down
(3). Consistent matrix rounding is evidenced by feasible flow through the network
Max Flow Jose Rolim 15
Graph Representation
1
2
3
st
1’
2’
3’
(10,11)(12,13)
(11,12)
(3,4)
(6,7)(7,8)
(9,10)(2,3)
(0,1)
(3,4)
(6,7)
(1,2)
(16,17)(17,18)
(14,15)
Max Flow Jose Rolim 16
Scheduling
Assume a set of jobs, J, is to scheduled on M identical processors, with each job having 3 parameters: processing time (pi), ready time (ri) and due time (di).
ri + pi <= di if the job can be performed
Preemption is allowed – jobs can be interrupted and restarted arbitrarily
Max Flow Jose Rolim 17
Example
Let M = 3 for the following job set:
The job set may therefore be represented graphically as shown
Max Flow Jose Rolim 18
(1). Create a node for every interval in the interval diagram and one for every job as well as a source node, s, and a sink, t.
(2). Connect s to job j with capacity pi.(3). Connect each interval node Tjk to sink t with
capacity (k − j) * M, indicating the number of machine units available in that interval.
(4). Connect a job i to each interval Tjk such that ri % j and di ! k. The capacity of this edge is (k − j) indicating the number of machine units allotable to job i in this interval.
(5). There is a soln to the problem iff there is a max flow of value
Converting to Graph Form
Max Flow Jose Rolim 19
Sample Graph
s
1
2
3
4
T13
T34
T45
T57
T79
t
1.5
1.25
2.1
3.6
1
1
2
1
1
1
2
2
2
6
3
3
6
6
This sample graph demonstrates some of the power of max flow. Many scheduling problems are NP-Complete, so finding a soln. to such a problem is very useful
Thus max flow may be used to solve a wide range of seemingly unrelated problems and is useful beyond simple representations of computer networks
Max Flow Jose Rolim 20
Ford-Fulkerson Method
Developed by Ford and Fulkerson [1956] Widely used and influential ideas:
augmentation, residual network, and famous min-cut max-flow theorem.
Algorithm: Generic FF (G,s,t)1. Initialize f = 0 (i.e. zero flow on all edges)2. While there exists an “augmenting path” p from
s to t1. Push flow along p2. Reduce capacities along p
Max Flow Jose Rolim 21
Example 1:
s
u v
x y
t
2
4
4
6 5
2
3
1
5
According to the greedy approach of the Generic FF algorithm, consider the maximum flows from s to t.
Max Flow Jose Rolim 22
Example 1 (contd.)
1. Path s-u-v-t gives f=2.
s
u v
t
2/2
2/4
2/5
Max Flow Jose Rolim 23
Example 1 (contd.)
2. Path s-x-y-t gives f=2+2=4.
s
x y
t
2/4
2/2
2/3
Max Flow Jose Rolim 24
Example 1 (contd.)
3. Path s-x-u-v-t gives f=2+2+2=6. This gives us a total flow of 6, but it is not an optimal solution.
s
u v
x
t
4/4
4/4
2/6
4/5
Max Flow Jose Rolim 25
Example 2:
By employing a greedy approach, we get a flow of 2. However, by not employing a greedy approach we can get a flow capacity of 3 in the above network.
Max Flow Jose Rolim 26
Residual Network
Given an edge (u,v) with residual capacity cf(u,v) of an edge (u,v) is defined as cf(u,v) = c(u,v) – f(u,v)
Residual capacity is the additional flow one can send on an edge, possibly by canceling some flow in opposite edge.
Example 1:cf(u,v) = 10-6 = 4
cf(u,v) = 0 - (- 6) = 6
u v
6/10
Max Flow Jose Rolim 27
Residual network
Residual network Gf is (V,Ef ), where Ef = {(u, v) | cf (u, v) > 0}.
Note: |Ef | <= 2|E|.
When is an edge (u, v) ε Ef? if (u, v) ε E and f(u, v) < c(u, v), or if (v, u) ε E and f(v, u) > 0.
Max Flow Jose Rolim 28
Example 2
Max Flow Jose Rolim 29
Augmenting Paths
An augmenting path ‘p’ is a simple path in Gf
from s to t. The residual capacity of p is cf(p) = min { cf(u,v)
| (u,v) ε p }. By definition, cf(p) > 0.
Can you spot an augmenting path in the graph below?
Max Flow Jose Rolim 30
Now, Ford-Fulkerson changes to –1. Initialize f = 0 2. While there exists an “augmenting path” p from
s to t in Gf
1. Push flow along p2. Reduce capacities along p
s
u v
x y
t
2
1
1
1
1
1
1
2
Example 1
Max Flow Jose Rolim 31
Example 1(contd.)
Consider s-x-y-t f = 1
s
x y
t
1
1
1
Max Flow Jose Rolim 32
Example 1(contd.)
Consider s-u-v-t f=1+1
s
u v
t
1
1
1
Max Flow Jose Rolim 33
Example 1(contd.)
This gives us the intermediate graph:
s
u v
yx
t
1
1
1
1
1
1
1
1
1 1
Max Flow Jose Rolim 34
Example 1(contd.)
Finally, considering s-u-y-x-v-t, we get the residual graph shown below.
f=1+1+1 = 3
u
s
v
x y
t
2
1
1
1
2
1
1
1
1
Max Flow Jose Rolim 35
Cuts
A cut (S, T) is a partition of V with s ε S and t ε T.
f(S, T) is the net flow across cut (S, T). c(S, T) is the max capacity of cut (S, T); use only
forward edges.
Max Flow Jose Rolim 36
Example 1
In this example, f(S, T) = 12 − 4 + 11 = 19. c(S, T) = 12 + 14 = 26.
Max Flow Jose Rolim 37
Flows and Cuts
No matter how you separate s and t, the net flow across (S, T) is exactly |f|.
Cut Lemma: If f is a flow and (S, T) a cut in G, then f(S, T) = |f|.
Max Flow Jose Rolim 38
Proof
Max Flow Jose Rolim 39
MaxFlow-MinCut Theorem
The following are equivalent:1. f is a maxflow.2. No augmenting path in Gf .3. |f| = c(S, T) for some cut (S, T).
PROOF: (1) => (2). Augmenting path increases f. (3) => (1). By Cut Lemma, |f| = f(S, T) ≤ c(S, T). So, equality
means flow is a maxflow. (2) => (3). Define reachable set, S = {v | such that path from s to v in
Gf} T = V − S. Then, t ε T—because no augmenting path. For
any u ε S, v ε T, f(u, v) = c(u, v); otherwise, (u, v) ε Ef , and v will be
reachable from s. Thus, |f| = f(S, T) = c(S, T).
Max Flow Jose Rolim 40
Updated FF Algorithm
1. for each edge (u, v) є E do2. f(u, v) = f(v, u) = 0;3. while there is a path p in Gf do4. cf (p) = min{cf (u, v) | (u, v) є p}5. for each (u, v) є p do6. f(u, v) = f(u, v) + cf (p)7. f(v, u) = −f(u, v)8. end9. end.
Max Flow Jose Rolim 41
Example 1
Original Residual Graph Choose a path
u
s
v
x y
t
16
14
79
20
10
13
12
4
4
Max Flow Jose Rolim 42
Example 1 (contd.)
Edit the path following the while loop Choose a new path
u
s
v
x y
t
12
10
79
20
14
13
12
4
4
4
Max Flow Jose Rolim 43
Example 1 (contd.)
Keep iterating the while loop Choose the final path
u
s
v
x y
t
12
3
79
13
14
6
12
4
4
11
7
7
Max Flow Jose Rolim 44
Example 1 (contd.)
No more augmenting paths Final residual graph
u
s
v
x y
t
3
79
1
14
6
12
4
16
11
19
7
Max Flow Jose Rolim 45
Example 1 (contd.)
Final Capacity Graph All (S,T) cuts = 23
u
s
v
x y
t
16/16
11/14
7/70/9
19/20
0/10
7/13
12/12
4/4
4/4
Max Flow Jose Rolim 46
Analysis of Ford - Fulkerson
Correctness follows from maxflow–mincut
BFS or DFS to find augmenting path takes O(m) time
If edge capacities are integers with maximum cap U, then the number of augmentations is at most Un
Total running time O(m) * O(nU) = O(nmU)
If the edge capacities are irrational, then it is not clear that the algorithm will terminate in polynomial time.
Max Flow Jose Rolim 47
A Pathological Case for FF
For large edge capacities and certain graph topologies the run-time may be pathological. Assume M >109:
Max Flow Jose Rolim 48
Polynomial Time Maxflow
FF method does not prescribe how to pick augmenting paths
Edmunds-Karp heuristics: Shortest augmenting path first Max capacity augmentation
Heuristics are somewhat obvious, cleverness lies in their analysis
Max Flow Jose Rolim 49
Shortest Path Augmentation
Always augments flow from the shortest path from s to t
Let df(s, v) denote the shortest path distance from s to v in the current residual graph Gf .
Standard BFS algorithm finds the df(s, v) in O(m) time
Max Flow Jose Rolim 50
Shortest Path Augmentation
Max Flow Jose Rolim 51
Shortest Path Augmentation