简体   繁体   English

Boost Graph Library C ++ /幂定律

[英]Boost Graph Library C++/ Power Law

I have a vector of vertex with id,x & y coordinates, I want to generate a power law graph for my vertices. 我有一个具有id,x和y坐标的顶点向量,我想为我的顶点生成幂律图。 The Boost Library graph provide power law plod_iterator() but how can I generate that with my vertices. Boost库图提供了幂定律plod_iterator(),但如何使用顶点生成该定律。 anyone can help? 有人可以帮忙吗?

The Boost documentation states that these are generators. Boost文档指出这些是生成器。

"This class template implements a generator for scale-free graphs using the Power Law Out Degree (PLOD) algorithm" ( http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/plod_generator.html ) “此类模板使用幂律出位度(PLOD)算法为无标度图实现了生成器”( http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/plod_generator.html

It is a little confusing that it says iterator. 它说迭代器有点令人困惑。

I would instead create a vector of structs with your data then generate a power-law graph with the same number of nodes. 相反,我将使用您的数据创建一个结构向量,然后生成具有相同数量节点的幂律图。

Modified from boost documentation: 从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;
}

Here this will set of a scale free graph with 100 nodes using the power-law exponent of 2.5. 在这里,将使用2.5的幂律指数设置一个具有100个节点的无标度图。

Then when you want to access a node's data, just access its index and do a look up in your struct vector. 然后,当您要访问节点的数据时,只需访问其索引并在结构向量中进行查找即可。 You can get the index like this: 您可以像这样获取索引:

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

This may not be the absolute best way, but it has enabled me to get my work done. 这可能不是绝对最佳的方法,但是它使我能够完成工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM