簡體   English   中英

Boost Graph Library C ++ /冪定律

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

我有一個具有id,x和y坐標的頂點向量,我想為我的頂點生成冪律圖。 Boost庫圖提供了冪定律plod_iterator(),但如何使用頂點生成該定律。 有人可以幫忙嗎?

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

這可能不是絕對最佳的方法,但是它使我能夠完成工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM