首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用boostlib计算邻接表的介数?

如何使用boostlib计算邻接表的介数?
EN

Stack Overflow用户
提问于 2011-10-10 04:33:42
回答 1查看 2.3K关注 0票数 0

我正在尝试编写一个简单的程序来使用boostlib中的brandes_betweenness_centrality来计算中间值。我在获取输出(CentralityMap)时遇到了困难。我一直在阅读文档,但我不知道如何将它们组合在一起。

下面是我的简单代码:

代码语言:javascript
运行
复制
#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;
}

根据我的理解,我需要定义结果将被写入的中心性图。它与读/写属性映射相关,但我不知道如何定义它。

最终,我需要输出介数。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-09 13:48:04

填充缺失部分的最简单方法是:

代码语言:javascript
运行
复制
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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7706391

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档