我正在尝试编写一个简单的程序来使用boostlib中的brandes_betweenness_centrality来计算中间值。我在获取输出(CentralityMap)时遇到了困难。我一直在阅读文档,但我不知道如何将它们组合在一起。
下面是我的简单代码:
#include <iostream> // std::cout
#include <utility> // std::pair
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/betweenness_centrality.hpp>
using namespace boost;
int main()
{
int nVertices = 100;
srand ( time(NULL) );
typedef std::pair<int, int> Edge;
std::vector<Edge> edges;
for(int i=0; i<nVertices; i++){
std::cout << i << " : ";
for(int j=0; j<nVertices; j++){
if(rand() % 100 < 9){ /// chances of making a connection is 9 out of 100. may not be accurate
std::cout << j << " ";
edges.push_back(std::make_pair(i,j));
}
}
std::cout << std::endl;
}
typedef adjacency_list<vecS, vecS, bidirectionalS,
property<vertex_color_t, default_color_type>
> Graph;
Graph g(edges.begin(), edges.end(), edges.size());
brandes_betweenness_centrality(g,?????? );
return 0;
}
根据我的理解,我需要定义结果将被写入的中心性图。它与读/写属性映射相关,但我不知道如何定义它。
最终,我需要输出介数。
发布于 2012-02-09 13:48:04
填充缺失部分的最简单方法是:
boost::shared_array_property_map<double, boost::property_map<Graph, vertex_index_t>::const_type>
centrality_map(num_vertices(g), get(boost::vertex_index, g));
然后将centrality_map
作为中心图传递给brandes_betweenness_centrality
。
https://stackoverflow.com/questions/7706391
复制相似问题