2013-08-02 34 views
-1

我想使用Boost Graph Library C++中的dense_boruvka_minimum_spanning_tree函數。我想要做的是生成一個隨機圖,然後將其輸入到該函數中並行運行Boruvka算法。任何人都可以通過幾行代碼來幫助我如何使用函數?請幫助我使用Boost Graph Library

+0

這個問題沒有顯示研究的跡象。閱讀文檔,谷歌,嘗試一些代碼。如果仍然卡住,請發佈代碼並尋求具體幫助。 – ravenspoint

回答

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));