0

我有一个带有 id、x 和 y 坐标的顶点向量,我想为我的顶点生成一个幂律图。Boost Library 图提供幂律plod_iterator()但我如何用我的顶点生成它。有人可以帮忙吗?

4

1 回答 1

3

Boost 文档指出这些是生成器。

“此类模板使用幂律输出度 (PLOD) 算法实现了无标度图生成器”(http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/plod_generator.html

它说迭代器有点令人困惑。

相反,我会用您的数据创建一个结构向量,然后生成一个具有相同数量节点的幂律图。

从 boost 文档修改:

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/plod_generator.hpp>
#include <boost/random/linear_congruential.hpp>

struct VertData{
  size_t id;
  size_t x;
  size_t y;
};

typedef boost::adjacency_list<> Graph;
typedef boost::plod_iterator<boost::minstd_rand, Graph> SFGen;

int main()
{

  vector<VertData> vertData;
  //... Initialize with data ...


  boost::minstd_rand gen;
  // Create graph with 100 nodes 
  Graph g(SFGen(gen, 100, 2.5, 1000), SFGen(), 100);


  typedef property_map<Graph, vertex_index_t >::type VertexIndexMap;
  VertexIndexMap iMap = get(vertex_index,g);
  // ... get some vertex v
  size_t vertexIndex = iMap[v];
  //...
  vertexData.at(vertexIndex).x = 4;//or what ever



  return 0;
}

在这里,这将使用 2.5 的幂律指数设置具有 100 个节点的无标度图。

然后,当您想要访问节点的数据时,只需访问其索引并在您的结构向量中进行查找。您可以像这样获取索引:

typedef property_map<Graph, vertex_index_t >::type VertexIndexMap;
VertexIndexMap iMap = get(vertex_index,g);
size_t vertexIndex = iMap[v];
...
vertexData.at(vertexIndex).x = 4;//or what ever

这可能不是绝对最好的方法,但它使我能够完成我的工作。

于 2014-04-08T13:03:54.533 回答