Download presentation
Presentation is loading. Please wait.
1
1 Max Flow Jose Rolim University of Geneva
2
Max FlowJose Rolim2 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
3
Max FlowJose Rolim3 Examples ExampleEdgesNodes Highway systemRoadsInterchanges Comp. Communication Networks Communication links Routers Oil/gas distribution networks PipesJunctions with pumps
4
Max FlowJose Rolim4 Example Graph - Max. capacity of edge Actual flow through this edge Source node Sink node
5
Max FlowJose Rolim5 Simplified Model The network is modeled simply as a)a directed graph G = (V,E) with b)non-negative capacity on each edge, c)a single source node, s, and d)a single sink node, t
6
Max FlowJose Rolim6 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
7
Max FlowJose Rolim7 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
8
Max FlowJose Rolim8 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
9
Max FlowJose Rolim9 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.
10
Max FlowJose Rolim10 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)
11
Max FlowJose Rolim11 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…
12
Max FlowJose Rolim12 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
13
Max FlowJose Rolim13 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.16.87.317.2 9.62.40.712.7 3.61.26.511.3 16.310.414.5 37717 92112 31711.3 151015
14
Max FlowJose Rolim14 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(M ij ), ceil(M ij )) corresponding to rounding up or rounding down (3). Consistent matrix rounding is evidenced by feasible flow through the network
15
Max FlowJose Rolim15 Graph Representation 1 2 3 s t 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)
16
Max FlowJose Rolim16 Scheduling Assume a set of jobs, J, is to scheduled on M identical processors, with each job having 3 parameters: processing time (p i ), ready time (r i ) and due time (d i ). r i + p i <= d i if the job can be performed Preemption is allowed – jobs can be interrupted and restarted arbitrarily
17
Max FlowJose Rolim17 Example Let M = 3 for the following job set: The job set may therefore be represented graphically as shown
18
Max FlowJose Rolim18 (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 p i. (3). Connect each interval node T jk 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 T jk such that r i % j and d i ! 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
19
Max FlowJose Rolim19 Sample Graph 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
20
Max FlowJose Rolim20 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 t 1.Push flow along p 2.Reduce capacities along p
21
Max FlowJose Rolim21 Example 1: s uv xy t 2 4 4 65 2 3 1 5 According to the greedy approach of the Generic FF algorithm, consider the maximum flows from s to t.
22
Max FlowJose Rolim22 Example 1 (contd.) 1.Path s-u-v-t gives f=2. s uv t 2/2 2/4 2/5
23
Max FlowJose Rolim23 Example 1 (contd.) 2.Path s-x-y-t gives f=2+2=4. s xy t 2/4 2/2 2/3
24
Max FlowJose Rolim24 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 uv x t 4/4 2/6 4/5
25
Max FlowJose Rolim25 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.
26
Max FlowJose Rolim26 Residual Network Given an edge (u,v) with residual capacity c f (u,v) of an edge (u,v) is defined as c f (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: c f (u,v) = 10-6 = 4 c f (u,v) = 0 - (- 6) = 6 u v 6/10
27
Max FlowJose Rolim27 Residual network Residual network G f is (V,E f ), where E f = {(u, v) | c f (u, v) > 0}. Note: |E f | <= 2|E|. When is an edge (u, v) ε E f ? if (u, v) ε E and f(u, v) < c(u, v), or if (v, u) ε E and f(v, u) > 0.
28
Max FlowJose Rolim28 Example 2
29
Max FlowJose Rolim29 Augmenting Paths An augmenting path ‘ p ’ is a simple path in G f from s to t. The residual capacity of p is c f (p) = min { c f (u,v) | (u,v) ε p }. By definition, c f (p) > 0. Can you spot an augmenting path in the graph below?
30
Max FlowJose Rolim30 Now, Ford-Fulkerson changes to – 1.Initialize f = 0 2.While there exists an “ augmenting path ” p from s to t in G f 1.Push flow along p 2.Reduce capacities along p s uv xy t 2 1 1 1 1 1 1 2 Example 1
31
Max FlowJose Rolim31 Example 1(contd.) Consider s-x-y-t f = 1 s xy t 1 1 1
32
Max FlowJose Rolim32 Example 1(contd.) Consider s-u-v-t f=1+1 s uv t 1 1 1
33
Max FlowJose Rolim33 Example 1(contd.) This gives us the intermediate graph: s uv yx t 1 1 1 1 1 1 1 1 11
34
Max FlowJose Rolim34 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 xy t 2 1 1 1 2 1 1 1 1
35
Max FlowJose Rolim35 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.
36
Max FlowJose Rolim36 Example 1 In this example, f(S, T) = 12 − 4 + 11 = 19. c(S, T) = 12 + 14 = 26.
37
Max FlowJose Rolim37 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|.
38
Max FlowJose Rolim38 Proof
39
Max FlowJose Rolim39 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 G f } 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).
40
Max FlowJose Rolim40 Updated FF Algorithm 1.for each edge (u, v) є E do 2. f(u, v) = f(v, u) = 0; 3.while there is a path p in Gf do 4. cf (p) = min{cf (u, v) | (u, v) є p} 5. for each (u, v) є p do 6. f(u, v) = f(u, v) + cf (p) 7. f(v, u) = −f(u, v) 8. end 9.end.
41
Max FlowJose Rolim41 Example 1 Original Residual Graph Choose a path u s v xy t 16 14 79 20 10 13 12 4 4
42
Max FlowJose Rolim42 Example 1 (contd.) Edit the path following the while loop Choose a new path u s v xy t 12 10 79 20 14 13 12 4 4 4
43
Max FlowJose Rolim43 Example 1 (contd.) Keep iterating the while loop Choose the final path u s v xy t 12 3 79 13 14 6 12 4 4 11 7 7
44
Max FlowJose Rolim44 Example 1 (contd.) No more augmenting paths Final residual graph u s v xy t 3 79 1 14 6 12 4 16 11 19 7
45
Max FlowJose Rolim45 Example 1 (contd.) Final Capacity Graph All (S,T) cuts = 23 u s v xy t 16/16 11/14 7/70/9 19/20 0/10 7/13 12/12 4/4
46
Max FlowJose Rolim46 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.
47
Max FlowJose Rolim47 A Pathological Case for FF For large edge capacities and certain graph topologies the run-time may be pathological. Assume M >10 9 :
48
Max FlowJose Rolim48 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
49
Max FlowJose Rolim49 Shortest Path Augmentation Always augments flow from the shortest path from s to t Let d f (s, v) denote the shortest path distance from s to v in the current residual graph Gf. Standard BFS algorithm finds the d f (s, v) in O(m) time
50
Max FlowJose Rolim50 Shortest Path Augmentation
51
Max FlowJose Rolim51 Shortest Path Augmentation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.