1 / 37

Maximum Flow

Maximum Flow. Graph Theory Basics. - Anil Kishore. Prerequisites . What is a Graph Directed , Weighted graphs How to traverse a graph using Depth First Search ( DFS ) Breadth First Search ( BFS ). Terms related to Network Flow. A network of water pipes and junctions.

dieter
Download Presentation

Maximum Flow

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MaximumFlow Graph Theory Basics - Anil Kishore

  2. Prerequisites • What is a Graph • Directed, Weighted graphs • How to traverse a graph using • Depth First Search ( DFS ) • Breadth First Search ( BFS )

  3. Terms related to Network Flow • A network of water pipes and junctions • Maximum amount of water • a pipe allows is its Capacity • Actual amount of water in • a particular instance is its flow Flowe ≤ Capacitye A 3 3 1 5 2 B S C T Source Sink 4 3 2 D E Augment : to make or become greater in number, amount, strength, etc.; increase

  4. What is MaxFlow? • Given a network of water pipes ( some fat, some slim etc., ) • find the maximum amount of water that can flow from S to T • Source produces • Sink consumes • Others neither • produce nor consume Source : in Flow = 0 Sink : out Flow = 0 Others : in Flow = out Flow ∴ Flow out of Source = Flow in to Sink

  5. Find MaxFlow A 3 3 1 5 2 S B C T Source Sink 4 3 D E 2

  6. here is the MaxFlow A 2/3 2/3 1/1 0/5 2/2 3 3 S B C T Source Sink 1/4 1/3 D E 1/2 flow / cap

  7. how can we find theMaxFlow ? …by keep sending some positive flow from Source to Sink 4 7 3 S B C T If we send flow = 1 1/4 1/7 1/3 S B C T instead, look at capacity left 3 6 2 S B C T How much more can we send ? Minimum capacity of an edge along the path 1 4 0 S B C T

  8. keep increasing the flow So all we need to do is, } “ Find a path from Source to Sink having edge with minimum capacity left > 0 ” Augmenting Path ALGORITHM While ( there is an augmenting path P ) { Increase flow along P and adjust capacities left } we are almost done.. just one more observation

  9. Running MaxFlow A 3 3 1 5 2 S B C T Source Sink 4 3 D E 2 flow = 0

  10. Running MaxFlow A 3 3 1 5 2 S B C T Source Sink 4 3 D E 2 flow = 0

  11. Running MaxFlow A 3 3 0 4 1 S B C T Source Sink 4 3 D E 2 flow = 1

  12. Running MaxFlow A 3 3 0 4 1 S B C T Source Sink 4 3 D E 2 flow = 1

  13. Running MaxFlow A 2 2 0 4 0 S B C T Source Sink 4 3 D E 2 flow = 2

  14. Running MaxFlow A 2 2 0 4 0 S B C T Source Sink 4 3 D E 2 flow = 2 There seems to be no augmenting path now, but MaxFlow was 3

  15. Running MaxFlow We can try to increase flow along green edges, but cap(CT) = 0 already  A 2 2 0 4 0 S B C T Source Sink 4 3 D E 2

  16. Running MaxFlow There is flow = 1 along red path already, but can it find some other way A 2 2 0 4 0 S B C T Source Sink 4 3 D E 2

  17. Running MaxFlow Yes ! A 2 2 0 4 0 S B C T Source Sink 4 3 D E 2

  18. Running MaxFlow Hey ! If possible, divert some of your flow to other path A 2 2 0 4 0 S B C T Source Sink 4 3 D E 2

  19. Running MaxFlow A 1 1 0 5 0 S B C T Source Sink 3 2 D E 1 After diversion of some existing flow, we can increase overall flow to 3 Diversion looks complex.. lets simplify it by adding additional edges

  20. Residual Graph Edges with capacity left c A B after sending f flow c - f A B f maximum you can send back if needed

  21. after flow = 2, the residual graph 1 1 A 2 2 2 1 0 4 0 S B C T Source Sink 0 0 4 3 1 0 D E 2 flow = 2

  22. now here is one more augmenting path 1 1 A 2 2 2 1 0 4 0 S B C T Source Sink 0 0 4 3 1 0 D E 2 flow = 2

  23. after augmenting 2 2 A 2 1 1 0 0 5 0 S B C T Source Sink 1 1 3 2 1 1 D E 1 flow = 3

  24. No more augmenting paths 2 2 A 2 1 1 0 0 5 0 S B C T Source Sink 1 1 3 2 1 1 D E 1 flow = 3

  25. its actually very simple finally ! ALGORITHM While ( there is an augmenting path P in residual network ) { Increase flow along P and adjust capacities left } u v Adjust : Sending f flow from u to v Cap[u][v] - = f Cap[v][u] + = f

  26. a simple application(its not always water that flows ) A company owns a factory located in city X where products are manufactured that need to be transported to the distribution center in city Y. You are given the one-way roads that connect pairs of cities in the country, and the maximum number of trucks that can drive along each road. What is the maximum number of trucks that the company can send to the distribution center

  27. some commonly used algorithms source : Wikipedia All that matters is which augmenting path to choose now !

  28. Standard Variations, Applications and Theorems onMaxFlow

  29. Multiple Sources / Sinks • Add a Super Source and a Super Sink and corresponding edges between them • Restriction on maximum amount a Source can produce / maximum amount a Sink can consume, can be added as corresponding edge capacities

  30. Vertex Capacities • In the truck example : in addition to “maximum number of trucks that can drive along each road” there can also be, “maximum number of trucks that can drive through a city” v Capacity of v = C vout C vin split the vertex

  31. Disjoint paths • If all edges have unit capacity then MaxFlow = Maximum number of edge disjoint paths from S to T • Adding unit capacity to each vertex, similarly • MaxFlow = Maximum number of vertex disjoint paths • from S to T

  32. Min-Cut • Min-Cut : Given a weighted directed graph, remove a minimum-weighted set of edges in such a way that S is unreachable from T A 3 3 Find a Min-Cut : 1 5 2 S B C T Source Sink 4 3 D E 2

  33. Max-Flow-Min-Cut Theorem Maximum Flow = Minimum Cut A 3 3 Min-Cut = 3 1 5 2 S B C T Source Sink 4 3 D E 2

  34. Maximum Bipartite Matching • Find maximum cardinality matching (independent edges) in a bipartite graph

  35. Maximum Bipartite Matching • Find maximum cardinality matching (independent edges) in a bipartite graph Max Bipartite Matching = Max Flow from S to T

  36. other related theorems • Konig’s Theorem : In any bipartite graph, the number of edges in a • maximum matching equals the number of vertices in a • minimum vertex cover. • Hall’s Theorem : For a set W of vertices of G, let NG(W) denote the • neighborhood of W in G, i.e. the set of all vertices adjacent to some • element of W. An X-saturating matching exists if and only if for every • subset W of X • In other words every subset W of X has enough adjacent vertices in Y. • Dilworth's Theorem : In any finite partially ordered set, the maximum • number of elements in any antichain equals the minimum number of • chains in any partition of the set into chains. |Chain Cover Set| = |V| - |Max Bipartite Matching|

  37. References • Introduction to Algorithms Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein • Topcoder Tutorial http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=maxFlow • http://en.wikipedia.org/wiki/K%C3%B6nig%27s_theorem_%28graph_theory%29 • http://en.wikipedia.org/wiki/Dilworth%27s_theorem • http://en.wikipedia.org/wiki/Hall%27s_marriage_theorem • Baseball-Elimination problem, Cycle cover End

More Related