C++ 如何使用boostlib计算邻接列表的介数?
我正试图编写一个简单的程序,使用boostlib中的brandes_betweenness_centrality计算中间性。我被困在获取输出(CentralityMap)上。我一直在阅读文档,但我不知道如何把它们放在一起 以下是我的简单代码:C++ 如何使用boostlib计算邻接列表的介数?,c++,boost,boost-graph,C++,Boost,Boost Graph,我正试图编写一个简单的程序,使用boostlib中的brandes_betweenness_centrality计算中间性。我被困在获取输出(CentralityMap)上。我一直在阅读文档,但我不知道如何把它们放在一起 以下是我的简单代码: #include <iostream> // std::cout #include <utility> // std::pair #include <boost/graph/graph_traits.hpp> #inc
#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;
}
#包括//std::cout
#include//std::pair
#包括
#包括
#包括
使用名称空间boost;
int main()
{
int-nVertices=100;
srand(时间(空));
typedef std::对边;
向量边;
对于(int i=0;i而言,填写缺失部分的最简单方法是:
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));
boost::共享数组属性映射
中心性映射(num_顶点(g),get(boost::顶点索引,g));
然后将centrality\u map
作为centrality map传递给brandes\u betweenness\u centrality