Download presentation
Presentation is loading. Please wait.
Published byFay Stone Modified over 9 years ago
1
1 Maximum Flow w s v u t z 3/33/3 1/91/9 1/11/1 3/33/3 4/74/7 4/64/6 3/53/5 1/11/1 3/53/5 2/22/2
2
Flow Network 2 A flow network (or just network) N consists of A weighted digraph G with nonnegative integer edge weights, where the weight of an edge e is called the capacity c(e) of e Two distinguished vertices, s and t of G, called the source and sink, respectively, such that s has no incoming edges and t has no outgoing edges. Example: w s v u t z 3 9 1 3 7 6 5 1 5 2 Maximum Flow
3
Flow 3 A flow f for a network N is is an assignment of an integer value f(e) to each edge e that satisfies the following properties: Capacity Rule: For each edge e, 0 f (e) c(e) Conservation Rule: For each vertex v s,t where E (v) and E (v) are the incoming and outgoing edges of v, resp. The value of a flow f, denoted |f|, is the total flow from the source, which is the same as the total flow into the sink Example: w s v u t z 3/33/3 2/92/9 1/11/1 1/31/3 3/73/7 2/62/6 4/54/5 1/11/1 3/53/5 2/22/2 Maximum Flow
4
4 A flow for a network N is said to be maximum if its value is the largest of all flows for N The maximum flow problem consists of finding a maximum flow for a given network N Applications Hydraulic systems Electrical circuits Traffic movements Freight transportation w s v u t z 3/33/3 2/92/9 1/11/1 1/31/3 3/73/7 2/62/6 4/54/5 1/11/1 3/53/5 2/22/2 w s v u t z 3/33/3 2/92/9 1/11/1 3/33/3 3/73/7 4/64/6 4/54/5 1/11/1 3/53/5 2/22/2 Flow of value 8 = 2 + 3 + 3 = 1 + 3 + 4 Maximum flow of value 10 = 4 + 3 + 3 = 3 + 3 + 4 Maximum Flow
5
Greedy may not work 5 If we just keep picking paths and adding them to the flow, we may make a mistake. In this case, sending 2 units along s-v-w-t is a mistake w s v u t z 3/63/6 1/11/1 2/2 0/30/3 5/5 2/22/2 5/55/5 1/11/1 5/55/5 4/44/4 Flow of value 10 = 2 + 3 + 5 = 1 + 5 + 4 Maximum flow of value 12 = 2+5+5 = 2+0+5+1+4 w s u t z 5/65/6 1/11/1 0/2 5/5 2/22/2 5/55/5 1/11/1 5/55/5 4/44/4 v 2/32/3 Maximum Flow
6
Cut 6 A cut of a network N with source s and sink t is a partition (V s,V t ) of the vertices of N such that s V s and t V t Forward edge of cut : origin in V s and destination in V t Backward edge of cut : origin in V t and destination in V s Flow f( ) across a cut : total flow of forward edges minus total flow of backward edges Capacity c( ) of a cut : total capacity of forward edges Example: c( ) 24 f( ) 8 w s v u t z 3 9 1 3 7 6 5 1 5 2 w s v u t z 3/33/3 2/92/9 1/11/1 1/31/3 3/73/7 2/62/6 4/54/5 1/11/1 3/53/5 2/22/2 Maximum Flow
7
Flow and Cut 7 Lemma: The flow f( ) across any cut is equal to the flow value |f| Lemma: The flow f( ) across a cut is less than or equal to the capacity c( ) of the cut Theorem: The value of any flow is less than or equal to the capacity of any cut, i.e., for any flow f and any cut , we have |f| c( ) w s v u t z 3/33/3 2/92/9 1/11/1 1/31/3 3/73/7 2/62/6 4/54/5 1/11/1 3/53/5 2/22/2 11 22 c( 1 ) 12 6 3 1 2 c( 2 ) 21 3 7 9 2 |f| 8 Maximum Flow
8
Augmenting Path 8 Consider a flow f for a network N Let e be an edge from u to v : Residual capacity of e from u to v : f (u, v) = c(e) f (e) Residual capacity of e from v to u : f (v, u) = f (e) (we can go backwards along edge) Let be a path from s to t The residual capacity f ( ) of is the smallest of the residual capacities of the edges of in the direction from s to t A path from s to t is an augmenting path if f ( ) 0 w s v u t z 3/33/3 2/92/9 1/11/1 1/31/3 2/72/7 2/62/6 4/54/5 0/10/1 2/52/5 2/22/2 f (s,u) 3 f (u,w) 1 f (w,v) 1 f (v,t) 2 f ( ) 1 |f| 7 Maximum Flow
9
Flow Augmentation 9 Lemma: Let be an augmenting path for flow f in network N. There exists a flow f for N of value | f | = |f | f ( ) Proof: We compute flow f by modifying the flow on the edges of Forward edge: f (e) = f(e) f ( ) Backward edge: f (e) = f(e) f ( ) w s v u t z 3/33/3 2/92/9 1/11/1 1/31/3 2/72/7 2/62/6 4/54/5 0/10/1 2/52/5 2/22/2 f ( ) = 1 w s v u t z 3/33/3 2/92/9 0/10/1 2/32/3 2/72/7 2/62/6 4/54/5 1/11/1 3/53/5 2/22/2 | f | = 7 | f | = 8 Maximum Flow
10
Ford-Fulkerson’s Algorithm 10 Initially, f(e) 0 for each edge e Repeatedly Search for an augmenting path Augment by f ( ) the flow along the edges of A specialization of DFS (or BFS) searches for an augmenting path An edge e is traversed from u to v provided f (u, v) 0 Algorithm FordFulkersonMaxFlow(N) for all e G.edges() setFlow(e, 0) while G has an augmenting path { compute residual capacity of } for all edges e { compute residual capacity of e } if e is a forward edge of getCapacity(e) getFlow(e) else { e is a backward edge } getFlow(e) if < { augment flow along } for all edges e if e is a forward edge of setFlow(e, getFlow(e) ) else { e is a backward edge } setFlow(e, getFlow(e) ) Maximum Flow
11
Example - Try a greedy algorithm, but be unlucky 11 w s v u t z 0/20/2 0/20/2 0/30/3 0/20/2 0/30/3 0/30/3 0/50/5 0/40/4 0/50/5 0/40/4
12
Example 12 w s v u t z 0/20/2 0/20/2 0/30/3 0/20/2 3/33/3 0/30/3 2/52/5 3/43/4 5/55/5 2/42/4 w s v u t z 2/22/2 2/22/2 0/30/3 2/22/2 3/33/3 2/32/3 4/54/5 3/43/4 5/55/5 2/42/4 w s v u t z 0/20/2 2/22/2 2/32/3 0/20/2 3/33/3 2/32/3 4/54/5 3/43/4 5/55/5 2/42/4 w s v u t z 0/20/2 0/20/2 0/30/3 0/20/2 3/33/3 0/30/3 0/50/5 3/43/4 3/53/5 0/40/4 No more forward flow without pushing back
13
Example (cont) 13 w s v u t z 2/22/2 2/22/2 0/30/3 2/22/2 3/33/3 2/32/3 4/54/5 3/43/4 5/55/5 2/42/4 w s v u t z 2/22/2 2/22/2 2/32/3 2/22/2 3/33/3 3/33/3 5/55/5 2/42/4 5/55/5 3/43/4 Notice: This is clearly optimal, as the arcs into t (and leaving s) are filled. If ANY cut is maxed out, we can’t do better. Notice the effects of pushing backwards along an arc. We don’t REALLY require the flow goes forward and then backward. It is like we could change our mind while still making progress.
14
Analysis 14 In the worst case, Ford- Fulkerson’s algorithm performs |f*| flow augmentations, where f* is a maximum flow Example The augmenting paths found alternate between 1 and 2 The algorithm performs 100 augmentations Finding an augmenting path and augmenting the flow takes O(n m) time The running time of Ford- Fulkerson’s algorithm is O(|f*|(n m)) t s v u 1/11/1 1/50 0/50 1/50 0/50 t s v u 0/10/1 1/50 11 22 Maximum Flow
15
Ford-Fulkerson Algorithm Details 15 Traversal can DFS or BFS, modify graph to include out- edges whose capacity is unused capacity and reversed flow edges who capacity is the flow they carry Might only increase flow by 1 each time O(|f*|m), pseudo-polynomial time (depends on the magnitude of a parameter not its encoding size) Maximum Flow
16
Edmonds-Karp Algorithm 16 Find the best augmenting paths, those with the fewest of edges. Greedy algorithm, like Prim’s. Each time we choose a path, the number of edges along an augmenting path to any vertex can’t decrease. But in turn, this implies that no edge can be a bottleneck (the smallest capacity) more than n times. m edges can be a bottleneck n times O(nm 2 ) Maximum Flow
17
Matchings 17 Kindergarten Teacher needs partners for a field trip Maximum Flow
18
Maximum Bipartite Matching 18 Bipartite graphs – edges only between elements of two separate sets of vertices Example:Jobs and Students. WorkAt edges link Students to Job. Can’t have edges from Students to Students. Dancing, room scheduling (maximum number of classes simultaneously) What if company has two jobs to fill? Maximum Flow
19
Bipartite matching 19 In a bipartite match, all arcs go between verticies of different sets. You want to maximize the number of matches Sometimes a bipartite matching problem is modeled as a network flow problem. Can you see how? Maximum Flow
20
Maximum Bipartite Matching, solved by maximum flow 20 Direct edges, assign capacity 1 Add source, sink, add edges to/from other nodes with capacity m. Find maximal flow for maximal matching Conservation => no sharing of vertices Use regular FordFulkerson as flow is quite small. O(f*m) but our F* is <n/2 O(nm) Maximum Flow
21
Maximum Bipartite Matching (transform into network flow) x: students y:jobs arc: “will work/will hire” 21 Maximum Flow
22
Maximum Bipartite Matching (transform into network flow) x: students y:jobs arc: “will work/will hire” 22 Maximum Flow
23
Minimum Cost flow (another version of network flow) 23 Add another “weight”, called cost, to edges to denote the cost to send a unit of flow along that leg. Now, the cost of a flow is the sum of products of flow and costs on all edges the cost of an augmenting path is the sum of forward edge costs minus the sum of backward costs We want minimal cost for a given |f| An augmenting cycle for a flow has same |f| (since it’s a cycle) but lower flow cost Maximum Flow
24
Augmenting Cycles 24 Given an augmenting cycle, there is a new flow whose value is the same but whose cost is augmented by w(γ) f Δ(γ) A flow is minimum cost there is no negative-cost augmenting cycle for it Maximum Flow
25
Bellman-Ford Algorithm (recall from chapter 7) 25 A better idea is just to continually add the cheapest augmenting paths Works even with negative- weight edges Initially all nodes are Must assume directed edges (for otherwise we would have negative-weight cycles) Iteration i finds all shortest paths that use i edges. Running time: O(nm). Algorithm BellmanFord(G, s) for all v G.vertices() if v s setDistance(v, 0) else setDistance(v, ) for i 1 to n-1 do for each e =(u,z) G.edges() { relax edge e } r getDistance(u) weight(e) if r getDistance(z) setDistance(z,r) Maximum Flow
26
26 Maximum Flow Residual graph is shown on right Find cheapest path by looking at edge costs. Send maximal flow along that path
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.