sorted_erdos_renyi_gen.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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: Jeremiah Willcock
  8. Douglas Gregor
  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>sorted_erdos_renyi_iterator</tt>
  29. <br>
  30. <PRE>
  31. template&lt;typename RandomGenerator, typename Graph&gt;
  32. class sorted_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. sorted_erdos_renyi_iterator();
  41. sorted_erdos_renyi_iterator(RandomGenerator&amp; gen, vertices_size_type n,
  42. double probability = 0.0, bool allow_self_loops = false);
  43. // Iterator operations
  44. reference operator*() const;
  45. pointer operator-&gt;() const;
  46. sorted_erdos_renyi_iterator&amp; operator++();
  47. sorted_erdos_renyi_iterator operator++(int);
  48. bool operator==(const sorted_erdos_renyi_iterator&amp; other) const;
  49. bool operator!=(const sorted_erdos_renyi_iterator&amp; other) const;
  50. };
  51. </PRE>
  52. <p> This class template implements a generator for Erd&ouml;s-Renyi
  53. graphs, suitable for initializing an <a
  54. href="adjacency_list.html"><tt>adjacency_list</tt></a> or other graph
  55. structure with iterator-based initialization. An Erd&ouml;s-Renyi
  56. graph <em>G = (n, p)</em> is a graph with <em>n</em> vertices
  57. such that the probability of having an edge <em>(u, v)</em> in <em>G</em>
  58. is <em>p</em> for any vertices <em>u</em> and <em>v</em>. Typically,
  59. there are no self-loops, but the generator can optionally introduce
  60. self-loops with probability <em>p</em>.</p>
  61. <p>Erd&ouml;s-Renyi graphs typically exhibit very little
  62. structure. For this reason, they are rarely useful in modeling
  63. real-world problems. However, they are often used when determining
  64. the theoretical complexity of complex graph algorithms.</p>
  65. <h3>Where Defined</h3>
  66. <a href="../../../boost/graph/erdos_renyi_generator.hpp"><tt>boost/graph/erdos_renyi_generator.hpp</tt></a>
  67. <h3>Constructors</h3>
  68. <a name="default-constructor"/>
  69. <pre>sorted_erdos_renyi_iterator();</pre>
  70. <blockquote>
  71. Constructs a past-the-end iterator.
  72. </blockquote>
  73. <pre>
  74. sorted_erdos_renyi_iterator(RandomGenerator&amp; gen, vertices_size_type n,
  75. double probability = 0.0, bool allow_self_loops = false);
  76. </pre>
  77. <blockquote>
  78. Constructs an Erd&ouml;s-Renyi generator iterator that creates a
  79. graph with <tt>n</tt> vertices and a given <tt>probability</tt> of the
  80. total number of edges that a simple graph may have.
  81. Random vertices and edges are selected using the
  82. random number generator <tt>gen</tt>. Self-loops are permitted only when
  83. <tt>allow_self_loops</tt> is <tt>true</tt>.
  84. </blockquote>
  85. <H3>Example</H3>
  86. <pre>
  87. #include &lt;boost/graph/adjacency_list.hpp&gt;
  88. #include &lt;boost/graph/erdos_renyi_generator.hpp&gt;
  89. #include &lt;boost/random/linear_congruential.hpp&gt;
  90. typedef boost::adjacency_list&lt;&gt; Graph;
  91. typedef boost::sorted_erdos_renyi_iterator&lt;boost::minstd_rand, Graph&gt; ERGen;
  92. int main()
  93. {
  94. boost::minstd_rand gen;
  95. // Create graph with 100 nodes and edges with probability 0.05
  96. Graph g(ERGen(gen, 100, 0.05), ERGen(), 100);
  97. return 0;
  98. }
  99. </pre>
  100. <br>
  101. <HR>
  102. <TABLE>
  103. <TR valign=top>
  104. <TD nowrap>Copyright &copy; 2005</TD><TD>
  105. Jeremiah Willcock, Indiana University (<script language="Javascript">address("cs.indiana.edu", "jewillco")</script>)<br>
  106. <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>
  107. <A HREF="https://homes.cs.washington.edu/~al75">Andrew Lumsdaine</A>,
  108. Indiana University (<script language="Javascript">address("osl.iu.edu", "lums")</script>)
  109. </TD></TR></TABLE>
  110. </BODY>
  111. </HTML>