3 Copyright (c) The Trustees of Indiana University
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
9 Authors: Douglas Gregor
13 <Title>Boost Graph Library: Small World Generator
</Title>
14 <script language=
"JavaScript" type=
"text/JavaScript">
16 function address(host, user) {
18 var thingy = user+atchar+host;
19 thingy = '<a hre' + 'f=' + "mai" + "lto:" + thingy + '>' + user+atchar+host + '</a>';
20 document.write(thingy);
26 <BODY BGCOLOR=
"#ffffff" LINK=
"#0000ee" TEXT=
"#000000" VLINK=
"#551a8b"
28 <IMG SRC=
"../../../boost.png"
29 ALT=
"C++ Boost" width=
"277" height=
"86">
31 <tt>small_world_iterator
</tt>
36 template
<typename RandomGenerator, typename Graph
>
37 class small_world_iterator
40 typedef std::input_iterator_tag iterator_category;
41 typedef std::pair
<vertices_size_type, vertices_size_type
> value_type;
42 typedef const value_type
& reference;
43 typedef const value_type* pointer;
44 typedef void difference_type;
46 small_world_iterator();
47 small_world_iterator(RandomGenerator
& gen, vertices_size_type n,
48 vertices_size_type k, double probability =
0.,
49 bool allow_self_loops = false);
50 // Iterator operations
51 reference operator*() const;
52 pointer operator-
>() const;
53 small_world_iterator
& operator++();
54 small_world_iterator operator++(int);
55 bool operator==(const small_world_iterator
& other) const;
56 bool operator!=(const small_world_iterator
& other) const;
60 <p> This class template implements a generator for small-world graphs,
61 suitable for initializing an
<a
62 href=
"adjacency_list.html"><tt>adjacency_list
</tt></a> or other graph
63 structure with iterator-based initialization. A small-world graph
64 consists of a ring graph (where each vertex is connected to its
65 <em>k
</em> nearest neighbors). Edges in the graph are randomly
66 rewired to different vertices with a probability
67 <em>p
</em>. Small-world graphs exhibit a high clustering coefficient
68 (because vertices are always connected to their closest neighbors),
69 but rewiring ensures a small diameter.
</p>
71 <h3>Where Defined
</h3>
73 <a href=
"../../../boost/graph/small_world_generator.hpp"><tt>boost/graph/small_world_generator.hpp
</tt></a>
77 <a name=
"default-constructor"/>
78 <pre>small_world_iterator();
</pre>
80 Constructs a past-the-end iterator.
84 small_world_iterator(RandomGenerator
& gen, vertices_size_type n,
85 vertices_size_type k, double probability =
0.,
86 bool allow_self_loops = false);
89 Constructs a small-world generator iterator that creates a
90 graph with
<tt>n
</tt> vertices, each connected to its
<tt>k
</tt>
91 nearest neighbors. Probabilities are drawn from the
92 random number generator
<tt>gen
</tt>. Self-loops are permitted only
93 when
<tt>allow_self_loops
</tt> is
<tt>true
</tt>.
99 #include
<boost/graph/adjacency_list.hpp
>
100 #include
<boost/graph/small_world_generator.hpp
>
101 #include
<boost/random/linear_congruential.hpp
>
103 typedef boost::adjacency_list
<> Graph;
104 typedef boost::small_world_iterator
<boost::minstd_rand, Graph
> SWGen;
108 boost::minstd_rand gen;
109 // Create graph with
100 nodes
110 Graph g(SWGen(gen,
100,
6,
0.03), SWGen(),
100);
119 <TD nowrap
>Copyright
© 2005</TD><TD>
120 <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>
121 <A HREF=
"http://www.osl.iu.edu/~lums">Andrew Lumsdaine
</A>,
122 Indiana University (
<script language=
"Javascript">address(
"osl.iu.edu",
"lums")
</script>)