120 likes | 322 Views
s. 2. 3. 1. a. b. 3. 2. 4. c. d. Determine the maximum amount of flow that can pass from s to t . 2. 3. t. §4 Network Flow Problems. 〖 Example 〗 Consider the following network of pipes:. source. Note: Total coming in ( v ) Total going out ( v )
E N D
s 2 3 1 a b 3 2 4 c d Determine the maximum amount of flow that can pass from s to t. 2 3 t §4 Network Flow Problems 〖Example〗 Consider the following network of pipes: source Note: Total coming in (v) Total going out (v) where v { s, t } sink 1/10
§4 Network Flow Problems s s s 2 3 1 a b a a b b 3 2 4 c d c d c d 2 3 t t t G Flow Gf Residual Gr 1. A Simple Algorithm Step 1: Find any path s t in Gr; Step 4: If (there is a path s t in Gr ) Goto Step 1; Else End. Step 2: Take the minimum edge on this path as the amount of flow and add to Gf; augmenting path Step 3: Update Grand remove the 0 flow edges; 2/10
§4 Network Flow Problems s 2 3 1 a b 3 2 4 c d 2 3 t G You are right! What if I pick up the path s a d t first? It is simple indeed. But I bet that you will point out some problems here… Uh-oh… Seems we cannot be greedy at this point. 3/10
§4 Network Flow Problems For each edge ( v, w ) with flow fv, w in Gf, add an edge ( w, v ) with flow fv, w in Gr. s s 2 3 1 a b a s b 3 2 3 2 3 2 3 2 4 1 c d a b c d 2 2 2 3 4 2 2 3 2 3 2 3 c d t t 2 3 3 2 G 3 Flow Gf 2 t Residual Gr 2. A Solution – allow the algorithm to undo its decisions 3 1 1 1 〖Proposition〗If the edge capabilities are rational numbers, this algorithm always terminate with a maximum flow. Note: The algorithm works for G with cycles as well. 4/10
§4 Network Flow Problems s 1 000 000 1 000 000 1 a b 1 000 000 1 000 000 t 3. Analysis ( If the capacities are all integers ) An augmenting path can be found by an unweighted shortest path algorithm. T = O( ) where f is the maximum flow. f · |E| Always choose the augmenting path that allows the largest increase in flow. /* modify Dijkstra’s algorithm */ T = Taugmentation * Tfind a path = O( |E| log capmax) * O( |E| log |V| ) = O( |E|2 log |V| ) if capmax is a small integer. 5/10
§4 Network Flow Problems Always choose the augmenting path that has the least number of edges. Home work: p.341 9.11 A test case. T = Taugmentation * Tfind a path = O( |E| ) * O( |E| · |V| ) /* unweighted shortest path algorithm */ = O( |E|2 |V| ) • Note: • If every v { s, t } has either a single incoming edge of capacity 1 or a single outgoing edge of capacity 1, then time bound is reduced to O( |E| |V|1/2 ). • The min-cost flow problem is to find, among all maximum flows, the one flow of minimum cost provided that each edge has a cost per unit of flow. 6/10
§5 Minimum Spanning Tree 【Definition】 A spanning tree of a graph G is a tree which consists of V( G ) and a subset of E( G ) 〖Example〗 A complete graph and three of its spanning trees • Note: • The minimum spanning tree is a tree since it is acyclic -- the number of edges is |V| – 1. • It is minimum for the total cost of edges is minimized. • It is spanning because it covers every vertex. • A minimum spanning tree exists iff G is connected. • Adding a non-tree edge to a spanning tree, we obtain a cycle. 7/10
§5 Minimum Spanning Tree 2 v1 v2 4 1 3 10 7 2 v3 v4 v5 4 8 5 6 1 v6 v7 Greedy Method Make the best decision for each stage, under the following constrains : (1) we must use only edges within the graph; (2) we must use exactly |V| 1 edges; (3) we may not use edges that would produce a cycle. 1. Prim’s Algorithm – grow a tree /* very similar to Dijkstra’s algorithm */ 8/10
§5 Minimum Spanning Tree 2. Kruskal’s Algorithm – maintain a forest void Kruskal ( Graph G ) { T = { } ; while ( T contains less than |V| 1 edges && E is not empty ) { choose a least cost edge (v, w) from E ; delete (v, w) from E ; if ( (v, w) does not create a cycle in T ) add (v, w) to T ; else discard (v, w) ; } if ( T contains fewer than |V| 1 edges ) Error ( “No spanning tree” ) ; } T = O( |E| log |E| ) Home work: p.341 9.15 A test case and a discussion on uniqueness. /* DeleteMin */ /* Union / Find */ A more detailed pseudocode is given by Figure 9.58 on p.321 9/10
§5 Minimum Spanning Tree Laboratory Project 6 Electric Wiring Due: Thursday, December 21st, 2006 at 10:00pm Detailed requirements can be downloaded from http://10.71.45.99/list.asp?boardid=47 Courseware Download Don’t forget to sign you names and duties at the end of your report. 10/10