Download presentation
Presentation is loading. Please wait.
Published byMark Riley Modified over 9 years ago
1
Network Flow How to solve maximal flow and minimal cut problems
2
What is Network Flow? Network Flow is a subsection of graph theory related specifically to situations where something moves from one location to another. An easily visualized example of network flow is piping system through which a quantity of water must pass.
3
Concepts in Network Flow “Sources” are nodes which supply a commodity “Sinks” are nodes which use up a commodity An edge’s capacity is the maximum amount of flow which can pass through it Graphs are usually directed
4
An example 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
5
The Ford-Fulkerson method This is a relatively simple way to find maximum flow through a network: Find an unsaturated path from the source to the sink Add an amount of flow to each edge in that path equal to the smallest capacity in it Repeat this process till no more paths can be found The total amount of flow added is then maximal
6
Storing the graph It is easiest to store, for each edge in the graph, its capacity in both directions, as well as the current flow in each direction. Thus for a directed graph, the capacity in the reverse direction will start as zero. When flow is put through the edge, decrease its capacity in the direction and increase the capacity in the opposite direction.
7
Finding a path The eventual answer given by this method is not affected by the path chosen, although the algorithm’s speed will be affected If possible, the shortest path or the path with maximum flow is a good choice, else simply using a DFS works reasonably well
8
Minimum Cuts It is sometimes necessary to know the minimum total weight of a cut that splits the graph in two, separating the source and the sink This will be equal to the maximum flow through the network
9
To find the minimum cut First create the maximum flow graph Select all the 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
10
An example Maximal flow in the graph shown earlier A B 1 2 3 5 4 3 3 6 4 2 5 3 1 2
11
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
12
An example Current flow = 1 A B 1 2 3 5 4 3 2 6 4 2 5 2 0 2
13
An example Current flow = 3 A B 1 2 3 5 4 3 0 4 4 0 3 2 0 2
14
An example Current flow = 3 A B 1 2 3 5 4 3 0 4 4 0 3 2 0 2
15
An example Current flow = 5 A B 1 2 3 5 4 1 0 4 2 0 3 0 0 0
16
An example Total flow = 5 A B 1 2 3 5 4 1 0 4 2 0 3 0 0 0
17
An example To find a minimal cut A B 1 2 3 5 4 1 0 4 2 0 3 0 0 0 [3] [4] [6] [1] [3] [2] [5]
18
An example Minimal cut = 1 + 2 + 2 = 5 A B 1 2 3 5 4 2 3 2 2 2 2 3 1 2
19
Variations on Network Flow Undirected graphs – give the edge the capacity in both directions, then increase or decrease this capacity as flow changes, as before.
20
Variations on Network Flow Multiple sources / sinks – create a “supersource” or “supersink” which connects directly to each of these nodes, and has infinite capacity S 3 5 3 5
21
Variations on Network Flow Node capacity – split the node into an “in” node, an “out” node and an edge 4 1 5 3 2 1 5 3 2 4
22
Conclusion Network flow problems can come in a number of forms, usually relating to some commodity being moved from suppliers to where it is needed. Also look for minimal cut problems, which can be solved easily with graph theory.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.