Now on ScienceBlogs: Rhodes Secretary: Wall Street Megabonuses Draining Our Young Talent

Seed Media Group

Collective Imagination

Good Math, Bad Math

Finding the fun in good math; Shredding bad math and squashing the crackpots who espouse it.

Search

Profile

markcc.jpg
Mark Chu-Carroll (aka MarkCC) is a PhD Computer Scientist, who works for Google as a Software Engineer. My professional interests center on programming languages and tools, and how to improve the languages and tools that are used for building complex software systems.

Donors Choose

Other Information

Add this blog to my Technorati Favorites!

Recent Posts

Recent Comments

Categories

Blogroll

Old Topic Indices

Great Online Books

« The Sierpinski Gasket by Affine | Main | Fractal Dimension »

Maximum Flow and Minimum Cut

Category: Graph Theory
Posted on: August 7, 2007 6:50 PM, by Mark C. Chu-Carroll

I got started on this series about graph theory by writing a post debunking something foolish that George Gilder said about network theory. Today I'm going to talk about one of the classic problems in graph theory, which happens to be a network problem. It's called the maximum flow problem.

The idea is that you have a weighted graph, which is modeling a bunch of places connected by pipes of different sizes. The sizes of the pipes are represented by the weight labels on the edges, which are called capacities. Pick two nodes in the graph, called the source and the sink, how much can you pump from source to sink without exceeding the capacities of the pipes? That value is called the maximum flow of the graph.

The answer, in a sort of naive sense, is obvious: find the bottleneck. In a problem like this, the flow is going to be constrained by some structure - find that, and it's easy to figure out the maximum flow of the graph is: it's the capacity of the bottleneck.

It turns out that that naive answer is actually pretty deep. There's a theory called the max-flow/min-cut theorem which is just a formalized version of "the bottleneck determines the maximum".

cut.png

To state the theorem, first we need to introduce the idea of a cut. Suppose you've got a connected graph, G=(V,E). A cut on G is a way of partitioning V into two disjoint sets. A good way of thinking about it is that any partition of the vertices into disjoint sets is essentially a description of what edges need to be eliminated to split G into two disjoint graphs. The edges between the partitions are called the cut edges. If G is a weighted graph, then a cut on G has a weight. The weight of a cut is the sum of the weights of the cut edges.

So, for example, look at the graph over to the right. The dotted line represents a cut. The weight of the cut is 4+5+9+7+11+7+3=46.

The minimum cut of a weighted graph G is the the cut of the graph with minimum weight. The minimum cut between two vertices v and w in G is the minimum weight cut of G that puts v and w in different partitions. For example, in the graph below, the minimum cut is shown with a green dotted line, and has weight 16. (In the original version of this post, I messed up my hand-simulation of Ford-Fulkerson, and wound with an incorrect result, which was caught by a commenter. That's why I like computers: I can't do this stuff right by hand, but I can write a program to do it!)

max-flow.png

What the max-flow/min-cut theorem says is that the maximum flow in a weighted graph G between a source s and sink k is the weight of the minimum cut of s and k.

Finding the minimum cut of a graph is reasonably easy - I'll show one algorithm that does it in low-order polynomial time. (It's O(V3) for arbitrary weight values; O(Ef), where f is the max flow, for integer values. The latter is generally a lot lower that V2, but there's no guarantee.) But interestingly, finding the maximum cut is NP-complete.

The solution that I'm going to show is called the Ford-Fulkerson algorithm. The simplest version of Ford-Fulkerson is only guaranteed to terminate if the capacities are integers. (There's a refinement of the algorithm, called Edmonds-Karp which is guaranteed to terminate for all weights, but it's easiest to explain the simple Ford-Fulkerson; E-K is basically the same idea.)

The Ford-Fulkerson algorithm is really simple. Basically, find a path from the source to the sink. Find the maximum capacity of that path - that is, the smallest weight of any edge on the path. Subtract that amount of capacity from the edges in the path. Now, repeatedly, search for any path through the graph that, if added to the solution, would increase the flow; that's called an augmenting path. If you can find an augmenting path, then add it to the solution; subtract the capacity of the augmenting path from the edges in the path. When you can't find any more augmenting paths, you'll have the maximum flow. Finding augmenting paths is a relatively straightforward search of the edges of the graph - it takes time O(E). With integer weights, the minimum augmenting flow has weight 1, so there will be no more than f edges.)

flow-reverse.png

There's one tricky point in that algorithm, and I'll demonstrate it with an example. Look at the graph over to the right. Suppose that initially, we start with "ACBD", with a max flow of 3. Then we find that "ABCD" is an augmenting path - adding flow ABCD adds a flow of 6 - but it reverses the flow along edge BC. That leaves a capacity of 4 on AB, 1 on CD, and 0 on BC. Then ABC is an augmenting flow of 3 - leaving 1 and AB, and 0 on BD. Then ACD is an augmenting flow - we can add 1 on AC, and one on CD. So the maximum flow is 6+3+1=10.

