stoer_wagner_min_cut.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <!DOCTYPE html>
  2. <!--
  3. Copyright Daniel Trebbien 2010.
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or the copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <html>
  9. <head>
  10. <title>Boost Graph Library: Stoer&ndash;Wagner Min-Cut</title>
  11. </head>
  12. <body>
  13. <img src="../../../boost.png" alt="C++ Boost">
  14. <h1><a name="sec:stoer_wagner"><tt>stoer_wagner_min_cut</tt></a></h1>
  15. <table border="0" cellspacing="0" style="float: right">
  16. <caption align="bottom">A min-cut of a weighted graph<br>having min-cut weight 4</caption>
  17. <tr><td style="border: #666 1px solid"><img src="stoer_wagner_imgs/stoer_wagner-example-min-cut.gif" width="376"></td></tr>
  18. </table>
  19. <pre>
  20. template &lt;class UndirectedGraph, class WeightMap, class P, class T, class R&gt;
  21. weight_type
  22. stoer_wagner_min_cut(const UndirectedGraph&amp; g, WeightMap weights,
  23. const bgl_named_params&lt;P, T, R&gt;&amp; params = <i>all defaults</i>);
  24. </pre>
  25. <p>The <tt>stoer_wagner_min_cut</tt> function determines a min-cut and the min-cut weight of a connected, undirected graph.
  26. <p>A <em>cut</em> of a graph <i>G</i> is a partition of the vertices into two, non-empty sets. The <em>weight</em> of such a partition is the number of edges between the two sets if <i>G</i> is unweighted, or the sum of the weights of all edges between the two sets if <i>G</i> is weighted. A <em>min-cut</em> is a cut having the least weight.
  27. <p>Sometimes a graph has multiple min-cuts, but all have the same weight. The <tt>stoer_wagner_min_cut</tt> function determines exactly one of the min-cuts as well as its weight.
  28. <h3>Where Defined</h3>
  29. <p><a href="../../../boost/graph/stoer_wagner_min_cut.hpp"><tt>boost/graph/stoer_wagner_min_cut.hpp</tt></a>
  30. <h3>Parameters</h3>
  31. <p>IN: <tt>const UndirectedGraph&amp; g</tt>
  32. <blockquote>
  33. A connected, undirected graph. The graph type must be a model of
  34. <a href="./VertexListGraph.html">Vertex List Graph</a>
  35. and <a href="./IncidenceGraph.html">Incidence Graph</a>.
  36. </blockquote>
  37. <p>IN: <tt>WeightMap weights</tt>
  38. <blockquote>
  39. The weight or length of each edge in the graph. The <tt>WeightMap</tt> type must be a model
  40. of <a href="../../property_map/doc/ReadablePropertyMap.html">Readable
  41. Property Map</a> and its value type must be <a class="external" href="http://www.boost.org/sgi/stl/LessThanComparable.html">Less Than
  42. Comparable</a> and summable. The key type of this map needs to be the graph's
  43. edge descriptor type.
  44. </blockquote>
  45. <h3>Named Parameters</h3>
  46. <p>OUT: <tt>parity_map(ParityMap parities)</tt>
  47. <blockquote>
  48. The algorithm computes a min-cut, which divides the set of vertices into two,
  49. non-empty sets. The <tt>stoer_wagner_min_cut</tt> function records which of
  50. the two sets that each vertex belongs to by setting the parity to <tt>true</tt>
  51. (representing one set) or <tt>false</tt> (for the other). <tt>ParityMap</tt>
  52. must be a model of a <a href="../../property_map/doc/WritablePropertyMap.html">Writable
  53. Property Map</a> and its value type should be a bool type. The
  54. key type must be the graph's vertex descriptor type.<br>
  55. <b>Default:</b> <tt>boost::dummy_property_map</tt>
  56. </blockquote>
  57. <h4>Expert Parameters</h4>
  58. <p>IN: <tt>vertex_index_map(VertexIndexMap vertexIndices)</tt>
  59. <blockquote>
  60. This maps each vertex to an integer in the range [0, <tt>num_vertices(g)</tt>). This
  61. is only necessary if the default is used for the assignment, index-in-heap, or distance maps.
  62. <tt>VertexIndexMap</tt> must be a model of <a
  63. href="../../property_map/doc/ReadablePropertyMap.html">Readable Property
  64. Map</a>. The value type of the map must be an integer type. The
  65. key type must be the graph's vertex descriptor type.<br>
  66. <b>Default:</b> <tt>get(boost::vertex_index, g)</tt>
  67. </blockquote>
  68. <p>UTIL: <tt>assignment_map(AssignmentMap assignments)</tt>
  69. <blockquote>
  70. <tt>AssignmentMap</tt> must be a model of <a
  71. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write Property
  72. Map</a>. The key and value types must be the graph's vertex descriptor type.<br>
  73. <b>Default:</b> A <tt>boost::iterator_property_map</tt> using a <tt>std::vector</tt>
  74. of <tt>num_vertices(g)</tt> vertex descriptors and <tt>vertexIndices</tt> for
  75. the index map.
  76. </blockquote>
  77. <p>UTIL: <tt>max_priority_queue(MaxPriorityQueue&amp; pq)</tt>
  78. <blockquote>
  79. <tt>MaxPriorityQueue</tt> must be a model of <a href="./KeyedUpdatableQueue.html">Keyed Updatable Queue</a>
  80. and a max-<a href="./UpdatableQueue.html#concept%3AUpdatablePriorityQueue">Updatable Priority Queue</a>.
  81. The value type must be the graph's vertex descriptor and the key type must be
  82. the weight type.
  83. <b>Default:</b> A <tt>boost::d_ary_heap_indirect</tt> using a default index-in-heap
  84. and distance map.
  85. </blockquote>
  86. <p>UTIL: <tt>index_in_heap_map(IndexInHeapMap indicesInHeap)</tt>
  87. <blockquote>
  88. This parameter only has an effect when the default max-priority queue is used.<br>
  89. <tt>IndexInHeapMap</tt> must be a model of <a
  90. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write Property
  91. Map</a>. The key type must be the graph's vertex descriptor type. The value type
  92. must be a size type (<tt>typename&nbsp;std::vector&lt;vertex_descriptor&gt;::size_type</tt>).<br>
  93. <b>Default:</b> A <tt>boost::iterator_property_map</tt> using a <tt>std::vector</tt>
  94. of <tt>num_vertices(g)</tt> size type objects and <tt>vertexIndices</tt> for
  95. the index map.
  96. </blockquote>
  97. <p>UTIL: <tt>distance_map(DistanceMap wAs)</tt>
  98. <blockquote>
  99. This parameter only has an effect when the default max-priority queue is used.<br>
  100. <tt>DistanceMap</tt> must be a model of <a
  101. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write Property
  102. Map</a>. The key type must be the graph's vertex descriptor type. The value type
  103. must be the weight type (<tt>typename&nbsp;boost::property_traits&lt;WeightMap&gt;::value_type</tt>).<br>
  104. <b>Default:</b> A <tt>boost::iterator_property_map</tt> using a <tt>std::vector</tt>
  105. of <tt>num_vertices(g)</tt> weight type objects and <tt>vertexIndices</tt> for
  106. the index map.
  107. </blockquote>
  108. <h3>Returns</h3>
  109. <p>The weight of the min-cut
  110. <h3>Throws</h3>
  111. <p><tt>bad_graph</tt>
  112. <blockquote>
  113. If <tt>num_vertices(g)</tt> is less than 2
  114. </blockquote>
  115. <p><tt>std::invalid_argument</tt>
  116. <blockquote>
  117. If a max-priority queue is given as an argument and it is not empty
  118. </blockquote>
  119. <h3>Complexity</h3>
  120. <p>The time complexity is <i>O</i>(<i>V</i>&#xb7;<i>E</i> + <i>V</i><sup>2</sup> log <i>V</i>).
  121. <h3>Example</h3>
  122. <p>The file <a href="../example/stoer_wagner.cpp"><tt>examples/stoer_wagner.cpp</tt></a> contains an example of calculating a min-cut of a weighted, undirected graph and its min-cut weight.
  123. <h3>References</h3>
  124. <ul>
  125. <li>Mehlhorn, Kurt and Christian Uhrig (1995). <q><a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.31.614&amp;rep=rep1&amp;type=pdf">The minimum cut algorithm of Stoer and Wagner</a></q>.
  126. <li>Stoer, Mechthild and Frank Wagner (1997). <q><a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.114.6687&amp;rep=rep1&amp;type=pdf">A simple min-cut algorithm</a></q>. <i>Journal of the ACM</i> <b>44</b> (4), 585&ndash;591.
  127. <li>Zwick, Uri (2008). <q><a href="http://www.cs.tau.ac.il/~zwick/grad-algo-08/gmc.pdf">Global minimum cuts</a></q>.
  128. </ul>
  129. <br>
  130. <hr>
  131. <table>
  132. <tr>
  133. <td>Copyright&nbsp;&copy;&nbsp;2010</td>
  134. <td>Daniel Trebbien (<a href="mailto:dtrebbien@gmail.com">dtrebbien@gmail.com</a>)
  135. </td>
  136. </tr>
  137. </table>
  138. </body>
  139. </html>