small_world_generator.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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: Small World 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>small_world_iterator</tt>
  28. <br>
  29. <PRE>
  30. template&lt;typename RandomGenerator, typename Graph&gt;
  31. class small_world_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. small_world_iterator();
  40. small_world_iterator(RandomGenerator&amp; gen, vertices_size_type n,
  41. vertices_size_type k, double probability = 0.,
  42. bool allow_self_loops = false);
  43. // Iterator operations
  44. reference operator*() const;
  45. pointer operator-&gt;() const;
  46. small_world_iterator&amp; operator++();
  47. small_world_iterator operator++(int);
  48. bool operator==(const small_world_iterator&amp; other) const;
  49. bool operator!=(const small_world_iterator&amp; other) const;
  50. };
  51. </PRE>
  52. <p> This class template implements a generator for small-world graphs,
  53. suitable for initializing an <a
  54. href="adjacency_list.html"><tt>adjacency_list</tt></a> or other graph
  55. structure with iterator-based initialization. A small-world graph
  56. consists of a ring graph (where each vertex is connected to its
  57. <em>k</em> nearest neighbors). Edges in the graph are randomly
  58. rewired to different vertices with a probability
  59. <em>p</em>. Small-world graphs exhibit a high clustering coefficient
  60. (because vertices are always connected to their closest neighbors),
  61. but rewiring ensures a small diameter.</p>
  62. <h3>Where Defined</h3>
  63. <a href="../../../boost/graph/small_world_generator.hpp"><tt>boost/graph/small_world_generator.hpp</tt></a>
  64. <h3>Constructors</h3>
  65. <a name="default-constructor"/>
  66. <pre>small_world_iterator();</pre>
  67. <blockquote>
  68. Constructs a past-the-end iterator.
  69. </blockquote>
  70. <pre>
  71. small_world_iterator(RandomGenerator&amp; gen, vertices_size_type n,
  72. vertices_size_type k, double probability = 0.,
  73. bool allow_self_loops = false);
  74. </pre>
  75. <blockquote>
  76. Constructs a small-world generator iterator that creates a
  77. graph with <tt>n</tt> vertices, each connected to its <tt>k</tt>
  78. nearest neighbors. Probabilities are drawn from the
  79. random number generator <tt>gen</tt>. Self-loops are permitted only
  80. when <tt>allow_self_loops</tt> is <tt>true</tt>.
  81. </blockquote>
  82. <H3>Example</H3>
  83. <pre>
  84. #include &lt;boost/graph/adjacency_list.hpp&gt;
  85. #include &lt;boost/graph/small_world_generator.hpp&gt;
  86. #include &lt;boost/random/linear_congruential.hpp&gt;
  87. typedef boost::adjacency_list&lt;&gt; Graph;
  88. typedef boost::small_world_iterator&lt;boost::minstd_rand, Graph&gt; SWGen;
  89. int main()
  90. {
  91. boost::minstd_rand gen;
  92. // Create graph with 100 nodes
  93. Graph g(SWGen(gen, 100, 6, 0.03), SWGen(), 100);
  94. return 0;
  95. }
  96. </pre>
  97. <br>
  98. <HR>
  99. <TABLE>
  100. <TR valign=top>
  101. <TD nowrap>Copyright &copy; 2005</TD><TD>
  102. <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>
  103. <A HREF="https://homes.cs.washington.edu/~al75">Andrew Lumsdaine</A>,
  104. Indiana University (<script language="Javascript">address("osl.iu.edu", "lums")</script>)
  105. </TD></TR></TABLE>
  106. </BODY>
  107. </HTML>