Teaching / Algorithm Design / Network Flow II

Interactive lesson · Chapter 7 · Network Flow

Network Flow II: applications

Max flow and min cut are powerful because so many different problems reduce to them: build the right network, run the algorithm, read the answer off the flow or the cut. Here are six reductions to play with. Each one shows the network that the problem becomes.

For Algorithm Design (FTU, undergraduate). This page goes with the lecture slides 07 Network Flow II by Kevin Wayne. It uses the algorithms from Part I.

Sections: 1 Bipartite matching · 2 Edge-disjoint paths · 3 Project selection · 4 Image segmentation · 5 Baseball elimination · 6 Circulation · 7 The recipe

1 · Matching (slides 6–21)

Bipartite matching and Hall’s theorem

A matching pairs up nodes of L with nodes of R so that nobody is used twice. To find a largest one, add a source s joined to every node of L and a sink t joined from every node of R, give every edge capacity 1, and compute a max flow. A flow of value k is exactly a matching with k edges. An augmenting path in the residual network is an alternating path: it adds new edges and removes (⇠) some matched ones. If the matching cannot be perfect, the min cut hands you a set S ⊆ L with fewer neighbours than members: Hall’s theorem.

Edit: click a left node, then a right node to add or remove an edge · click an edge to remove it

Bipartite graph G green = matched · orange = current path

Flow network G′ all capacities 1

2 · Connectivity (slides 23–38)

Edge-disjoint paths and Menger’s theorem

How many routes from s to t share no edge? Give every edge capacity 1: the max-flow value is exactly the number of edge-disjoint s→t paths. Menger’s theorem says this equals the fewest edges whose removal disconnects t from s: the min cut. Switch to Break it yourself and try to cut s off from t with as few edges as possible.

Show

Network

3 · Min cut as optimisation (slides 64–68)

Project selection

Each project has a profit (+) or a cost (−), and some projects require others first. Choose a set of projects that is closed under the prerequisites and has the largest total profit. The reduction: source → profitable project (capacity = profit), costly project → sink (capacity = cost), and an infinite edge from a project to each of its prerequisites. A set A of chosen projects is legal exactly when no infinite edge leaves A, and then profit = (sum of all profits) − cap(A, B). So the best selection is a minimum cut.

Click a project to select or deselect it

Network shaded = chosen · edge label = capacity (or flow / capacity after solving)

4 · Min cut in pictures (slides 57–62)

Image segmentation

Label every pixel foreground or background. Pixel i prefers the foreground by ai and the background by bi; neighbouring pixels that get different labels pay a penalty p. Maximise (foreground likelihoods) + (background likelihoods) − p·(number of label changes between neighbours). This is a minimum cut: s→i with capacity ai, i→t with capacity bi, and capacity p both ways between neighbours. Deciding pixel by pixel ignores the neighbours; the cut does not.

Image brightness = ai (foreground likelihood)

Pixel by pixel foreground if ai > bi

Minimum cut uses the neighbours

5 · A surprising reduction (slides 70–79)

Baseball elimination

Can team z still finish with the most wins, if it wins all its remaining games? The other games have to be divided so that nobody ends above wz + rz. Network: s → each game node (capacity = games left), game → both team nodes (∞), team x → t (capacity wz + rz − wx, the wins x may still collect). Team z is not eliminated exactly when the max flow saturates all edges out of s. You can edit the standings.

Flow network for the chosen team edge label = flow / capacity

6 · Supplies and demands (slides 41–47)

Circulation with supplies and demands

Some nodes supply goods, others demand them, edges have capacities, and flow must be conserved elsewhere. Is there a feasible way to ship everything? Add a super-source S with an edge to every supply node and a super-sink T from every demand node. Feasible exactly when the max flow saturates all of these new edges. Lower the capacity of the bottleneck edge e→d and watch it become infeasible.

Network with super-source S and super-sink T node labels: supply (−) or demand (+)

7 · Summary

The recipe

ProblemNetworkRead the answer from
Bipartite matchings→L (1), L→R (1), R→t (1)Edges of L→R with flow 1. Min cut gives Hall’s violator.
Edge-disjoint pathsAll capacities 1Decompose the flow into paths. Min cut = Menger’s edge set.
Project selections→profit, cost→t, prerequisites ∞Source side of a min cut. Profit = Σ profits − cut.
Image segmentations→ai, i→t bi, neighbours p both waysSource side of a min cut = foreground.
Baseball eliminations→games, games→teams (∞), teams→tSaturated? If not, the cut names the teams that eliminate z.
Circulation with demandsSuper-source and super-sinkSaturated? Then a feasible circulation exists.

Not yet animated here: survey design and airline scheduling (slides 49–55), edge-disjoint paths in undirected graphs (slides 32–38), and circulation with lower bounds (slides 46–47). They use the same recipe.

Questions to explore

  1. Alternating paths. In the first matching example, which augmentation uses ⇠ arcs? Which matched edges does it undo?
  2. Hall. Remove one edge from a perfect matching example until it breaks. What is the violating set S, and why is it exactly the nodes reachable from s?
  3. Menger. Can you disconnect s from t with fewer edges than the number of disjoint paths? Why not?
  4. Greedy fails. In the open-pit mine, dig the single most valuable block. Is that the best plan?
  5. Penalty. Slide the smoothness penalty from 0 to 8. At p = 0 the min cut equals the pixel-by-pixel labelling. Why?
  6. Elimination. Change Atlanta’s wins. Which teams are eliminated, and which set R of teams proves it?