Boost C++ 库

...世界上最受尊敬和专家设计的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu,《C++ 编码标准

C++ Boost small_world_iterator(小世界迭代器)
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* 随机地重新连接到不同的顶点。小世界图表现出高聚类系数(因为顶点总是连接到它们最近的邻居),但重新连接确保了较小的直径。

定义位置

boost/graph/small_world_generator.hpp

构造函数

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