random_spanning_tree.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <HTML>
  2. <!--
  3. Copyright 2010 The Trustees of Indiana University.
  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. Authors: Jeremiah Willcock
  8. Jeremy Siek (due to adaptation from depth_first_search.html)
  9. Andrew Lumsdaine
  10. -->
  11. <Head>
  12. <Title>Boost Graph Library: Random Spanning Tree</Title>
  13. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  14. ALINK="#ff0000">
  15. <IMG SRC="../../../boost.png"
  16. ALT="C++ Boost" width="277" height="86">
  17. <BR Clear>
  18. <TT>random_spanning_tree</TT>
  19. </H1>
  20. <P>
  21. <PRE>
  22. <i>// named parameter version</i>
  23. template &lt;class Graph, class Gen, class class P, class T, class R&gt;
  24. void random_spanning_tree(Graph&amp; G,
  25. Gen&amp; gen,
  26. const bgl_named_params&lt;P, T, R&gt;&amp; params);
  27. <i>// non-named parameter versions</i>
  28. template &lt;class Graph, class Gen, class PredMap, class WeightMap, class ColorMap&gt;
  29. void random_spanning_tree(const Graph&amp; g, Gen&amp; gen, vertex_descriptor root,
  30. PredMap pred, WeightMap weight, ColorMap color);
  31. </PRE>
  32. <p>
  33. The <tt>random_spanning_tree()</tt> function generates a random spanning tree
  34. on a directed or undirected graph. The algorithm used is Wilson's algorithm (<a
  35. href="bibliography.html#wilson96generating">73</a>, based on <!-- (FIXME: add
  36. documentation for loop_erased_random_walk()) <a
  37. href="loop_erased_random_walk.html"> -->loop-erased random walks<!-- </a> -->. There must
  38. be a path from every non-root vertex of the graph to the root;
  39. the algorithm typically enters an infinite loop when
  40. given a graph that does not satisfy this property, but may also throw the
  41. exception <tt>loop_erased_random_walk_stuck</tt> if the search reaches a vertex
  42. with no outgoing edges. Both weighted and unweighted versions of
  43. <tt>random_spanning_tree()</tt> are
  44. implemented. In the unweighted version, all spanning trees are equally likely.
  45. In the weighted version, the probability of a particular spanning tree being
  46. selected is the product of its edge weights.
  47. In the non-named-parameter
  48. version of the algorithm, the unweighted version can be selected by passing an
  49. object of type <tt>static_property_map&lt;double&gt;</tt> as the weight map.
  50. In the named-parameter version, leaving off the <tt>weight_map</tt> parameter
  51. has the same effect.
  52. </p>
  53. <H3>Where Defined</H3>
  54. <P>
  55. <a href="../../../boost/graph/random_spanning_tree.hpp"><TT>boost/graph/random_spanning_tree.hpp</TT></a>
  56. <h3>Parameters</h3>
  57. IN: <tt>const Graph&amp; g</tt>
  58. <blockquote>
  59. An undirected graph. The graph type must
  60. be a model of <a href="./IncidenceGraph.html">Incidence Graph</a>
  61. and <a href="./VertexListGraph.html">Vertex List Graph</a>.<br>
  62. </blockquote>
  63. IN: <tt>Gen&amp; gen</tt>
  64. <blockquote>
  65. A random number generator. The generator type must
  66. be a model of <a
  67. href="../../../doc/html/boost_random/reference.html#boost_random.reference.concepts.uniform_random_number_generator">Uniform
  68. Random Number Generator</a> or a pointer or reference to such a type.<br>
  69. </blockquote>
  70. <h3>Named Parameters</h3>
  71. IN: <tt>root_vertex(vertex_descriptor root)</tt>
  72. <blockquote>
  73. This parameter, whose type must be the vertex descriptor type of
  74. <tt>Graph</tt>, gives the root of the tree to be generated. The default is
  75. <tt>*vertices(g).first</tt>.<br>
  76. </blockquote>
  77. UTIL: <tt>color_map(ColorMap color)</tt>
  78. <blockquote>
  79. This is used by the algorithm to keep track of its progress through
  80. the graph. The type <tt>ColorMap</tt> must be a model of <a
  81. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write
  82. Property Map</a> and its key type must be the graph's vertex
  83. descriptor type and the value type of the color map must model
  84. <a href="./ColorValue.html">ColorValue</a>.<br>
  85. <b>Default:</b> a <tt>two_bit_color_map</tt> of size
  86. <tt>num_vertices(g)</tt> and using the <tt>i_map</tt> for the index
  87. map.<br>
  88. </blockquote>
  89. IN: <tt>vertex_index_map(VertexIndexMap i_map)</tt>
  90. <blockquote>
  91. This maps each vertex to an integer in the range <tt>[0,
  92. num_vertices(g))</tt>. This parameter is only necessary when the
  93. default color property map is used. The type <tt>VertexIndexMap</tt>
  94. must be a model of <a
  95. href="../../property_map/doc/ReadablePropertyMap.html">Readable Property
  96. Map</a>. The value type of the map must be an integer type. The
  97. vertex descriptor type of the graph needs to be usable as the key
  98. type of the map.<br>
  99. </blockquote>
  100. OUT: <tt>predecessor_map(PredMap pred)</tt>
  101. <blockquote>
  102. This map, on output, will contain the predecessor of each vertex in the graph
  103. in the spanning tree. The value
  104. <tt>graph_traits&lt;Graph&gt;::null_vertex()</tt> will be used as the
  105. predecessor of the root of the tree. The type <tt>PredMap</tt> must be a
  106. model of
  107. <a
  108. href="../../property_map/doc/ReadWritePropertyMap.html">Read/Write Property
  109. Map</a>. The key and value types of the map must both be the graph's vertex type.<br>
  110. </blockquote>
  111. IN: <tt>weight_map(WeightMap weight)</tt>
  112. <blockquote>
  113. This map contains the weight of each edge in the graph. The probability of
  114. any given spanning tree being produced as the result of the algorithm is
  115. proportional to the product of its edge weights. If the weight map is
  116. omitted, a default that gives an equal weight to each edge will be used; a
  117. faster algorithm that relies on constant weights will also be invoked.
  118. The type <tt>WeightMap</tt> must be a
  119. model of
  120. <a
  121. href="../../property_map/doc/ReadablePropertyMap.html">Readable Property
  122. Map</a>. The key type of the map must be the graph's edge type, and the value
  123. type must be a real number type (such as <tt>double</tt>).<br>
  124. </blockquote>
  125. <br>
  126. <HR>
  127. <TABLE>
  128. <TR valign=top>
  129. <TD nowrap>Copyright &copy; 2000-2001</TD><TD>
  130. <A HREF="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</A>,
  131. Indiana University (<A
  132. HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
  133. <A HREF="http://www.boost.org/people/liequan_lee.htm">Lie-Quan Lee</A>, Indiana University (<A HREF="mailto:llee@cs.indiana.edu">llee@cs.indiana.edu</A>)<br>
  134. <A HREF="https://homes.cs.washington.edu/~al75">Andrew Lumsdaine</A>,
  135. Indiana University (<A
  136. HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
  137. </TD></TR></TABLE>
  138. </BODY>
  139. </HTML>