#include #include #include #include int main() { using namespace boost; typedef adjacency_list < vecS, vecS, undirectedS, property, property < edge_weight_t, int > > Graph; typedef std::pair < int, int >E; const int num_nodes = 6; #if SPECIFY_ONCE E edges_l[] = { E(0, 1), E(0, 2), E(0, 3), E(0, 4), E(0, 5), E(1, 2), E(1, 3), E(1, 4), E(1, 5), E(2, 3), E(2, 4), E(2, 5), E(3, 4), E(3, 5), E(4, 5), }; int weights[] = { 6, 7, 26, 9, 2, 1, 26, 10, 5, 27, 11, 6, 17, 24, 7, }; #else E edges_l[] = { E(0, 1), E(0, 2), E(0, 3), E(0, 4), E(0, 5), E(1, 0), E(1, 2), E(1, 3), E(1, 4), E(1, 5), E(2, 0), E(2, 1), E(2, 3), E(2, 4), E(2, 5), E(3, 0), E(3, 1), E(3, 2), E(3, 4), E(3, 5), E(4, 0), E(4, 1), E(4, 2), E(4, 3), E(4, 5), E(5, 0), E(5, 1), E(5, 2), E(5, 3), E(5, 4) }; int weights[] = { 6, 7, 26, 9, 2, 6, 1, 26, 10, 5, 7, 1, 27, 11, 6, 26, 26, 27, 17, 24, 9, 10, 11, 17, 7, 2, 5, 6, 24, 7 }; #endif Graph g(edges_l, edges_l + sizeof(edges_l) / sizeof(E), weights, num_nodes); property_map::type weightmap = get(edge_weight, g); std::vector < graph_traits < Graph >::vertex_descriptor > p(num_vertices(g)); #if DEBUG typedef graph_traits::edge_iterator edge_iterator; edge_iterator ei, e_end; std::cout << " edge info: " << std::endl; for ( tie(ei, e_end) = edges(g); ei != e_end; ++ei ) { std::cout << " from " << source(*ei, g); std::cout << " to " << target(*ei, g); std::cout << " weight " << weightmap[*ei]; std::cout << std::endl; } std::cout << std::endl; #endif prim_minimum_spanning_tree(g, &p[0]); for (std::size_t i = 0; i != p.size(); ++i) if (p[i] != i) std::cout << "parent[" << i << "] = " << p[i] << std::endl; else std::cout << "parent[" << i << "] = no parent" << std::endl; return EXIT_SUCCESS; }