项目中用到的东西,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