athos@1182: #include athos@1182: #include athos@1182: athos@1182: #include athos@1182: #include athos@1182: #include athos@1182: athos@1182: athos@1182: using namespace std; athos@1182: using namespace lemon; athos@1182: athos@1182: athos@1182: int main() { athos@1182: athos@1182: typedef ListGraph::Node Node; athos@1182: typedef ListGraph::Edge Edge; athos@1182: typedef ListGraph::NodeIt NodeIt; athos@1182: typedef ListGraph::EdgeIt EdgeIt; athos@1182: athos@1182: ListGraph G; athos@1182: athos@1182: Node s=G.addNode(); athos@1182: Node v1=G.addNode(); athos@1182: Node v2=G.addNode(); athos@1182: Node v3=G.addNode(); athos@1182: Node v4=G.addNode(); athos@1182: Node t=G.addNode(); athos@1182: athos@1182: Edge e1 = G.addEdge(s, v1); athos@1182: Edge e2 = G.addEdge(s, v2); athos@1182: Edge e3 = G.addEdge(v1, v2); athos@1182: Edge e4 = G.addEdge(v2, v1); athos@1182: Edge e5 = G.addEdge(v1, v3); athos@1182: Edge e6 = G.addEdge(v3, v2); athos@1182: Edge e7 = G.addEdge(v2, v4); athos@1182: Edge e8 = G.addEdge(v4, v3); athos@1182: Edge e9 = G.addEdge(v3, t); athos@1182: Edge e10 = G.addEdge(v4, t); athos@1182: athos@1182: typedef ListGraph::EdgeMap ECostMap; athos@1182: typedef ListGraph::EdgeMap EBoolMap; athos@1182: athos@1182: ECostMap edge_cost_map(G, 2); athos@1182: EBoolMap tree_map(G); athos@1182: athos@1182: athos@1182: //Test with const map. athos@1182: std::cout << "The weight of the minimum spanning tree is " << kruskalEdgeMap(G, ConstMap(2), tree_map)< tree_edge_vec; athos@1182: athos@1182: //Test with a edge map and inserter. athos@1182: check(kruskalEdgeMap_IteratorOut(G, edge_cost_map, athos@1182: back_inserter(tree_edge_vec)) athos@1182: ==-31, athos@1182: "Total cost should be -31."); athos@1182: athos@1182: tree_edge_vec.clear(); athos@1182: athos@1182: //The above test could also be coded like this: athos@1182: check(kruskal(G, athos@1182: makeKruskalMapInput(G, edge_cost_map), athos@1182: makeKruskalSequenceOutput(back_inserter(tree_edge_vec))) athos@1182: ==-31, athos@1182: "Total cost should be -31."); athos@1182: athos@1182: check(tree_edge_vec.size()==5,"The tree should have 5 edges."); athos@1182: athos@1182: check(tree_edge_vec[0]==e1 && athos@1182: tree_edge_vec[1]==e2 && athos@1182: tree_edge_vec[2]==e5 && athos@1182: tree_edge_vec[3]==e7 && athos@1182: tree_edge_vec[4]==e9, athos@1182: "Wrong tree."); athos@1182: */ athos@1182: return 0; athos@1182: }