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) Andrew Lumsdaine, 印第安纳大学 () |