template<typename RandomGenerator, typename Graph>
class small_world_iterator
{
public:
typedef std::input_iterator_tag iterator_category;
typedef std::pair<vertices_size_type, vertices_size_type> value_type;
typedef const value_type& reference;
typedef const value_type* pointer;
typedef void difference_type;
small_world_iterator();
small_world_iterator(RandomGenerator& gen, vertices_size_type n,
vertices_size_type k, double probability = 0.,
bool allow_self_loops = false);
// Iterator operations
reference operator*() const;
pointer operator->() const;
small_world_iterator& operator++();
small_world_iterator operator++(int);
bool operator==(const small_world_iterator& other) const;
bool operator!=(const small_world_iterator& other) const;
};
这个类模板实现了一个小世界图生成器,适用于使用 adjacency_list 或其他基于迭代器的初始化方式来初始化图结构。小世界图由一个环形图(其中每个顶点与其 k 个最近邻居相连)组成。图中的边会以概率 p 随机重连到不同的顶点。小世界图表现出很高的聚类系数(因为顶点始终与其最近的邻居相连),但重连确保了较小的直径。
small_world_iterator();
构造一个超出末尾的迭代器。
small_world_iterator(RandomGenerator& gen, vertices_size_type n,
vertices_size_type k, double probability = 0.,
bool allow_self_loops = false);
构造一个小世界生成器迭代器,创建一个具有n个顶点,每个顶点与其k个最近邻居相连。概率从随机数生成器gen中抽取。自环仅在allow_self_loops是true.
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/small_world_generator.hpp>
#include <boost/random/linear_congruential.hpp>
typedef boost::adjacency_list<> Graph;
typedef boost::small_world_iterator<boost::minstd_rand, Graph> SWGen;
int main()
{
boost::minstd_rand gen;
// Create graph with 100 nodes
Graph g(SWGen(gen, 100, 6, 0.03), SWGen(), 100);
return 0;
}
| 版权 © 2005 |
Doug Gregor, Indiana University () Andrew Lumsdaine, Indiana University () |