Network Flow How to solve maximal flow and

  • Slides: 22
Download presentation
Network Flow How to solve maximal flow and minimal cut problems

Network Flow How to solve maximal flow and minimal cut problems

What is Network Flow? n n Network Flow is a subsection of graph theory

What is Network Flow? n n 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.

Concepts in Network Flow n n “Sources” are nodes which supply a commodity “Sinks”

Concepts in Network Flow n n “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

An example n What is the maximum flow from A to B? 4 1

An example n What is the maximum flow from A to B? 4 1 4 3 3 A 5 2 B 6 3 2 1 5

The Ford-Fulkerson method n This is a relatively simple way to find maximum flow

The Ford-Fulkerson method n 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

Storing the graph n n n It is easiest to store, for each edge

Storing the graph n n n 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.

Finding a path n n The eventual answer given by this method is not

Finding a path n n 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

Minimum Cuts n n It is sometimes necessary to know the minimum total weight

Minimum Cuts n n 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

To find the minimum cut n n First create the maximum flow graph Select

To find the minimum cut n n 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

An example n Maximal flow in the graph shown earlier 4 1 4 3

An example n Maximal flow in the graph shown earlier 4 1 4 3 3 A 5 2 B 6 3 2 1 5

An example n Choose a path and put flow through it 4 1 4

An example n Choose a path and put flow through it 4 1 4 3 3 A 5 2 B 6 2 2 0 5

An example n Current flow = 1 4 3 3 A 5 2 B

An example n Current flow = 1 4 3 3 A 5 2 B 6 2 2 0 5

An example n Current flow = 3 4 1 4 3 3 A 3

An example n Current flow = 3 4 1 4 3 3 A 3 0 B 4 0 2 2 2 0 5

An example n Current flow = 3 4 1 4 3 3 A 3

An example n Current flow = 3 4 1 4 3 3 A 3 0 B 4 0 2 2 2 0 5

An example n Current flow = 5 4 1 2 3 1 A 3

An example n Current flow = 5 4 1 2 3 1 A 3 0 B 4 0 0 0 2 0 5

An example n Total flow = 5 4 1 2 3 1 A 3

An example n Total flow = 5 4 1 2 3 1 A 3 0 B 4 0 0 0 2 0 5

An example n To find a minimal cut 4 1 [3] [4] [2] 2

An example n To find a minimal cut 4 1 [3] [4] [2] 2 3 1 A 0 0 3 [5] B [6] [3] 4 [2] 0 [3] 0 2 [1] 0 5

An example n Minimal cut = 1 + 2 = 5 4 1 2

An example n Minimal cut = 1 + 2 = 5 4 1 2 3 2 A 2 2 B 2 3 2 1 5

Variations on Network Flow n Undirected graphs – give the edge the capacity in

Variations on Network Flow n Undirected graphs – give the edge the capacity in both directions, then increase or decrease this capacity as flow changes, as before.

Variations on Network Flow n Multiple sources / sinks – create a “supersource” or

Variations on Network Flow n Multiple sources / sinks – create a “supersource” or “supersink” which connects directly to each of these nodes, and has infinite capacity S 3 3 5 5

Variations on Network Flow Node capacity – split the node into an “in” node,

Variations on Network Flow Node capacity – split the node into an “in” node, an “out” node and an edge n 2 1 4 5 3 2 4 1 5 3

Conclusion n n Network flow problems can come in a number of forms, usually

Conclusion n n 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.