maximum_adjacency_search.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <html>
  2. <!--
  3. Copyright (c) Fernando Vilas 2013
  4. Some content from the Stoer-Wagner Min Cut documentation,
  5. Copyright (c) Daniel Trebbien 2010
  6. Distributed under the Boost Software License, Version 1.0.
  7. (See accompanying file LICENSE_1_0.txt or copy at
  8. http://www.boost.org/LICENSE_1_0.txt)
  9. -->
  10. <head>
  11. <title>Boost Graph Library: Maximum Adjacency Search</Title>
  12. <body>
  13. <img src="../../../boost.png" alt="C++ Boost" width="277" height="86">
  14. <h1><a name="sec:maximum-adjacency-search"></a>
  15. <tt>maximum_adjacency_search</tt>
  16. </h1>
  17. <p>
  18. <pre>
  19. <em>// named parameter versions</em>
  20. template &lt;class Graph, class class P, class T, class R&gt;
  21. void
  22. maximum_adjacency_search(const Graph&amp; g,
  23. const bgl_named_params&lt;P, T, R&gt;&amp; params);
  24. <i>// non-named parameter versions</i>
  25. template &lt;class Graph, class WeightMap, class MASVisitor&gt;
  26. void
  27. maximum_adjacency_search(const Graph&amp; g, WeightMap weights, MASVisitor vis,
  28. const typename graph_traits&lt;Graph&gt;::vertex_descriptor start);
  29. </pre>
  30. <p>
  31. The <tt>maximum_adjacency_search()</tt> function performs a traversal
  32. of the vertices in an undirected graph. The next vertex visited is the
  33. vertex that has the most visited neighbors at any time. In the case of
  34. an unweighted, undirected graph, the number of visited neighbors of the
  35. very last vertex visited in the graph is also the number of edge-disjoint
  36. paths between that vertex and the next-to-last vertex visited. These can be
  37. retrieved from a visitor, an example of which is in the test harness
  38. mas_test.cpp.
  39. </p>
  40. <p>
  41. The <tt>maximum_adjacency_search()</tt> function invokes user-defined
  42. actions at certain event-points within the algorithm. This provides a
  43. mechanism for adapting the generic MAS algorithm to the many situations
  44. in which it can be used. In the pseudo-code below, the event points
  45. for MAS are the labels on the right. The user-defined actions must be
  46. provided in the form of a visitor object, that is, an object whose type
  47. meets the requirements for a MAS Visitor.
  48. </p>
  49. <table>
  50. <tr>
  51. <td valign="top">
  52. <pre>
  53. MAS(<i>G</i>)
  54. <b>for</b> each vertex <i>u in V</i>
  55. <i>reach_count[u] := 0</i>
  56. <b>end for</b>
  57. // for the starting vertex s
  58. <i>reach_count[s] := 1</i>
  59. <b>for</b> each unvisited vertex <i>u in V</i>
  60. <b>call</b> MAS-VISIT(<i>G</i>, <i>u</i>)
  61. remove u from the list on unvisited vertices
  62. <b>for</b> each out edge from <i>u</i> to <i>t</i>
  63. <b>if</b> <i>t</i> has not yet been visited
  64. increment <i>reach_count[t]</i>
  65. <b>end if</b>
  66. <b>end for</b> each out edge
  67. <b>call</b> MAS-VISIT(<i>G</i>, <i>u</i>)
  68. <b>end for</b> each unvisited vertex
  69. <pre>
  70. </td>
  71. <td valign="top">
  72. <pre>
  73. -
  74. -
  75. initialize vertex <i>u</i>
  76. -
  77. -
  78. -
  79. -
  80. examine vertex <i>u</i>
  81. -
  82. examine edge <i>(u,t)</i>
  83. -
  84. -
  85. -
  86. -
  87. finish vertex <i>u</i>
  88. -
  89. </pre>
  90. </td>
  91. </tr>
  92. </table>
  93. <h3>Where Defined</h3>
  94. <p>
  95. <a href="../../../boost/graph/maximum_adjacency_search.hpp"><tt>boost/graph/maximum_adjacency_search.hpp</tt></a></p>
  96. <h3>Parameters</h3>
  97. IN: <tt>const UndirectedGraph&amp; g</tt></p>
  98. <blockquote>
  99. A connected, directed graph. The graph type must
  100. be a model of <a href="./IncidenceGraph.html">Incidence Graph</a>
  101. and <a href="./VertexListGraph.html">Vertex List Graph</a>.<br>
  102. </blockquote>
  103. <h3>Named Parameters</h3>
  104. <p>IN: <tt>WeightMap weights</tt></p>
  105. <blockquote>
  106. The weight or length of each edge in the graph. The
  107. <tt>WeightMap</tt> type must be a model of
  108. <a href="../../property_map/doc/ReadablePropertyMap.html">Readable
  109. Property Map</a> and its value type must be <a class="external"
  110. href="http://www.boost.org/sgi/stl/LessThanComparable.html">
  111. Less Than Comparable</a> and summable. The key type of this map
  112. needs to be the graph's edge descriptor type.
  113. <b>Default:</b> <tt>get(edge_weight, g)</tt><br>
  114. </blockquote>
  115. IN: <tt>visitor(MASVisitor vis)</tt></p>
  116. <blockquote>
  117. A visitor object that is invoked inside the algorithm at the
  118. event-points specified by the MAS Visitor concept. The visitor
  119. object is passed by value <a href="#1">[1]</a>. <br>
  120. <b>Default:</b> <tt>mas_visitor&lt;null_visitor&gt;</tt><br>
  121. </blockquote>
  122. IN: <tt>root_vertex(typename
  123. graph_traits&lt;VertexListGraph&gt;::vertex_descriptor start)</tt></p>
  124. <blockquote>
  125. This specifies the vertex that the depth-first search should
  126. originate from. The type is the type of a vertex descriptor for the
  127. given graph.<br>
  128. <b>Default:</b> <tt>*vertices(g).first</tt><br>
  129. </blockquote>
  130. <h4>Expert Parameters</h4>
  131. <p>IN: <tt>vertex_index_map(VertexIndexMap vertexIndices)</tt> </p>
  132. <blockquote>
  133. This maps each vertex to an integer in the range
  134. [0, <tt>num_vertices(g)</tt>). This is only necessary if the default is
  135. used for the assignment, index-in-heap, or distance maps.
  136. <tt>VertexIndexMap</tt> must be a model of <a
  137. href="../../property_map/doc/ReadablePropertyMap.html">Readable Property
  138. Map</a>. The value type of the map must be an integer type. The
  139. key type must be the graph's vertex descriptor type.<br>
  140. <b>Default:</b> <tt>get(boost::vertex_index, g)</tt>
  141. Note: if you use this default, make sure your graph has
  142. an internal <tt>vertex_index</tt> property. For example,
  143. <tt>adjacency_list</tt> with <tt>VertexList=listS</tt> does
  144. not have an internal <tt>vertex_index</tt> property.
  145. </blockquote>
  146. <p>UTIL: <tt>vertex_assignment_map(AssignmentMap assignments)</tt></p>
  147. <blockquote>
  148. <tt>AssignmentMap</tt> must be a model of <a
  149. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write Property
  150. Map</a>. The key and value types must be the graph's vertex descriptor
  151. type.<br>
  152. <b>Default:</b> A <tt>boost::iterator_property_map</tt> using a
  153. <tt>std::vector</tt> of <tt>num_vertices(g)</tt> vertex descriptors and
  154. <tt>vertexIndices</tt> for the index map.
  155. </blockquote>
  156. <p>UTIL: <tt>max_priority_queue(MaxPriorityQueue&amp; pq)</tt></p>
  157. <blockquote>
  158. <tt>MaxPriorityQueue</tt> must be a model of <a
  159. href="./KeyedUpdatableQueue.html">Keyed Updatable Queue</a> and a
  160. max-<a href="./UpdatableQueue.html#concept%3AUpdatablePriorityQueue">
  161. Updatable Priority Queue</a>. The value type must be the graph's vertex
  162. descriptor and the key type must be the weight type.
  163. <b>Default:</b> A <tt>boost::d_ary_heap_indirect</tt> using a default
  164. index-in-heap and distance map.
  165. </blockquote>
  166. <p>UTIL: <tt>index_in_heap_map(IndexInHeapMap indicesInHeap)</tt></p>
  167. <blockquote>
  168. This parameter only has an effect when the default max-priority queue is used.<br>
  169. <tt>IndexInHeapMap</tt> must be a model of <a
  170. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write Property
  171. Map</a>. The key type must be the graph's vertex descriptor type. The
  172. value type must be a size type
  173. (<tt>typename&nbsp;std::vector&lt;vertex_descriptor&gt;::size_type</tt>).<br>
  174. <b>Default:</b> A <tt>boost::iterator_property_map</tt> using a
  175. <tt>std::vector</tt> of <tt>num_vertices(g)</tt> size type objects and
  176. <tt>vertexIndices</tt> for the index map.
  177. </blockquote>
  178. <p>UTIL: <tt>distance_map(DistanceMap wAs)</tt></p>
  179. <blockquote>
  180. This parameter only has an effect when the default max-priority queue is used.<br>
  181. <tt>DistanceMap</tt> must be a model of <a
  182. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write Property
  183. Map</a>. The key type must be the graph's vertex descriptor type. The
  184. value type must be the weight type
  185. (<tt>typename&nbsp;boost::property_traits&lt;WeightMap&gt;::value_type</tt>).
  186. <br>
  187. <b>Default:</b> A <tt>boost::iterator_property_map</tt> using a
  188. <tt>std::vector</tt> of <tt>num_vertices(g)</tt> weight type objects
  189. and <tt>vertexIndices</tt> for the index map.
  190. </blockquote>
  191. <h3>Returns</h3>
  192. <p>void</p>
  193. <h3>Throws</h3>
  194. <p><tt>bad_graph</tt>
  195. <blockquote>
  196. If <tt>num_vertices(g)</tt> is less than 2
  197. </blockquote></p>
  198. <p><tt>std::invalid_argument</tt>
  199. <blockquote>
  200. If a max-priority queue is given as an argument and it is not empty
  201. </blockquote>.
  202. <h3><a name="SECTION001340300000000000000">
  203. Complexity</a>
  204. </h3>
  205. <p>
  206. The time complexity is <i>O(E + V)</i>.
  207. </p>
  208. <h3>References</h3>
  209. <ul>
  210. <li>David Matula (1993). <q><a href="http://dl.acm.org/citation.cfm?id=313872&dl=ACM&coll=DL&CFID=85991501&CFTOKEN=44461131">A linear time 2 + epsilon approximation algorightm for edge connectivity</a></q>
  211. </li>
  212. <li>Cai, Weiqing and Matula, David W.
  213. Partitioning by maximum adjacency search of graphs.
  214. Partitioning Data Sets: Dimacs Workshop, April 19-21, 1993.
  215. Vol 19. Page 55. 1995. Amer Mathematical Society</li>
  216. }
  217. </ul>
  218. <h3>Visitor Event Points</h3>
  219. <ul>
  220. <li><b><tt>vis.initialize_vertex(s, g)</tt></b> is invoked on every
  221. vertex of the graph before the start of the graph search.</li>
  222. <li><b><tt>vis.start_vertex(s, g)</tt></b> is invoked on the source
  223. vertex once before processing its out edges.</li>
  224. <li><b><tt>vis.examine_edge(e, g)</tt></b> is invoked on every out-edge
  225. of each vertex after it is started.</li>
  226. <li><b><tt>vis.finish_vertex(u, g)</tt></b> is invoked on a vertex after
  227. all of its out edges have been examined and the reach counts of the
  228. unvisited targets have been updated.</li>
  229. </ul>
  230. <h3>Notes</h3>
  231. <p><a name="1">[1]</a>
  232. Since the visitor parameter is passed by value, if your visitor
  233. contains state then any changes to the state during the algorithm
  234. will be made to a copy of the visitor object, not the visitor object
  235. passed in. Therefore you may want the visitor to hold this state by
  236. pointer or reference.</p>
  237. <hr>
  238. <table>
  239. <tr valign=top>
  240. <td nowrap>Copyright &copy; 2012</td><td>
  241. Fernando Vilas
  242. </td></tr></table>
  243. </body>
  244. </html>