network flow - university of cape...

21
Network Flow Maximum Flow Minimum Cut

Upload: phamtram

Post on 02-Jun-2019

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

Network Flow

Maximum FlowMinimum Cut

Page 2: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

What is Network Flow?

Graph Theory Flow Direction A -> B e.g. Water flowing through pipes

Page 3: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

Concepts and Definitions

“Source” – Node in the graph emitting the “flow”

“Sink” – Node in the graph consuming the “flow”

“Capacity” – the maximum amount of “flow” that can pass through this edge/node.

“Flow” – the amount of material passing through this node/edge/graph.

Page 4: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

Max Flow Problem

What is the maximum flow from A to B?

A B

1

2

3

5

4

3

3 6

4 2 5

3

1

2

Page 5: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

Ford-Fulkerson

Simple Initialize all flow counts to 0. While there is an unsaturated path from source

to sink: Find the minimum capacity of all edges in that

path Increment the flow count of each edge in that

path by the minimum Increment the global flow count by that

minimum The total amount of flow in the global flow

count is then maximum

Page 6: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

Storage

For each edge store: Capacity Current flow

Undirected Depends on problem for optimal storage Store 2 flows (positive and negative) or

sometimes 2 capacities. Depending on problem, positive may cancel

out negative and vice versa.

Page 7: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

Finding the path

Method does not affect answer Affects running time

Good choices (depending on problem) Shortest path (BFS) Path with maximum flow DFS - simplest

Page 8: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

An example

Determining maximal flow in the graph shown earlier

A B

1

2

3

5

4

3

3 6

4 2 5

3

1

2

Page 9: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

An example

Choose a path and put flow through it

A B

1

2

3

5

4

3

2 6

4 2 5

2

0

2

Page 10: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

An example

Current flow = 1

A B

1

2

3

5

4

3

2 6

4 2 5

2

0

2

Page 11: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

An example

Current flow = 3

A B

1

2

3

5

4

3

0 4

4 0 3

2

0

2

Page 12: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

An example

Current flow = 3

A B

1

2

3

5

4

3

0 4

4 0 3

2

0

2

Page 13: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

An example

Current flow = 5

A B

1

2

3

5

4

1

0 4

2 0 3

0

0

0

Page 14: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

An example

Total flow = 5

A B

1

2

3

5

4

1

0 4

2 0 3

0

0

0

Page 15: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

Minimum Cuts

Maximum flow problems are tied in with Minimum Cut problems

Minimum Cut The minimum weighting of edges that

separates two nodes (in this case source and sink)

Sum of the weighting of cut edges = maximum flow through the network

Page 16: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

An example

Minimal cut = 1 + 2 + 2 = 5

A B

1

2

3

5

4

2

3 2

2 2 2

3

1

2

Page 17: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

To find the minimum cut

Create the maximum flow graph Select all nodes that can be reached

from the source by unsaturated edges

Cut all the edges that connect these nodes to the rest of the nodes in the graph

This cut will be minimal

Page 18: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

An example

To find a minimal cut

A B

1

2

3

5

4

1

0 4

2 0 3

0

0

0

[3]

[3]

[4]

[6]

[1]

[3][2]

[2]

[5]

Page 19: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

Variations on Network Flow

Multiple sources & sinks – create a “supersource” or “supersink” which connects directly to each of these nodes, and has infinite capacity

S3

5

3

5

Page 20: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

Variations on Network Flow

Node capacity – split the node into an “in” node, an “out” node and an edge

41

5 3

2

1

5 3

24

Page 21: Network Flow - University of Cape Townolympiad.cs.uct.ac.za/presentations/camp2_2008/networkflow.pdfFord-Fulkerson Simple Initialize all flow counts to 0. While there is an unsaturated

Conclusion

Network flow problems Graph Theory Transporting some material from A to B Along pathways (edges) that have

capacities Maximum flow is that maximum

amount of material that can be transported from A to B.