cuthill_mckee_ordering.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <HTML>
  2. <!-- Copyright (c) Jeremy Siek 2000
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. -->
  7. <Head>
  8. <Title>Boost Graph Library: Cuthill-Mckee Ordering</Title>
  9. </Head>
  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>
  16. <img src="figs/python.gif" alt="(Python)"/>
  17. <TT>cuthill_mckee_ordering</TT>
  18. </H1>
  19. <P>
  20. <DIV ALIGN="LEFT">
  21. <TABLE CELLPADDING=3 border>
  22. <TR><TH ALIGN="LEFT"><B>Graphs:</B></TH>
  23. <TD ALIGN="LEFT">undirected</TD>
  24. </TR>
  25. <TR><TH ALIGN="LEFT"><B>Properties:</B></TH>
  26. <TD ALIGN="LEFT">color, degree</TD>
  27. </TR>
  28. <TR><TH ALIGN="LEFT"><B>Complexity:</B></TH>
  29. <TD ALIGN="LEFT">time: <i>O(m log(m)|V|)</i> where <i>m = max { degree(v) | v in V }</i> </TD>
  30. </TR>
  31. </TABLE>
  32. </DIV>
  33. <pre>
  34. (1)
  35. template &lt;class IncidenceGraph, class OutputIterator,
  36. class ColorMap, class DegreeMap&gt;
  37. OutputIterator
  38. cuthill_mckee_ordering(const IncidenceGraph&amp; g,
  39. typename graph_traits&lt;IncidenceGraph&gt;::vertex_descriptor s,
  40. OutputIterator inverse_permutation,
  41. ColorMap color, DegreeMap degree)
  42. (2)
  43. template &lt;class VertexListGraph, class OutputIterator&gt;
  44. OutputIterator
  45. cuthill_mckee_ordering(const VertexListGraph&amp; g, OutputIterator inverse_permutation);
  46. template &lt;class VertexListGraph, class OutputIterator, class VertexIndexMap&gt;
  47. OutputIterator
  48. cuthill_mckee_ordering(const VertexListGraph&amp; g, OutputIterator inverse_permutation,
  49. VertexIndexMap index_map);
  50. template &lt;class VertexListGraph, class OutputIterator,
  51. class ColorMap, class DegreeMap&gt;
  52. OutputIterator
  53. cuthill_mckee_ordering(const VertexListGraph&amp; g, OutputIterator inverse_permutation,
  54. ColorMap color, DegreeMap degree)
  55. (3)
  56. template &lt;class IncidenceGraph, class OutputIterator,
  57. class ColorMap, class DegreeMap&gt;
  58. OutputIterator
  59. cuthill_mckee_ordering(const IncidenceGraph&amp; g,
  60. std::deque&lt; typename
  61. graph_traits&lt;IncidenceGraph&gt;::vertex_descriptor &gt; vertex_queue,
  62. OutputIterator inverse_permutation,
  63. ColorMap color, DegreeMap degree)
  64. </pre>
  65. The goal of the Cuthill-Mckee (and reverse Cuthill-Mckee) ordering
  66. algorithm[<A
  67. HREF="bibliography.html#george81:__sparse_pos_def">14</A>, <A
  68. HREF="bibliography.html#cuthill69:reducing_bandwith">43</A>, <a
  69. href="bibliography.html#liu75:anal_cm_rcm">44</a>, <a
  70. href="bibliography.html#george71:fem">45</a> ] is to reduce the <a
  71. href="./bandwidth.html">bandwidth</a> of a graph by reordering the
  72. indices assigned to each vertex. The Cuthill-Mckee ordering algorithm
  73. works by a local minimization of the i-th bandwidths. The vertices are
  74. basically assigned a breadth-first search order, except that at each
  75. step, the adjacent vertices are placed in the queue in order of
  76. increasing degree.
  77. <p>
  78. Version 1 of the algorithm lets the user choose the ``starting
  79. vertex'', version 2 finds a good starting vertex using the
  80. pseudo-peripheral pair heuristic (among each component), while version 3
  81. contains the starting nodes for each vertex in the deque. The choice of the
  82. ``starting vertex'' can have a significant effect on the quality of the
  83. ordering. For versions 2 and 3, <tt>find_starting_vertex</tt> will be called
  84. for each component in the graph, increasing run time significantly.
  85. </p>
  86. <p>
  87. The output of the algorithm are the vertices in the new ordering.
  88. Depending on what kind of output iterator you use, you can get either
  89. the Cuthill-Mckee ordering or the reverse Cuthill-McKee ordering. For
  90. example, if you store the output into a vector using the vector's
  91. reverse iterator, then you get the reverse Cuthill-McKee ordering.
  92. </p>
  93. <pre>
  94. std::vector&lt;vertex_descriptor&gt; inv_perm(num_vertices(G));
  95. cuthill_mckee_ordering(G, inv_perm.rbegin(), ...);
  96. </pre>
  97. <p>
  98. Either way, storing the output into a vector gives you the
  99. permutation from the new ordering to the old ordering.
  100. </p>
  101. <pre>
  102. inv_perm[new_index[u]] == u
  103. </pre>
  104. <p>
  105. Often times, it is the opposite permutation that you want, the
  106. permutation from the old index to the new index. This can easily be
  107. computed in the following way.
  108. </p>
  109. <pre>
  110. for (size_type i = 0; i != inv_perm.size(); ++i)
  111. perm[old_index[inv_perm[i]]] = i;
  112. </pre>
  113. <h3>Parameters</h3>
  114. For version 1:
  115. <ul>
  116. <li> <tt>IncidenceGraph&amp; g</tt> &nbsp;(IN) <br>
  117. An undirected graph. The graph's type must be a model of <a
  118. href="./IncidenceGraph.html">IncidenceGraph</a>.<br>
  119. <b>Python</b>: The parameter is named <tt>graph</tt>.
  120. <li> <tt>vertex_descriptor s</tt> &nbsp(IN) <br>
  121. The starting vertex.<br>
  122. <b>Python</b>: Unsupported parameter.
  123. <li> <tt>OutputIterator inverse_permutation</tt> &nbsp(OUT) <br>
  124. The new vertex ordering. The vertices are written to the <a
  125. href="http://www.boost.org/sgi/stl/OutputIterator.html">output
  126. iterator</a> in their new order.<br>
  127. <b>Python</b>: This parameter is unused in Python. The new vertex
  128. ordering is returned as a Python <tt>list</tt>.
  129. <li> <tt>ColorMap color_map</tt> &nbsp(WORK) <br>
  130. Used internally to keep track of the progress of the algorithm
  131. (to avoid visiting the same vertex twice).<br>
  132. <b>Python</b>: Unsupported parameter.
  133. <li> <tt>DegreeMap degree_map</tt> &nbsp(IN) <br>
  134. This must map vertices to their degree.<br>
  135. <b>Python</b>: Unsupported parameter.
  136. </ul>
  137. For version 2:
  138. <ul>
  139. <li> <tt>VertexListGraph&amp; g</tt> &nbsp;(IN) <br>
  140. An undirected graph. The graph's type must be a model of <a
  141. href="./VertexListGraph.html">VertexListGraph</a> and <a href="./IncidenceGraph.html">IncidenceGraph</a>.<br>
  142. <b>Python</b>: The parameter is named <tt>graph</tt>.
  143. <li> <tt><a href="http://www.boost.org/sgi/stl/OutputIterator.html">
  144. OutputIterator</a> inverse_permutation</tt> &nbsp(OUT) <br>
  145. The new vertex ordering. The vertices are written to the
  146. output iterator in their new order.<br>
  147. <b>Python</b>: This parameter is unused in Python. The new vertex
  148. ordering is returned as a Python <tt>list</tt>.
  149. <li> <tt>ColorMap color_map</tt> &nbsp(WORK) <br>
  150. Used internally to keep track of the progress of the algorithm
  151. (to avoid visiting the same vertex twice).<br>
  152. <b>Python</b>: Unsupported parameter.
  153. <li> <tt>DegreeMap degree_map</tt> &nbsp(IN) <br>
  154. This must map vertices to their degree.<br>
  155. <b>Python</b>: Unsupported parameter.
  156. </ul>
  157. For version 3:
  158. <ul>
  159. <li> <tt>IncidenceGraph&amp; g</tt> &nbsp;(IN) <br>
  160. An undirected graph. The graph's type must be a model of <a
  161. href="./IncidenceGraph.html">IncidenceGraph</a>.<br>
  162. <b>Python</b>: The parameter is named <tt>graph</tt>.
  163. <li> <tt> std::deque&lt; typename graph_traits&lt;Graph&gt;::vertex_descriptor &gt; vertex_queue </tt> &nbsp(IN) <br>
  164. The deque containing the starting vertices for each component.<br>
  165. <b>Python</b>: Unsupported parameter.
  166. <li> <tt>OutputIterator inverse_permutation</tt> &nbsp(OUT) <br>
  167. The new vertex ordering. The vertices are written to the <a
  168. href="http://www.boost.org/sgi/stl/OutputIterator.html">output
  169. iterator</a> in their new order.<br>
  170. <b>Python</b>: This parameter is unused in Python. The new vertex
  171. ordering is returned as a Python <tt>list</tt>.
  172. <li> <tt>ColorMap color_map</tt> &nbsp(WORK) <br>
  173. Used internally to keep track of the progress of the algorithm
  174. (to avoid visiting the same vertex twice).<br>
  175. <b>Python</b>: Unsupported parameter.
  176. <li> <tt>DegreeMap degree_map</tt> &nbsp(IN) <br>
  177. This must map vertices to their degree.<br>
  178. <b>Python</b>: Unsupported parameter.
  179. </ul>
  180. <h3>Example</h3>
  181. See <a
  182. href="../example/cuthill_mckee_ordering.cpp"><tt>example/cuthill_mckee_ordering.cpp</tt></a>.
  183. <h3>See Also</h3>
  184. <a href="./bandwidth.html">bandwidth</tt></a>,
  185. and <tt>degree_property_map</tt> in <tt>boost/graph/properties.hpp</tt>.
  186. <br>
  187. <HR>
  188. <TABLE>
  189. <TR valign=top>
  190. <TD nowrap>Copyright &copy; 2000-2001</TD><TD>
  191. <A HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</A>, Indiana University (<A HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)
  192. </TD></TR></TABLE>
  193. </BODY>
  194. </HTML>