algorithms 2il15 lecture 7 maximum flow
play

Algorithms (2IL15) Lecture 7 MAXIMUM FLOW 1 TU/e Algorithms - PowerPoint PPT Presentation

TU/e Algorithms (2IL15) Lecture 7 Algorithms (2IL15) Lecture 7 MAXIMUM FLOW 1 TU/e Algorithms (2IL15) Lecture 7 Part II of the course: optimization problems on graphs 2 1 single-source shortest paths 2 1 Find shortest


  1. TU/e Algorithms (2IL15) – Lecture 7 Algorithms (2IL15) – Lecture 7 MAXIMUM FLOW 1

  2. TU/e Algorithms (2IL15) – Lecture 7 Part II of the course: optimization problems on graphs − 2 1 single-source shortest paths 2 1 Find shortest path from source vertex 2 to all other vertices 2.3 4 all-pairs shortest paths Find shortest paths between all pairs of vertices 4 maximum flow 3 1 5 Find maximum flow from source vertex 3 2 8 to target vertex 3 maximum bipartite matching Find maximum number of disjoint pairs of vertices with edge between them 2

  3. TU/e Algorithms (2IL15) – Lecture 7 Single-Source Shortest Paths Bellman-Ford algorithm  can handle negative edge weights, works even for negative-weight cycles  running time Θ ( | V | ∙ | E | ) Dijkstra’s algorithm  works only for non-negative edge weights  running time Θ ( | V | log | V | + | E | ) All-Pairs Shortest Paths Dynamic-programming algorithms  connection to matrix-multiplication  improved version (repeated squaring) runs in Θ ( | V | 3 log | V | ) time  different subproblems give simple Θ ( | V | 3 )-time algorithm (Floyd-Warshall) Johnson’s algorithm: reweighting  modify graph to make all edge-weights non-negative  then run Dijkstra’s algorithm | V | times  running time Θ ( | V | 2 log | V | + | V | ∙ | E | ) 3

  4. TU/e Algorithms (2IL15) – Lecture 7 The maximum-flow problem sink source How much flow we can push through the network?  edges are directed and have a maximum capacity  source is generating the flow, sink is consuming it  all flow arriving at a node must also leave the node, except at sink 4

  5. TU/e Algorithms (2IL15) – Lecture 7 3 2 10 2 3 t s sink source 2 1 5 5 3 Flow network: directed graph G = ( V, E ), where  each edge (u,v) in E has a capacity c ( u,v ) ≥ 0 − define c ( u,v )=0 if ( u,v ) not in E  there are two special nodes in V : the source s and the sink t  if ( u,v ) in E then ( v,u ) not in E trick: insert node on edge  Assume that any node u can be reached from s and can reach t Note: G can have cycles 5

  6. TU/e Algorithms (2IL15) – Lecture 7 2 / 3 2 / 2 4 / 10 2 / 2 3 / 3 t s sink source 2 / 2 1 / 1 5 1 / 1 / 5 0 / 3 flow = 1, capacity = 5 Flow: function f : V x V → R satisfying  capacity constraint : 0 ≤ f ( u,v ) ≤ c ( u,v ) for all nodes u,v ( Hence, f ( u,v ) = 0 if edge ( u,v ) does not exist. )  flow conservation: for all nodes u ≠ s, t we have flow in = flow out: ∑ v in V f ( v,u ) = ∑ v in V f ( u,v ) value of flow: | f | = ∑ v in V f ( s,v ) − ∑ v in V f ( v,s ) 6

  7. TU/e Algorithms (2IL15) – Lecture 7 Flow: function f : V x V → R satisfying  capacity constraint : 0 ≤ f ( u,v ) ≤ c ( u,v ) for all nodes u,v ( Hence, f ( u,v ) = 0 if edge ( u,v ) does not exist. )  flow conservation: for all nodes u ≠ s, t we have flow in = flow out: ∑ v in V f ( v,u ) = ∑ v in V f ( u,v ) value of flow: | f | = ∑ v in V f ( s,v ) − ∑ v in V f ( v,s ) Can there be flow if all outgoing edges from the source have zero flow? 0 / 2 0 / 3 2 / 2 s t 2 / 5 2 / 3 7

  8. TU/e Algorithms (2IL15) – Lecture 7 Idea for computing max flow incrementally  start with zero flow  repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path 0 / 3 0 / 2 0 / 2 0 / 3 0 / 2 t s sink source 0 / 6 0 / 1 5 0 / 0 / 5 0 / 3 Total flow: 0 8

  9. TU/e Algorithms (2IL15) – Lecture 7 Idea for computing max flow incrementally  start with zero flow  repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path 0 / 3 0 / 2 2 / 2 3 2 / 2 / 2 t s sink source FULL 0 / 6 0 / 1 5 0 / 0 / 5 0 / 3 Total flow: 0 + 2 9

  10. TU/e Algorithms (2IL15) – Lecture 7 Idea for computing max flow incrementally  start with zero flow  repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path 0 / 3 0 / 2 2 / 2 2 / 3 2 / 2 t s sink source FULL 0 / 6 0 / 1 5 0 / 0 / 5 0 / 3 Total flow: 0 + 2 10

  11. TU/e Algorithms (2IL15) – Lecture 7 Idea for computing max flow incrementally  start with zero flow  repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path 0 / 3 0 / 2 2 / 2 2 / 3 2 / 2 t s sink source FULL 5 / 6 5 / 1 5 0 / 5 / 5 FULL 0 / 3 Total flow: 0 + 2 + 5 11

  12. TU/e Algorithms (2IL15) – Lecture 7 Idea for computing max flow incrementally  start with zero flow  repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path stuck ! we need to decrease flow along an edge do we have max flow? no 0 / 3 0 / 2 2 / 2 2 / 3 2 / 2 t s sink source FULL 5 / 6 5 / 1 5 0 / 5 / 5 FULL 0 / 3 Total flow: 0 + 2 + 5 12

  13. TU/e Algorithms (2IL15) – Lecture 7 Idea for computing max flow incrementally  start with zero flow  repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path trick: decrease flow along edge = send flow along reverse edge 0 / 3 0 / 2 2 / 2 2 / 3 2 / 2 t s sink source FULL 5 / 6 5 / 1 5 0 / 5 / 5 FULL 0 / 3 Total flow: 0 + 2 + 5 13

  14. TU/e Algorithms (2IL15) – Lecture 7 Idea for computing max flow incrementally  start with zero flow  repeat until stuck − find path from s to t along which we can increase the flow − increase flow along the path trick: decrease flow along edge = send flow along reverse edge 1 / 3 1 / 2 2 / 2 1 / 3 1 2 / 2 t s sink source FULL 6 / 6 5 / 1 5 1 / 5 / 5 FULL 0 / 3 Total flow: 0 + 2 + 5 + 1 14

  15. TU/e Algorithms (2IL15) – Lecture 7 The Ford-Fulkerson method work with residual network G f  original edges  reverse edges: sending flow along such an edge = decreasing flow along original edge Ford-Fulkerson-Method ( G, s, t ) 1. Initialize flow: set f ( u,v ) = 0 for each pair ( u,v ) in V x V 2. while there is an augmenting path p in the residual network G f 3. do increase flow by augmenting flow along p 4. return f 15

  16. TU/e Algorithms (2IL15) – Lecture 7  G = ( V,E ) is flow network with source s and sink t  f = flow on G residual capacity of pair of vertices u,v in G ( for the given flow f ) c ( u,v ) − f ( u,v ) if ( u,v ) in E // original edge c f ( u,v ) = f ( u,v ) if ( v,u ) in E // reverse edge 0 otherwise well defined because ( u,v ) and ( v,u ) cannot both be in E 2 / 2 c f = 0 2 / 3 c f = 1 s t c f = 2 c f = 2 1 / 2 0 / 5 c f = 0 1 / 5 1 / 3 16

  17. TU/e Algorithms (2IL15) – Lecture 7 Residual network of network G with given flow f network G f = ( V, E f ) where E f = { ( u,v ) in V x V : c f ( u,v ) > 0 }  ( u,v ) in E : E f can contain ( u,v ) and/or ( v,u )  ( u,v ) not in E and ( v,u ) not in E : ( u,v ) and ( v,u ) not in E f either 2 / 2 c f = 0 2 / 3 c f = 1 s t c f = 2 c f = 2 1 / 2 0 / 5 1 / 5 1 / 3 residual network 1 s t 2 2 1 4 5 1 2 1 1 17

  18. TU/e Algorithms (2IL15) – Lecture 7 Let’s look at earlier example, where we had to decrease flow along some edge 0 / 3 0 / 2 2 / 2 2 / 3 2 / 2 t s FULL 5 / 6 5 / 1 5 0 / 5 / 5 FULL 0 / 3 residual network 3 2 2 1 2 2 t s 1 1 5 5 5 3 18

  19. TU/e Algorithms (2IL15) – Lecture 7 flow in residual network G f  should satisfy residual capacity constraints  for each vertex ≠ s,t : flow in = flow out We will only use flows along augmenting path p = simple s -to- t path in G f 3 2 2 1 2 2 t s 1 1 5 5 5 3 residual capacity = 1 residual capacity c f ( p ) of p = amount of flow we can push along p = min { c f ( u,v ): ( u,v ) is an edge of p } 19

  20. TU/e Algorithms (2IL15) – Lecture 7 Augmenting flow f by flow along simple s -to- t path p in G f 3 2 2 1 2 2 s t 1 1 5 5 5 residual capacity = 1 3 for each edge (u,v) on the augmenting path p do if (u,v) in E then increase f ( u,v ) by c f ( p ) else decrease f ( v,u ) by c f ( p ) 1 0 / 3 1 0 / 2 2 / 2 1 2 / 3 2 / 2 s t 6 5 / 6 1 1 0 / 5 / 5 5 / 5 0 / 3 20

  21. TU/e Algorithms (2IL15) – Lecture 7 Lemma: Augmenting flow along simple s- to -t path p gives valid flow in G whose value is (old flow value) + residual capacity c f ( p ). Proof. Must show:  new flow satisfies capacity constraint: 0 ≤ f ( u,v ) ≤ c ( u,v )  new flow satisfies: flow in = flow out  new flow value = (old flow value) + residual capacity c f ( p ). 2 2 1 2 2 s t 1 1 5 5 5 3 c ( u,v ) − f ( u,v ) if ( u,v ) in E c f ( u,v ) = f ( v,u ) if ( v,u ) in E 0 otherwise 21

Recommend


More recommend