successive_shortest_path_nonnegative_weights.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <HTML>
  2. <!--
  3. Copyright (c) Piotr Wygocki 2013
  4. Distributed under the Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. -->
  8. <Head>
  9. <Title>Boost Graph Library: Successive Shortest Path for Min Cost Max Flow</Title>
  10. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  11. ALINK="#ff0000">
  12. <IMG SRC="../../../boost.png"
  13. ALT="C++ Boost" width="277" height="86">
  14. <BR Clear>
  15. <H1><A NAME="sec:successive_shortest_path_nonnegative_weights">
  16. <TT>successive_shortest_path_nonnegative_weights</TT>
  17. </H1>
  18. <PRE>
  19. <i>// named parameter version</i>
  20. template &lt;class <a href="./Graph.html">Graph</a>, class P, class T, class R&gt;
  21. void successive_shortest_path_nonnegative_weights(
  22. Graph &amp;g,
  23. typename graph_traits&lt;Graph&gt;::vertex_descriptor s,
  24. typename graph_traits&lt;Graph&gt;::vertex_descriptor t,
  25. const bgl_named_params&lt;P, T, R&gt; &amp; params = <i>all defaults</i>)
  26. <i>// non-named parameter version</i>
  27. template &lt;class <a href="./Graph.html">Graph</a>, class Capacity, class ResidualCapacity, class Reversed, class Pred, class Weight, class Distance, class Distance2, class VertexIndex&gt;
  28. void successive_shortest_path_nonnegative_weights(
  29. const Graph &amp; g,
  30. typename graph_traits&lt;Graph&gt;::vertex_descriptor s,
  31. typename graph_traits&lt;Graph&gt;::vertex_descriptor t,
  32. Capacity capacity,
  33. ResidualCapacity residual_capacity,
  34. Weight weight,
  35. Reversed rev,
  36. VertexIndex index,
  37. Pred pred,
  38. Distance distance,
  39. Distance2 distance_prev)
  40. </PRE>
  41. <P>
  42. The <tt>successive_shortest_path_nonnegative_weights()</tt> function calculates the minimum cost maximum flow of a network. See Section <a
  43. href="./graph_theory_review.html#sec:network-flow-algorithms">Network
  44. Flow Algorithms</a> for a description of maximum flow.
  45. The function calculates the flow values <i>f(u,v)</i> for all <i>(u,v)</i> in
  46. <i>E</i>, which are returned in the form of the residual capacity
  47. <i>r(u,v) = c(u,v) - f(u,v)</i>.
  48. <p>
  49. There are several special requirements on the input graph and property
  50. map parameters for this algorithm. First, the directed graph
  51. <i>G=(V,E)</i> that represents the network must be augmented to
  52. include the reverse edge for every edge in <i>E</i>. That is, the
  53. input graph should be <i>G<sub>in</sub> = (V,{E U
  54. E<sup>T</sup>})</i>. The <tt>ReverseEdgeMap</tt> argument <tt>rev</tt>
  55. must map each edge in the original graph to its reverse edge, that is
  56. <i>(u,v) -> (v,u)</i> for all <i>(u,v)</i> in <i>E</i>. The
  57. <tt>CapacityEdgeMap</tt> argument <tt>cap</tt> must map each edge in
  58. <i>E</i> to a positive number, and each edge in <i>E<sup>T</sup></i>
  59. to 0. The <tt>WeightMap</tt> has to map each edge from <i>E</i> to nonnegative number, and each edge from <i>E<sup>T</sup></i> to <i>-weight</i> of its reversed edge.
  60. <p>
  61. The algorithm is described in <a
  62. href="./bibliography.html#ahuja93:_network_flows">Network Flows</a>.
  63. <p>
  64. This algorithm starts with empty flow and in each round augments the shortest path (in terms of weight) in the residual graph.
  65. <p>
  66. In order to find the cost of the result flow use:
  67. <a href="./find_flow_cost.html"><tt>find_flow_cost()</tt></a>.
  68. <H3>Where Defined</H3>
  69. <P>
  70. <a href="../../../boost/graph/successive_shortest_path_nonnegative_weights.hpp"><TT>boost/graph/successive_shortest_path_nonnegative_weights.hpp</TT></a>
  71. <P>
  72. <h3>Parameters</h3>
  73. IN: <tt>Graph&amp; g</tt>
  74. <blockquote>
  75. A directed graph. The
  76. graph's type must be a model of <a
  77. href="./VertexListGraph.html">VertexListGraph</a> and <a href="./IncidenceGraph.html">IncidenceGraph</a> For each edge
  78. <i>(u,v)</i> in the graph, the reverse edge <i>(v,u)</i> must also
  79. be in the graph.
  80. </blockquote>
  81. IN: <tt>vertex_descriptor s</tt>
  82. <blockquote>
  83. The source vertex for the flow network graph.
  84. </blockquote>
  85. IN: <tt>vertex_descriptor t</tt>
  86. <blockquote>
  87. The sink vertex for the flow network graph.
  88. </blockquote>
  89. <h3>Named Parameters</h3>
  90. IN: <tt>capacity_map(CapacityEdgeMap cap)</tt>
  91. <blockquote>
  92. The edge capacity property map. The type must be a model of a
  93. constant <a
  94. href="../../property_map/doc/LvaluePropertyMap.html">Lvalue Property Map</a>. The
  95. key type of the map must be the graph's edge descriptor type.<br>
  96. <b>Default:</b> <tt>get(edge_capacity, g)</tt>
  97. </blockquote>
  98. OUT: <tt>residual_capacity_map(ResidualCapacityEdgeMap res)</tt>
  99. <blockquote>
  100. This maps edges to their residual capacity. The type must be a model
  101. of a mutable <a
  102. href="../../property_map/doc/LvaluePropertyMap.html">Lvalue Property
  103. Map</a>. The key type of the map must be the graph's edge descriptor
  104. type.<br>
  105. <b>Default:</b> <tt>get(edge_residual_capacity, g)</tt>
  106. </blockquote>
  107. IN: <tt>reverse_edge_map(ReverseEdgeMap rev)</tt>
  108. <blockquote>
  109. An edge property map that maps every edge <i>(u,v)</i> in the graph
  110. to the reverse edge <i>(v,u)</i>. The map must be a model of
  111. constant <a href="../../property_map/doc/LvaluePropertyMap.html">Lvalue
  112. Property Map</a>. The key type of the map must be the graph's edge
  113. descriptor type.<br>
  114. <b>Default:</b> <tt>get(edge_reverse, g)</tt>
  115. </blockquote>
  116. IN: <tt>weight_map(WeightMap w_map)</tt>
  117. <blockquote>
  118. The weight or ``cost'' of each edge in the graph. The weights
  119. must all be non-negative, and the algorithm will throw a
  120. <a href="./exception.html#negative_edge"><tt>negative_edge</tt></a>
  121. exception if one of the edges is negative.
  122. The type <tt>WeightMap</tt> must be a model of
  123. <a href="../../property_map/doc/ReadablePropertyMap.html">Readable Property Map</a>. The edge descriptor type of
  124. the graph needs to be usable as the key type for the weight
  125. map. The value type for this map must be
  126. the same as the value type of the distance map.<br>
  127. <b>Default:</b> <tt>get(edge_weight, g)</tt><br>
  128. </blockquote>
  129. UTIL: <tt>predecessor_map(PredEdgeMap pred)</tt>
  130. <blockquote>
  131. Use by the algorithm to store augmenting paths. The map must be a
  132. model of mutable <a
  133. href="../../property_map/doc/LvaluePropertyMap.html">Lvalue Property Map</a>.
  134. The key type must be the graph's vertex descriptor type and the
  135. value type must be the graph's edge descriptor type.<br>
  136. <b>Default:</b> an <a
  137. href="../../property_map/doc/iterator_property_map.html">
  138. <tt>iterator_property_map</tt></a> created from a <tt>std::vector</tt>
  139. of edge descriptors of size <tt>num_vertices(g)</tt> and
  140. using the <tt>i_map</tt> for the index map.
  141. </blockquote>
  142. UTIL: <tt>distance_map(DistanceMap d_map)</tt>
  143. <blockquote>
  144. The shortest path weight from the source vertex <tt>s</tt> to each
  145. vertex in the graph <tt>g</tt> is recorded in this property map. The
  146. shortest path weight is the sum of the edge weights along the
  147. shortest path. The type <tt>DistanceMap</tt> must be a model of <a
  148. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  149. Property Map</a>. The vertex descriptor type of the graph needs to
  150. be usable as the key type of the distance map.
  151. <b>Default:</b> <a
  152. href="../../property_map/doc/iterator_property_map.html">
  153. <tt>iterator_property_map</tt></a> created from a
  154. <tt>std::vector</tt> of the <tt>WeightMap</tt>'s value type of size
  155. <tt>num_vertices(g)</tt> and using the <tt>i_map</tt> for the index
  156. map.<br>
  157. </blockquote>
  158. UTIL: <tt>distance_map2(DistanceMap2 d_map2)</tt>
  159. <blockquote>
  160. The shortest path computation in iteration nr <i>k</i> uses distances computed in iteration <i>k</i>.
  161. The type <tt>DistanceMap2</tt> must be a model of <a
  162. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  163. Property Map</a>. The vertex descriptor type of the graph needs to
  164. be usable as the key type of the distance map.
  165. <b>Default:</b> <a
  166. href="../../property_map/doc/iterator_property_map.html">
  167. <tt>iterator_property_map</tt></a> created from a
  168. <tt>std::vector</tt> of the <tt>WeightMap</tt>'s value type of size
  169. <tt>num_vertices(g)</tt> and using the <tt>i_map</tt> for the index
  170. map.<br>
  171. </blockquote>
  172. IN: <tt>vertex_index_map(VertexIndexMap i_map)</tt>
  173. <blockquote>
  174. Maps each vertex of the graph to a unique integer in the range
  175. <tt>[0, num_vertices(g))</tt>. This property map is only needed
  176. if the default for the distance or distance2 or predecessor map is used.
  177. The vertex index map must be a model of <a
  178. href="../../property_map/doc/ReadablePropertyMap.html">Readable Property
  179. Map</a>. The key type of the map must be the graph's vertex
  180. descriptor type.<br>
  181. <b>Default:</b> <tt>get(vertex_index, g)</tt>
  182. Note: if you use this default, make sure your graph has
  183. an internal <tt>vertex_index</tt> property. For example,
  184. <tt>adjacency_list</tt> with <tt>VertexList=listS</tt> does
  185. not have an internal <tt>vertex_index</tt> property.
  186. </blockquote>
  187. <h3>Complexity</h3>
  188. In the integer capacity case, if <i>U</i> is the value of the max flow, then the complexity is <i> O(U * (|E| + |V|*log|V|))</i>,
  189. where <i>O(|E| + |V|*log|V|)</i> is the complexity of the dijkstra algorithm and <i>U</i> is upper bound on number of iteration.
  190. In many real world cases number of iterations is much smaller than <i>U</i>.
  191. <h3>Example</h3>
  192. The program in <a
  193. href="../example/successive_shortest_path_nonnegative_weights_example.cpp"><tt>example/successive_shortest_path_nonnegative_weights_example.cpp</tt></a>.
  194. <h3>See Also</h3>
  195. <a href="./cycle_canceling.html"><tt>cycle_canceling()</tt></a><br>
  196. <a href="./find_flow_cost.html"><tt>find_flow_cost()</tt></a>.
  197. <br>
  198. <HR>
  199. <TABLE>
  200. <TR valign=top>
  201. <TD nowrap>Copyright &copy; 2013</TD><TD>
  202. Piotr Wygocki, University of Warsaw (<A HREF="mailto:wygos@mimuw.edu.pl">wygos at mimuw.edu.pl</A>)
  203. </TD></TR></TABLE>
  204. </BODY>
  205. </HTML>
  206. <!-- LocalWords: HTML Siek Edmonds BGCOLOR ffffff ee VLINK ALINK ff IMG SRC
  207. -->
  208. <!-- LocalWords: gif ALT BR sec edmonds karp TT DIV CELLPADDING TR TD PRE lt
  209. -->
  210. <!-- LocalWords: typename VertexListGraph CapacityEdgeMap ReverseEdgeMap gt
  211. -->
  212. <!-- LocalWords: ResidualCapacityEdgeMap VertexIndexMap src rev ColorMap pred
  213. -->
  214. <!-- LocalWords: PredEdgeMap tt href html hpp ul li nbsp br LvaluePropertyMap
  215. -->
  216. <!-- LocalWords: num ColorValue DIMACS cpp pre config iostream dimacs int std
  217. -->
  218. <!-- LocalWords: namespace vecS directedS cout endl iter ei HR valign nowrap
  219. -->
  220. <!-- LocalWords: jeremy siek htm Univ mailto jsiek lsc edu
  221. p -->