请帮助我使用Boost Graph Library

时间:2013-08-02 09:11:55

标签: parallel-processing boost-graph minimum-spanning-tree

我想在Boost Graph Library,C ++中使用dense_boruvka_minimum_spanning_tree函数。我想要做的是生成一个随机图,然后将其输入到该函数中以并行运行Boruvka算法。对于如何使用这个函数,有没有人可以用几行代码来帮助我?

1 个答案:

答案 0 :(得分:2)

this有帮助吗?

typedef adjacency_list<listS, 
                     distributedS<mpi_process_group, vecS>,
                     undirectedS,
                     no_property,
                     property<edge_weight_t, int> > Graph;

typedef graph_traits<Graph>::vertex_descriptor vertex_descriptor;
typedef graph_traits<Graph>::vertex_iterator vertex_iterator;
typedef graph_traits<Graph>::edge_descriptor edge_descriptor;

typedef std::pair<int, int> E;

const int num_nodes = 5;
E edge_array[] = { E(0, 2), E(1, 3), E(1, 4), E(2, 1), E(2, 3),
    E(3, 4), E(4, 0), E(4, 1)
};
int weights[] = { 1, 1, 2, 7, 3, 1, 1, 1 };
std::size_t num_edges = sizeof(edge_array) / sizeof(E);

Graph g(edge_array, edge_array + num_edges, weights, num_nodes);

typedef property_map<Graph, edge_weight_t>::type WeightMap;
WeightMap weight_map = get(edge_weight, g);

std::vector<edge_descriptor> mst_edges;
dense_boruvka_minimum_spanning_tree(make_vertex_list_adaptor(g), 
                                    weight_map, 
                                    std::back_inserter(mst_edges));