random.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <html>
  2. <!--
  3. Copyright (c) 2003 Vladimir Prus
  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: random</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>
  15. The header <tt>&lt;boost/graph/random&gt;</tt> provides routines to create
  16. random graph, select random vertices and edges, and randomize properties.
  17. <h1>Synopsis</h1>
  18. <pre>
  19. template &lt;class Graph, class RandomNumGen&gt;
  20. typename graph_traits&lt;Graph&gt;::vertex_descriptor
  21. random_vertex(Graph&amp; g, RandomNumGen&amp; gen);
  22. template &lt;class Graph, class RandomNumGen&gt;
  23. typename graph_traits&lt;Graph&gt;::edge_descriptor
  24. random_edge(Graph&amp; g, RandomNumGen&amp; gen);
  25. template &lt;typename MutableGraph, class RandNumGen&gt;
  26. void generate_random_graph
  27. (MutableGraph&amp; g,
  28. typename graph_traits&lt;MutableGraph&gt;::vertices_size_type V,
  29. typename graph_traits&lt;MutableGraph&gt;::vertices_size_type E,
  30. RandNumGen&amp; gen,
  31. bool self_edges = false);
  32. template&lt;class Property, class G, class RandomGenerator&gt;
  33. void randomize_property(G&amp; g, RandomGenerator rg);
  34. </pre>
  35. <h1>Description</h1>
  36. <h2 id="random_vertex">random_vertex</h2>
  37. <pre>
  38. template &lt;class Graph, class RandomNumGen&gt;
  39. typename graph_traits&lt;Graph&gt;::vertex_descriptor
  40. random_vertex(Graph&amp; g, RandomNumGen&amp; gen);
  41. </pre>
  42. <p><b>Effects:</b> Selects a random vertex in a graph and returns it.
  43. <p><b>Preconditions:</b> <tt>num_vertices(g) != 0</tt>
  44. <p><b>Complexity:</b> <tt>O(num_vertices(g))</tt>
  45. <h2 id="random_edge">random_edge</h2>
  46. <pre>
  47. template &lt;class Graph, class RandomNumGen&gt;
  48. typename graph_traits&lt;Graph&gt;::edge_descriptor
  49. random_edge(Graph&amp; g, RandomNumGen&amp; gen);
  50. </pre>
  51. <p><b>Effects:</b> Selects a random edge in a graph and returns it.
  52. <p><b>Preconditions:</b> <tt>num_edges(g) != 0</tt>
  53. <p><b>Complexity:</b> <tt>O(num_edges(g))</tt>
  54. <h2 id="generate_random_graph">generate_random_graph</h2>
  55. <pre>
  56. template &lt;typename MutableGraph, class RandNumGen&gt;
  57. void generate_random_graph
  58. (MutableGraph&amp; g,
  59. typename graph_traits&lt;MutableGraph&gt;::vertices_size_type V,
  60. typename graph_traits&lt;MutableGraph&gt;::vertices_size_type E,
  61. RandNumGen&amp; gen,
  62. bool allow_parallel = true,
  63. bool self_edges = false);
  64. </pre>
  65. <p><b>Effects:</b> Adds <tt>V</tt> vertices and <tt>E</tt> edges, to
  66. <tt>g</tt>. Source and target vertices of each edge are randomly choosen. If
  67. <tt>self_edges</tt> is false, then no edge will have the same source and
  68. targets.
  69. <p><b>Precondition:</b> <tt>num_vertices(g) == 0</tt>
  70. <p><b>Compleixity:</b> <tt>O(V*E)</tt>
  71. <h2 id="randomize_property">randomize_property</h2>
  72. <pre>
  73. template&lt;class Property, class G, class RandomGenerator&gt;
  74. void randomize_property(G&amp; g, RandomGenerator&amp; rg);
  75. </pre>
  76. <p><b>Effects:</b> Sets the random value of property on either all vertices, or
  77. all edges, depending on property kind.
  78. <p><b>Complexity:</b> <tt>O(V)</tt> or <tt>O(E)</tt>, depending on property
  79. kind.
  80. <hr>
  81. <p class="revision">Last modified: Feb 05, 2003</p>
  82. <p>&copy; Copyright Vladimir Prus 2003. Permission to copy, use, modify,
  83. sell and distribute this document is granted provided this copyright
  84. notice appears in all copies. This document is provided ``as is'' without
  85. express or implied warranty, and with no claim as to its suitability for
  86. any purpose.</p>
  87. </body>
  88. </html>