Copyright header added.
2 * src/test/kruskal_test.cc - Part of HUGOlib, a generic C++ optimization library
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
20 #include "test_tools.h"
21 #include <hugo/maps.h>
22 #include <hugo/kruskal.h>
23 #include <hugo/list_graph.h>
24 #include <hugo/skeletons/maps.h>
25 #include <hugo/skeletons/graph.h>
31 void checkCompileKruskal()
33 skeleton::WriteMap<skeleton::StaticGraph::Edge,bool> w;
35 kruskalEdgeMap(skeleton::StaticGraph(),
36 skeleton::ReadMap<skeleton::StaticGraph::Edge,int>(),
42 typedef ListGraph::Node Node;
43 typedef ListGraph::Edge Edge;
44 typedef ListGraph::NodeIt NodeIt;
45 typedef ListGraph::EdgeIt EdgeIt;
56 Edge e1 = G.addEdge(s, v1);
57 Edge e2 = G.addEdge(s, v2);
58 Edge e3 = G.addEdge(v1, v2);
59 Edge e4 = G.addEdge(v2, v1);
60 Edge e5 = G.addEdge(v1, v3);
61 Edge e6 = G.addEdge(v3, v2);
62 Edge e7 = G.addEdge(v2, v4);
63 Edge e8 = G.addEdge(v4, v3);
64 Edge e9 = G.addEdge(v3, t);
65 Edge e10 = G.addEdge(v4, t);
67 typedef ListGraph::EdgeMap<int> ECostMap;
68 typedef ListGraph::EdgeMap<bool> EBoolMap;
70 ECostMap edge_cost_map(G, 2);
74 //Test with const map.
75 check(kruskalEdgeMap(G, ConstMap<ListGraph::Edge,int>(2), tree_map)==10,
76 "Total cost should be 10");
77 //Test with a edge map (filled with uniform costs).
78 check(kruskalEdgeMap(G, edge_cost_map, tree_map)==10,
79 "Total cost should be 10");
81 edge_cost_map.set(e1, -10);
82 edge_cost_map.set(e2, -9);
83 edge_cost_map.set(e3, -8);
84 edge_cost_map.set(e4, -7);
85 edge_cost_map.set(e5, -6);
86 edge_cost_map.set(e6, -5);
87 edge_cost_map.set(e7, -4);
88 edge_cost_map.set(e8, -3);
89 edge_cost_map.set(e9, -2);
90 edge_cost_map.set(e10, -1);
92 vector<Edge> tree_edge_vec;
94 //Test with a edge map and inserter.
95 check(kruskalEdgeMap_IteratorOut(G, edge_cost_map,
96 back_inserter(tree_edge_vec))
98 "Total cost should be -31.");
100 tree_edge_vec.clear();
102 //The above test could also be coded like this:
104 makeKruskalMapInput(G, edge_cost_map),
105 makeKruskalSequenceOutput(back_inserter(tree_edge_vec)))
107 "Total cost should be -31.");
109 check(tree_edge_vec.size()==5,"The tree should have 5 edges.");
111 check(tree_edge_vec[0]==e1 &&
112 tree_edge_vec[1]==e2 &&
113 tree_edge_vec[2]==e5 &&
114 tree_edge_vec[3]==e7 &&
115 tree_edge_vec[4]==e9,