使用boost graph library计算图中点和边的betweenness

项目中用到的东西,betweenness是社交网络里的概念。基于的思想是betweenness高的点和边在网络中更重要。betweenness具体定义见这里

搜了一下发现boost已经有实现,但是用起来也真是费了牛劲。模版类一不小心就写错,而且编译出错信息完全看不出来什么。

搜了文档和例子才算写好了。。

下面是一个星状图的例子:

input:
0 1 1 // an edge from 0 to 1, weight 1
0 2 1
0 3 1
0 4 1
0 5 1
0 6 1
6 7 1
output:
edge centrality:
(0 1): 7
(0 2): 7
(0 3): 7
(0 4): 7
(0 5): 7
(0 6): 12
(6 7): 7
vertex centrality:
0: 20
1: 0
2: 0
3: 0
4: 0
5: 0
6: 6
7: 0

下面是代码:

代码中实现了对点的重新编码,而且只需要修改一下图的typedef就可以切换有向无向图

#include <boost/config.hpp>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <fstream>
#include <set>
#include <vector>
#include <cstdio>
#include <map>

#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/format.hpp>

#include <boost/graph/graphviz.hpp>

//For clustering
#include <boost/graph/bc_clustering.hpp>
#include <boost/graph/iteration_macros.hpp>
#include <boost/property_tree/ptree.hpp>


using namespace boost;

typedef adjacency_list < lis
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值