gpt4 book ai didi

c++ - Boost 图形库 C++/幂律

转载 作者:行者123 更新时间:2023-11-28 00:31:02 28 4
gpt4 key购买 nike

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

最佳答案

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

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

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

我会使用您的数据创建结构 vector ,然后生成具有相同节点数的幂律图。

根据 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 个节点的无标度图。

然后当你想访问一个节点的数据时,只需访问它的索引并在你的结构 vector 中查找。你可以这样获取索引:

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

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

关于c++ - Boost 图形库 C++/幂律,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22928602/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com