plod_generator.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <HTML>
  2. <!--
  3. Copyright (c) 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. Andrew Lumsdaine
  9. -->
  10. <Head>
  11. <Title>Boost Graph Library: Power Law Out Degree (PLOD) Generator</Title>
  12. <script language="JavaScript" type="text/JavaScript">
  13. <!--
  14. function address(host, user) {
  15. var atchar = '@';
  16. var thingy = user+atchar+host;
  17. thingy = '<a hre' + 'f=' + "mai" + "lto:" + thingy + '>' + user+atchar+host + '</a>';
  18. document.write(thingy);
  19. }
  20. //-->
  21. </script>
  22. </head>
  23. <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b"
  24. ALINK="#ff0000">
  25. <IMG SRC="../../../boost.png"
  26. ALT="C++ Boost" width="277" height="86">
  27. <tt>plod_iterator</tt>
  28. <br>
  29. <PRE>
  30. template&lt;typename RandomGenerator, typename Graph&gt;
  31. class plod_iterator
  32. {
  33. public:
  34. typedef std::input_iterator_tag iterator_category;
  35. typedef std::pair&lt;vertices_size_type, vertices_size_type&gt; value_type;
  36. typedef const value_type&amp; reference;
  37. typedef const value_type* pointer;
  38. typedef void difference_type;
  39. plod_iterator();
  40. plod_iterator(RandomGenerator&amp; gen, vertices_size_type n,
  41. double alpha, double beta, bool allow_self_loops = false);
  42. // Iterator operations
  43. reference operator*() const;
  44. pointer operator-&gt;() const;
  45. plod_iterator&amp; operator++();
  46. plod_iterator operator++(int);
  47. bool operator==(const plod_iterator&amp; other) const;
  48. bool operator!=(const plod_iterator&amp; other) const;
  49. };
  50. </PRE>
  51. <p> This class template implements a generator for scale-free graphs
  52. using the Power Law Out Degree (PLOD) algorithm
  53. [<a href="bibliography.html#palmer2000">63</a>], suitable for
  54. initializing an <a
  55. href="adjacency_list.html"><tt>adjacency_list</tt></a> or other graph
  56. structure with iterator-based initialization. A scale-free graph
  57. typically has a very skewed degree distribution, where few vertices
  58. have a very high degree and a large number of vertices have a very
  59. small degree. Many naturally evolving networks, such as the World
  60. Wide Web, are scale-free graphs, making these graphs a good model for
  61. certain networking problems.</p>
  62. <p>The Power Law Out Degree (PLOD) algorithm generates a scale-free
  63. graph from three parameters, <em>n</em>, <em>alpha</em>, and
  64. <em>beta</em>, by allocating a certain number of degree "credits" to
  65. each vertex, drawn from a power-law distribution. It then creates
  66. edges between vertices, deducting a credit from each involved vertex
  67. (in the undirected case) or the source vertex (in the directed
  68. case). The number of credits assigned to a vertex is:
  69. <em>beta*x<sup>-alpha</sup></em>, where <em>x</em> is a random value
  70. between 0 and <em>n-1</em>. The value of <em>beta</em> controls the
  71. y-intercept of the curve, so that increasing <em>beta</em> increases
  72. the average degree of vertices. The value of <em>alpha</em> controls
  73. how steeply the curve drops off, with larger values indicating a
  74. steeper curve. The web graph, for instance, has <em>alpha ~
  75. 2.72</em>.</p>
  76. <h3>Where Defined</h3>
  77. <a href="../../../boost/graph/plod_generator.hpp"><tt>boost/graph/plod_generator.hpp</tt></a>
  78. <h3>Constructors</h3>
  79. <a name="default-constructor"/>
  80. <pre>plod_iterator();</pre>
  81. <blockquote>
  82. Constructs a past-the-end iterator.
  83. </blockquote>
  84. <pre>
  85. plod_iterator(RandomGenerator&amp; gen, vertices_size_type n,
  86. double alpha, double beta, bool allow_self_loops = false);
  87. </pre>
  88. <blockquote>
  89. Constructs a PLOD generator iterator that creates a
  90. graph with <tt>n</tt> vertices. Probabilities are drawn from the
  91. random number generator <tt>gen</tt>. Self-loops are permitted only
  92. when <tt>allow_self_loops</tt> is <tt>true</tt>.
  93. </blockquote>
  94. <H3>Example</H3>
  95. <pre>
  96. #include &lt;boost/graph/adjacency_list.hpp&gt;
  97. #include &lt;boost/graph/plod_generator.hpp&gt;
  98. #include &lt;boost/random/linear_congruential.hpp&gt;
  99. typedef boost::adjacency_list&lt;&gt; Graph;
  100. typedef boost::plod_iterator&lt;boost::minstd_rand, Graph&gt; SFGen;
  101. int main()
  102. {
  103. boost::minstd_rand gen;
  104. // Create graph with 100 nodes
  105. Graph g(SFGen(gen, 100, 2.5, 1000), SFGen(), 100);
  106. return 0;
  107. }
  108. </pre>
  109. <br>
  110. <HR>
  111. <TABLE>
  112. <TR valign=top>
  113. <TD nowrap>Copyright &copy; 2005</TD><TD>
  114. <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>
  115. <A HREF="https://homes.cs.washington.edu/~al75">Andrew Lumsdaine</A>,
  116. Indiana University (<script language="Javascript">address("osl.iu.edu", "lums")</script>)
  117. </TD></TR></TABLE>
  118. </BODY>
  119. </HTML>