king_ordering.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <HTML>
  2. <!--
  3. ~~ Copyright (c) Jeremy Siek 2000
  4. ~~
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE_1_0.txt or copy at
  7. http://www.boost.org/LICENSE_1_0.txt)
  8. -->
  9. <Head>
  10. <Title>Boost Graph Library: King Ordering</Title>
  11. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  12. ALINK="#ff0000">
  13. <IMG SRC="../../../boost.png"
  14. ALT="C++ Boost" width="277" height="86">
  15. <BR Clear>
  16. <H1>
  17. <img src="figs/python.gif" alt="(Python)"/>
  18. <TT>king_ordering</TT>
  19. </H1>
  20. <P>
  21. <DIV ALIGN="LEFT">
  22. <TABLE CELLPADDING=3 border>
  23. <TR><TH ALIGN="LEFT"><B>Graphs:</B></TH>
  24. <TD ALIGN="LEFT">undirected</TD>
  25. </TR>
  26. <TR><TH ALIGN="LEFT"><B>Properties:</B></TH>
  27. <TD ALIGN="LEFT">color, degree</TD>
  28. </TR>
  29. <TR><TH ALIGN="LEFT"><B>Complexity:</B></TH>
  30. <TD ALIGN="LEFT">time: <i>O(m<sup>2</sup>log(m)|E|)</i> where <i>m = max { degree(v) | v in V }</i> </TD>
  31. </TR>
  32. </TABLE>
  33. </DIV>
  34. <pre>
  35. (1)
  36. template &lt;class IncidenceGraph, class OutputIterator,
  37. class ColorMap, class DegreeMap, class VertexIndexMap&gt;
  38. OutputIterator
  39. king_ordering(const IncidenceGraph&amp; g,
  40. typename graph_traits&lt;Graph&gt;::vertex_descriptor s,
  41. OutputIterator inverse_permutation,
  42. ColorMap color, DegreeMap degree, VertexIndexMap index_map);
  43. (2)
  44. template &lt;class IncidenceGraph, class OutputIterator&gt;
  45. OutputIterator
  46. king_ordering(const IncidenceGraph&amp; g, OutputIterator inverse_permutation);
  47. template &lt;class IncidenceGraph, class OutputItrator, class VertexIndexMap&gt;
  48. OutputIterator
  49. king_ordering(const IncidenceGraph&amp; g, OutputIterator inverse_permutation,
  50. VertexIndexMap index_map);
  51. template &lt;class VertexListGraph, class OutputIterator,
  52. class ColorMap, class DegreeMap, class VertexIndexMap&gt;
  53. OutputIterator
  54. king_ordering(const VertexListGraph&amp; G, OutputIterator inverse_permutation,
  55. ColorMap color, DegreeMap degree, VertexIndexMap index_map);
  56. (3)
  57. template &lt;class IncidenceGraph, class OutputIterator,
  58. class ColorMap, class DegreeMap, class VertexIndexMap&gt;
  59. OutputIterator
  60. king_ordering(const IncidenceGraph&amp; g,
  61. std::deque&lt; typename
  62. graph_traits&lt;Graph&gt;::vertex_descriptor &gt; vertex_queue,
  63. OutputIterator permutation,
  64. ColorMap color, DegreeMap degree, VertexIndexMap index_map);
  65. </pre>
  66. <!-- King, I.P. An automatic reordering scheme for simultaneous equations derived from network analysis. Int. J. Numer. Methods Engrg. 2 (1970), 523-533 -->
  67. The goal of the King ordering
  68. algorithm [<a href="bibliography.html#king70">62</a>]is to reduce the <a
  69. href="./bandwidth.html">bandwidth</a> of a graph by reordering the
  70. indices assigned to each vertex. The King ordering algorithm
  71. works by a local minimization of the i-th bandwidths. The vertices are
  72. basically assigned a breadth-first search order, except that at each
  73. step, the adjacent vertices are placed in the queue in order of
  74. increasing pseudo-degree, where pseudo-degree is defined as the number of
  75. outgoing edges with white endpoints (vertices yet to be examined).
  76. <p>
  77. Version 1 of the algorithm lets the user choose the ``starting
  78. vertex'', version 2 finds a good starting vertex using the
  79. pseudo-peripheral pair heuristic (among each component), while version 3
  80. contains the starting nodes for each vertex in the deque. The choice of the ``starting
  81. vertex'' can have a significant effect on the quality of the ordering.
  82. </p>
  83. <p>
  84. The output of the algorithm are the vertices in the new ordering.
  85. Storing the output into a vector gives you the
  86. permutation from the new ordering to the old ordering.
  87. <pre>
  88. inv_perm[new_index[u]] == u
  89. </pre>
  90. <p>
  91. Often times, it is the opposite permutation that you want, the
  92. permutation from the old index to the new index. This can easily be
  93. computed in the following way.
  94. </p>
  95. <pre>
  96. for (size_type i = 0; i != inv_perm.size(); ++i)
  97. perm[old_index[inv_perm[i]]] = i;
  98. </pre>
  99. <h3>Parameters</h3>
  100. For version 1:
  101. <ul>
  102. <li> <tt>IncidenceGraph&amp; g</tt> &nbsp;(IN) <br>
  103. An undirected graph. The graph's type must be a model of <a
  104. href="./IncidenceGraph.html">IncidenceGraph</a>.<br>
  105. <b>Python</b>: The parameter is named <tt>graph</tt>.
  106. <li> <tt>vertex_descriptor s</tt> &nbsp(IN) <br>
  107. The starting vertex.<br>
  108. <b>Python</b>: Unsupported parameter.
  109. <li> <tt>OutputIterator permutation</tt> &nbsp(OUT) <br>
  110. The new vertex ordering. The vertices are written to the <a
  111. href="http://www.boost.org/sgi/stl/OutputIterator.html">output
  112. iterator</a> in their new order. <br>
  113. <b>Python</b>: This parameter is unused in Python. The new vertex
  114. ordering is returned as a Python <tt>list</tt>.
  115. <li> <tt>ColorMap color_map</tt> &nbsp(WORK) <br>
  116. Used internally to keep track of the progress of the algorithm
  117. (to avoid visiting the same vertex twice).<br>
  118. <b>Python</b>: Unsupported parameter.
  119. <li> <tt>DegreeMap degree_map</tt> &nbsp(IN) <br>
  120. This must map vertices to their degree.<br>
  121. <b>Python</b>: Unsupported parameter.
  122. </ul>
  123. For version 2:
  124. <ul>
  125. <li> <tt>VertexListGraph&amp; g</tt> &nbsp;(IN) <br>
  126. An undirected graph. The graph's type must be a model of <a
  127. href="./VertexListGraph.html">VertexListGraph</a>.<br>
  128. <b>Python</b>: The name of this parameter is <tt>graph</tt>.
  129. <li> <tt><a href="http://www.boost.org/sgi/stl/OutputIterator.html">
  130. OutputIterator</a> permutation</tt> &nbsp(OUT) <br>
  131. The new vertex ordering. The vertices are written to the
  132. output iterator in their new order.<br>
  133. <b>Python</b>: This parameter is unused in Python. The new vertex
  134. ordering is returned as a Python <tt>list</tt>.
  135. <li> <tt>ColorMap color_map</tt> &nbsp(WORK) <br>
  136. Used internally to keep track of the progress of the algorithm
  137. (to avoid visiting the same vertex twice).<br>
  138. <b>Python</b>: Unsupported parameter.
  139. <li> <tt>DegreeMap degree_map</tt> &nbsp(IN) <br>
  140. This must map vertices to their degree.<br>
  141. <b>Python</b>: Unsupported parameter.
  142. </ul>
  143. For version 3:
  144. <ul>
  145. <li> <tt>IncidenceGraph&amp; g</tt> &nbsp;(IN) <br>
  146. An undirected graph. The graph's type must be a model of <a
  147. href="./IncidenceGraph.html">IncidenceGraph</a>.<br>
  148. <b>Python</b>: The parameter is named <tt>graph</tt>.
  149. <li> <tt> std::deque&lt; typename graph_traits&lt;Graph&gt;::vertex_descriptor &gt; vertex_queue </tt> &nbsp(IN) <br>
  150. The deque containing the starting vertices for each component.<br>
  151. <b>Python</b>: This parameter is unused in Python. The new vertex
  152. ordering is returned as a Python <tt>list</tt>.
  153. <li> <tt>OutputIterator permutation</tt> &nbsp(OUT) <br>
  154. The new vertex ordering. The vertices are written to the <a
  155. href="http://www.boost.org/sgi/stl/OutputIterator.html">output
  156. iterator</a> in their new order.<br>
  157. <b>Python</b>: This parameter is unused in Python. The new vertex
  158. ordering is returned as a Python <tt>list</tt>.
  159. <li> <tt>ColorMap color_map</tt> &nbsp(WORK) <br>
  160. Used internally to keep track of the progress of the algorithm
  161. (to avoid visiting the same vertex twice).<br>
  162. <b>Python</b>: Unsupported parameter.
  163. <li> <tt>DegreeMap degree_map</tt> &nbsp(IN) <br>
  164. This must map vertices to their degree.<br>
  165. <b>Python</b>: Unsupported parameter.
  166. </ul>
  167. <h3>Example</h3>
  168. See <a
  169. href="../example/king_ordering.cpp"><tt>example/king_ordering.cpp</tt></a>.
  170. <h3>See Also</h3>
  171. <a href="./bandwidth.html">bandwidth</tt></a>,
  172. and <tt>degree_property_map</tt> in <tt>boost/graph/properties.hpp</tt>.
  173. <br>
  174. <HR>
  175. <TABLE>
  176. <TR valign=top>
  177. <TD nowrap>Copyright &copy; 2000-2001</TD><TD>
  178. <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>)
  179. </TD></TR></TABLE>
  180. </BODY>
  181. </HTML>