Presentation is loading. Please wait.

Presentation is loading. Please wait.

Maximum Flow - Anil Kishore Graph Theory Basics. Prerequisites What is a Graph Directed, Weighted graphs How to traverse a graph using – Depth First Search.

Similar presentations


Presentation on theme: "Maximum Flow - Anil Kishore Graph Theory Basics. Prerequisites What is a Graph Directed, Weighted graphs How to traverse a graph using – Depth First Search."— Presentation transcript:

1 Maximum Flow - Anil Kishore Graph Theory Basics

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 Flow e ≤ Capacity e 2 S A BC DE T 3 152 4 3 3 SourceSink 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 2 S A BC DE T 3 1 52 4 3 3 SourceSink

6 here is the MaxFlow 1 /2 S A BC DE T 2 /3 1 /1 0 /5 2 /2 1 /4 2 /3 1 /3 SourceSink flow / cap 3 3

7 how can we find the MaxFlow ? …by keep sending some positive flow from Source to Sink SBCT 4 73 If we send flow = 1 SBCT 1 /4 1 /7 1 /3 instead, look at capacity left SBCT 3 62 How much more can we send ? Minimum capacity of an edge along the path SBCT 1 40

8 keep increasing the flow ALGORITHM “ Find a path from Source to Sink having edge with minimum capacity left > 0 ” So all we need to do is, } Augmenting Path 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 2 S A BC DE T 3 1 52 4 3 3 SourceSink flow = 0

10 Running MaxFlow 2 S A BC DE T 3 1 52 4 3 3 SourceSink flow = 0

11 Running MaxFlow 2 S A BC DE T 3 0 41 4 3 3 SourceSink flow = 1

12 Running MaxFlow 2 S A BC DE T 3 0 41 4 3 3 SourceSink flow = 1

13 Running MaxFlow 2 S A BC DE T 2 0 40 4 2 3 SourceSink flow = 2

14 Running MaxFlow 2 S A BC DE T 2 0 40 4 2 3 SourceSink flow = 2 There seems to be no augmenting path now, but MaxFlow was 3

15 Running MaxFlow 2 S A BC DE T 2 0 40 4 2 3 SourceSink We can try to increase flow along green edges, but cap(CT) = 0 already 

16 Running MaxFlow 2 S A BC DE T 2 0 40 4 2 3 SourceSink There is flow = 1 along red path already, but can it find some other way

17 Running MaxFlow 2 S A BC DE T 2 0 40 4 2 3 SourceSink Yes !

18 Running MaxFlow 2 S A BC DE T 2 0 40 4 2 3 SourceSink Hey ! If possible, divert some of your flow to other path

19 Running MaxFlow 1 S A BC DE T 1 0 50 3 1 2 SourceSink 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 AB c AB f c - f after sending f flow Edges with capacity left maximum you can send back if needed

21 2 S A BC DE T 2 0 40 4 2 3 SourceSink flow = 2 after flow = 2, the residual graph 1 1 2 1 1 0 0 0

22 2 S A BC DE T 2 0 40 4 2 3 SourceSink flow = 2 now here is one more augmenting path 1 1 2 1 1 0 0 0

23 1 S A BC DE T 1 0 50 3 1 2 SourceSink flow = 3 after augmenting 2 2 2 1 0 1 1 1

24 1 S A BC DE T 1 0 50 3 1 2 SourceSink flow = 3 No more augmenting paths 2 2 2 1 0 1 1 1

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 } Adjust : uv 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 on MaxFlow

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 v in C v out 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 S A BC DE T 3 1 52 4 3 3 SourceSink Find a Min-Cut : 2

33 Maximum Flow = Minimum Cut S A BC DE T 3 1 52 4 3 3 SourceSink Min-Cut = 3 2 Max-Flow-Min-Cut Theorem

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 N G (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=tutori als&d2=maxFlow http://community.topcoder.com/tc?module=Static&d1=tutori als&d2=maxFlow http://en.wikipedia.org/wiki/K%C3%B6nig%27s_theorem_%2 8graph_theory%29 http://en.wikipedia.org/wiki/K%C3%B6nig%27s_theorem_%2 8graph_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


Download ppt "Maximum Flow - Anil Kishore Graph Theory Basics. Prerequisites What is a Graph Directed, Weighted graphs How to traverse a graph using – Depth First Search."

Similar presentations


Ads by Google