erdos_renyi_generator.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <HTML>
  2. <!--
  3. Copyright (c) 2004, 2005 The Trustees of Indiana University
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. Authors: Douglas Gregor
  8. Jeremiah Willcock
  9. Andrew Lumsdaine
  10. -->
  11. <Head>
  12. <Title>Boost Graph Library: Erd&ouml;s-Renyi Generator</Title>
  13. <script language="JavaScript" type="text/JavaScript">
  14. <!--
  15. function address(host, user) {
  16. var atchar = '@';
  17. var thingy = user+atchar+host;
  18. thingy = '<a hre' + 'f=' + "mai" + "lto:" + thingy + '>' + user+atchar+host + '</a>';
  19. document.write(thingy);
  20. }
  21. //-->
  22. </script>
  23. </head>
  24. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  25. ALINK="#ff0000">
  26. <IMG SRC="../../../boost.png"
  27. ALT="C++ Boost" width="277" height="86">
  28. <tt>erdos_renyi_iterator</tt>
  29. <br>
  30. <PRE>
  31. template&lt;typename RandomGenerator, typename Graph&gt;
  32. class erdos_renyi_iterator
  33. {
  34. public:
  35. typedef std::input_iterator_tag iterator_category;
  36. typedef std::pair&lt;vertices_size_type, vertices_size_type&gt; value_type;
  37. typedef const value_type&amp; reference;
  38. typedef const value_type* pointer;
  39. typedef void difference_type;
  40. erdos_renyi_iterator();
  41. erdos_renyi_iterator(RandomGenerator&amp; gen, vertices_size_type n,
  42. double fraction = 0.0, bool allow_self_loops = false);
  43. erdos_renyi_iterator(RandomGenerator&amp; gen, vertices_size_type n,
  44. edges_size_type m, bool allow_self_loops = false);
  45. // Iterator operations
  46. reference operator*() const;
  47. pointer operator-&gt;() const;
  48. erdos_renyi_iterator&amp; operator++();
  49. erdos_renyi_iterator operator++(int);
  50. bool operator==(const erdos_renyi_iterator&amp; other) const;
  51. bool operator!=(const erdos_renyi_iterator&amp; other) const;
  52. };
  53. </PRE>
  54. <p> This class template implements a generator for Erd&ouml;s-Renyi
  55. graphs, suitable for initializing an <a
  56. href="adjacency_list.html"><tt>adjacency_list</tt></a> or other graph
  57. structure with iterator-based initialization. An Erd&ouml;s-Renyi
  58. graph <em>G = (n, p)</em> is a graph with <em>n</em> vertices
  59. that. The probability of having an edge <em>(u, v)</em> in <em>G</em>
  60. is <em>p</em> for any vertices <em>u</em> and <em>v</em>. Typically,
  61. there are no self-loops, but the generator can optionally introduce
  62. self-loops with probability <em>p</em>. This generator will not
  63. produce any parallel edges and will produce edges in sorted order (as
  64. required by, e.g., the <a
  65. href="compressed_sparse_row.html"><tt>compressed_sparse_row_graph</tt></a>).</p>
  66. <p>Erd&ouml;s-Renyi graphs typically exhibit very little
  67. structure. For this reason, they are rarely useful in modeling
  68. real-world problems. However, they are often used when determining
  69. the theoretical complexity of complex graph algorithms.</p>
  70. <p>If you want the possibility of generating parallel edges and don't
  71. care about sorted order, use the <a
  72. href="erdos_renyi_generator.html"><tt>erdos_renyi_iterator</tt></a>.</p>
  73. <h3>Where Defined</h3>
  74. <a href="../../../boost/graph/erdos_renyi_generator.hpp"><tt>boost/graph/erdos_renyi_generator.hpp</tt></a>
  75. <h3>Constructors</h3>
  76. <a name="default-constructor"/>
  77. <pre>erdos_renyi_iterator();</pre>
  78. <blockquote>
  79. Constructs a past-the-end iterator.
  80. </blockquote>
  81. <pre>
  82. erdos_renyi_iterator(RandomGenerator&amp; gen, vertices_size_type n,
  83. double fraction = 0.0, bool allow_self_loops = false);
  84. </pre>
  85. <blockquote>
  86. Constructs an Erd&ouml;s-Renyi generator iterator that creates a
  87. graph with <tt>n</tt> vertices and a given <tt>fraction</tt> of the
  88. total number of edges that a simple graph may have.
  89. <tt>probability</tt>. Random vertices and edges are selected using the
  90. random number generator <tt>gen</tt>. Self-loops are permitted only when
  91. <tt>allow_self_loops</tt> is <tt>true</tt>.
  92. </blockquote>
  93. <pre>
  94. erdos_renyi_iterator(RandomGenerator&amp; gen, vertices_size_type n,
  95. edges_size_type m, bool allow_self_loops = false);
  96. </pre>
  97. <blockquote>
  98. Constructs an Erd&ouml;s-Renyi generator iterator that creates a
  99. graph with <tt>n</tt> vertices and <tt>m</tt> edges.
  100. <tt>probability</tt>. Random vertices and edges are selected using the
  101. random number generator <tt>gen</tt>. Self-loops are permitted only when
  102. <tt>allow_self_loops</tt> is <tt>true</tt>.
  103. </blockquote>
  104. <H3>Example</H3>
  105. <pre>
  106. #include &lt;boost/graph/adjacency_list.hpp&gt;
  107. #include &lt;boost/graph/erdos_renyi_generator.hpp&gt;
  108. #include &lt;boost/random/linear_congruential.hpp&gt;
  109. typedef boost::adjacency_list&lt;&gt; Graph;
  110. typedef boost::erdos_renyi_iterator&lt;boost::minstd_rand, Graph&gt; ERGen;
  111. int main()
  112. {
  113. boost::minstd_rand gen;
  114. // Create graph with 100 nodes and edges with probability 0.05
  115. Graph g(ERGen(gen, 100, 0.05), ERGen(), 100);
  116. return 0;
  117. }
  118. </pre>
  119. <br>
  120. <HR>
  121. <TABLE>
  122. <TR valign=top>
  123. <TD nowrap>Copyright &copy; 2005</TD><TD>
  124. <A HREF="http://www.boost.org/people/doug_gregor.html">Doug Gregor</A>, Indiana University (<script language="Javascript">address("cs.indiana.edu", "dgregor")</script>)<br>
  125. <A HREF="https://homes.cs.washington.edu/~al75">Andrew Lumsdaine</A>,
  126. Indiana University (<script language="Javascript">address("osl.iu.edu", "lums")</script>)
  127. </TD></TR></TABLE>
  128. </BODY>
  129. </HTML>