{"id":485,"date":"2007-08-07T18:50:52","date_gmt":"2007-08-07T18:50:52","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2007\/08\/07\/maximum-flow-and-minimum-cut\/"},"modified":"2007-08-07T18:50:52","modified_gmt":"2007-08-07T18:50:52","slug":"maximum-flow-and-minimum-cut","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2007\/08\/07\/maximum-flow-and-minimum-cut\/","title":{"rendered":"Maximum Flow and Minimum Cut"},"content":{"rendered":"<p> 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&#8217;m going to talk about one of the classic problems in graph theory, which happens to be a network problem. It&#8217;s called the maximum flow problem.<\/p>\n<p> 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<br \/>\nare called <em>capacities<\/em>. Pick two nodes in the graph, called the <em>source<\/em> and the <em>sink<\/em>, how much can you pump from source to sink without exceeding the capacities of the pipes? That value is called the <em>maximum flow<\/em> of the graph.<\/p>\n<p><!--more--><\/p>\n<p> 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 &#8211; find that, and it&#8217;s easy to figure out the maximum flow of the graph is: it&#8217;s the capacity of the bottleneck.<\/p>\n<p> It turns out that that naive answer is actually pretty deep. There&#8217;s a theory called the max-flow\/min-cut theorem which is just a formalized version of &#8220;the bottleneck determines the maximum&#8221;.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"cut.png\" src=\"https:\/\/i0.wp.com\/scientopia.org\/img-archive\/goodmath\/img_240.png?resize=226%2C156\" width=\"226\" height=\"156\" class=\"inset right\" \/><\/p>\n<p> To state the theorem, first we need to introduce the idea of a <em>cut<\/em>. Suppose you&#8217;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<br \/>\nthinking 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<br \/>\nare called the <em>cut edges<\/em>.  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.<\/p>\n<p> 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.<\/p>\n<p> The <em>minimum cut<\/em> 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. <em>(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&#8217;s why I like computers: I can&#8217;t do this stuff right by hand, but I can write a program to do it!)<\/em><\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"max-flow.png\" src=\"https:\/\/i0.wp.com\/scientopia.org\/img-archive\/goodmath\/img_241.png?resize=344%2C171\" width=\"344\" height=\"171\" \/><\/p>\n<p> 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. <\/p>\n<p> Finding the minimum cut of a graph is reasonably easy &#8211; I&#8217;ll show one algorithm that does it in low-order polynomial time. (It&#8217;s O(V<sup>3<\/sup>) for arbitrary weight values; O(Ef), where f is the max flow, for integer values. The latter is generally a lot lower that V<sup>2<\/sup>, but there&#8217;s no guarantee.)  But interestingly, finding the <em>maximum<\/em> cut is NP-complete.<\/p>\n<p> The solution that I&#8217;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&#8217;s a refinement of the algorithm, called Edmonds-Karp which is guaranteed to terminate for all weights, but it&#8217;s easiest to explain the simple Ford-Fulkerson; E-K is basically the same idea.)<\/p>\n<p> The Ford-Fulkerson algorithm is really simple. Basically, find a path from the source to the sink. Find the maximum capacity of that path &#8211; 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 <em>increase<\/em> the flow; that&#8217;s called an <em>augmenting path<\/em>. 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&#8217;t find any more augmenting paths, you&#8217;ll have the maximum flow. Finding augmenting paths is a relatively straightforward search of the edges of the graph &#8211; it takes time O(E). With integer weights, the minimum augmenting flow has weight 1, so there will be no more than f edges.)<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" alt=\"flow-reverse.png\" src=\"https:\/\/i0.wp.com\/scientopia.org\/img-archive\/goodmath\/img_242.png?resize=153%2C130\" width=\"153\" height=\"130\" class=\"inset right\" \/><\/p>\n<p> There&#8217;s one tricky point in that algorithm, and I&#8217;ll demonstrate it with an example. Look at the graph over to the right. Suppose that initially, we start with &#8220;ACBD&#8221;, with a max flow of 3. Then we find that &#8220;ABCD&#8221; is an augmenting path &#8211; adding flow ABCD adds a flow of 6 &#8211; but it <em>reverses<\/em> 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 &#8211; leaving 1 and AB, and 0 on BD. Then ACD is an augmenting flow &#8211; we can add 1 on AC, and one on CD. So the maximum flow is 6+3+1=10. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;m going to talk about one of the classic problems in graph theory, which happens to be a network problem. It&#8217;s called the maximum flow problem. The idea is that you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[25],"tags":[],"class_list":["post-485","post","type-post","status-publish","format-standard","hentry","category-graph-theory"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-7P","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/comments?post=485"}],"version-history":[{"count":0,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/485\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=485"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}