Share this: Stumbleupon Reddit Email + More

Comments

1

Isn't the minimum cut of the blue graph {B-Sink,B-G,F-G,H-Sink}, with a weight of 6+2+3+5=16? Or am I missing something?

Posted by: Mark | August 7, 2007 7:43 PM

2

Nope, you're absolutely right. I messed up doing F-F by hand. I'll correct it, thanks!

Posted by: Mark C. Chu-Carroll | August 7, 2007 7:54 PM

3

I'm very surprised that finding the maximum cut is harder than finding the minimum cut. Why couldn't you just transform the weights (for instance, by inverting them), find the minimum cut, and use that as the maximum cut of the original graph?

Posted by: Beren | August 7, 2007 8:41 PM

4

To me, it seems obvious that finding the maximum cut is harder than the minimum cut. That's because the weights have a lower bound of 0, but no upper bound. Right?

Posted by: Steve P. | August 7, 2007 10:42 PM

5

To address Beren's question, that's because the two will not necessarily correspond.

Suppose you have a graph with 4 vertices arranged in a square with edges around the perimeter. The lower left vertex is the source S, the upper right is the destination D. The capacities from source to intermediate nodes are 500,000 and 2, respectively. The capacities from intermediate nodes to destination are both 9. If you invert the capacities, and compute the min cut, you find the cut which isolates D gives the min cut: its capacity is 2/9, while the capacity of the only other cut (which isolates S) is a little more than 1/2. However, thus cut is also the min cut without inverting the graph, obviously.

In algebraic terms, computing the inverse min-cut will tell you that 1/x1 + 1/x2 < 1/x3 + 1/x4... This surely does not imply that x1+x2 > x3 + x4.

Posted by: Steve P. | August 7, 2007 10:57 PM

6

It is possible that Beren intended a different kind of inversion, where you replace an edge capacity c by the value C - c, where C is the sum of all edge capacities (this "trick" often shows up in dealing with such problems).

Of course, even this doesn't work, because different cuts may have a different number of edges in them, and so you can't 'reverse-engineer' a min cut from a min cut in the modified graph.

Posted by: Suresh Venkat | August 8, 2007 12:00 AM

7

Good point Suresh. I briefly considered the negation of c, but dismissed it (because of negative capacity) without taking the next logical step. Careless me.

Posted by: Steve P. | August 8, 2007 12:50 AM

8

Hi Mark,

You are getting closer and closer to Petri Nets.

http://www.informatik.uni-hamburg.de/TGI/PetriNets/

Just add a token economy.

This is mathematical game theory territory.

Posted by: Doug | August 8, 2007 12:52 AM

9

Thanks Mark, this was one of my favourite areas of the maths that I covered at A-level and it's great to realise I still enjoy it now!

Posted by: Sam Cartwright | August 8, 2007 7:31 AM

10

Actually, I considered both forms of inversion... but I didn't work it through far enough. Thanks for pointing out the flaws in the idea (:

Posted by: Beren | August 8, 2007 8:17 AM

11

In the last example, there seems to be a step missing, and a typo.

After starting with ACBD, you seem to abandon it without explanation. CB has been reduced to 3. How does the algorithm decide to throw away the initial choice?

Typo: "Then ABC is an augmenting flow of 3". Should be ABD?

Posted by: David Goodger | August 8, 2007 10:57 AM

12

Hello,
I have a question for you.... What about a kind of Graph where selecting a node *removes* other nodes from the graph? For example, the vertices of the graph are 'resources' and some verticies use the same resources as others. You can only select one of those vertices... So I would imagine either you remove it from the graph, or it changes the max flow of those nodes to 0. But I'm not sure. Any thoughts?

Posted by: Brigham | August 8, 2007 3:01 PM

13

Brigham:

You're talking about something very different from a simple network flow problem. The problem that you're talking about needs more information in the graph - in addition to capacities, each node needs to have a set of requirements, and a set of products - so that in addition to maximizing the flow, you need to also address the requirements. That's a pretty general constraint problem; the truly general form of it is NP complete; it's equivalent to the bag-packing problem.

Posted by: Mark C. Chu-Carroll | August 8, 2007 3:13 PM

Post a Comment

(Email is required for authentication purposes only. On some blogs, comments are moderated for spam, so your comment may not appear immediately.)






Stats

ScienceBlogs

Search ScienceBlogs:

Go to:

Advertisement
Enter to win a free copy of The Monty Hall Problem
Visit the Collective Imagination blog
Advertisement
Collective Imagination

© 2006-2009 Seed Media Group LLC. ScienceBlogs is a registered trademark of Seed Media Group. All rights reserved.

Sites by Seed Media Group: Seed Media Group | ScienceBlogs | SEEDMAGAZINE.COM