maximum flow n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Maximum Flow PowerPoint Presentation
Download Presentation
Maximum Flow

Loading in 2 Seconds...

play fullscreen
1 / 37

Maximum Flow - PowerPoint PPT Presentation


  • 90 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Maximum Flow' - dieter


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
maximum flow

MaximumFlow

Graph Theory Basics

- Anil Kishore

prerequisites
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
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

what is maxflow
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

find maxflow
Find MaxFlow

A

3

3

1

5

2

S

B

C

T

Source

Sink

4

3

D

E

2

here is the maxflow
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

how can we find the maxflow
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

keep increasing the flow
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

running maxflow
Running MaxFlow

A

3

3

1

5

2

S

B

C

T

Source

Sink

4

3

D

E

2

flow = 0

running maxflow1
Running MaxFlow

A

3

3

1

5

2

S

B

C

T

Source

Sink

4

3

D

E

2

flow = 0

running maxflow2
Running MaxFlow

A

3

3

0

4

1

S

B

C

T

Source

Sink

4

3

D

E

2

flow = 1

running maxflow3
Running MaxFlow

A

3

3

0

4

1

S

B

C

T

Source

Sink

4

3

D

E

2

flow = 1

running maxflow4
Running MaxFlow

A

2

2

0

4

0

S

B

C

T

Source

Sink

4

3

D

E

2

flow = 2

running maxflow5
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

running maxflow6
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

running maxflow7
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

running maxflow8
Running MaxFlow

Yes !

A

2

2

0

4

0

S

B

C

T

Source

Sink

4

3

D

E

2

running maxflow9
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

running maxflow10
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

residual graph
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

slide21

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

slide22

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

slide23

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

slide24

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

slide25

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

a simple application its not always water that flows
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

some commonly used algorithms
some commonly used algorithms

source : Wikipedia

All that matters is which augmenting path to choose now !

multiple sources sinks
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
vertex capacities
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

disjoint paths
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
min cut
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

max flow min cut theorem
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

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

Max Bipartite Matching

=

Max Flow from S to T

other related theorems
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|

references
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