使用boost库中的sloan_ordering算法进行图的重排序
对于一个大型的图结构,可能存在一些子图分属于不同的社区。为了更好地分析图的特征,我们可以将这个图进行重新排序,使得同一社区的节点排列在一起,不同社区的节点相对离散。本文介绍使用boost库中的sloan_ordering算法进行图的重排序。
首先,我们需要生成一个图实例,这里以随机图为例:
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/random.hpp>
#include <iostream>
int main()
{
using namespace boost;
typedef adjacency_list<vecS, vecS, undirectedS> Graph;
Graph g;
generate_random_graph(g, 10, 20, seed);
typedef graph_traits<Graph>::vertex_descriptor Vertex;
typedef property_map<Graph, vertex_index_t>::type IndexMap;
IndexMap index = get(vertex_index, g);
graph_traits<Graph>::edge_iterator ei, ei_end;
for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
std::cou