-1

我想dense_boruvka_minimum_spanning_tree在 C++ Boost Graph Library 中使用该函数。我想做的是生成一个随机图,然后将其输入到该函数中以并行运行 Boruvka 算法。有人可以帮我写几行代码来了解该函数的使用方式吗?

4

1 回答 1

2

有帮助吗?

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));
于 2013-08-02T09:31:30.110 回答