A push/relabel type max cardinality matching implementation.
(slightly incompatible with bipartite_matching.h)
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
22 #include "test_tools.h"
23 #include <lemon/maps.h>
24 #include <lemon/kruskal.h>
25 #include <lemon/list_graph.h>
26 #include <lemon/concepts/maps.h>
27 #include <lemon/concepts/graph.h>
31 using namespace lemon;
33 void checkCompileKruskal()
35 concepts::WriteMap<concepts::Graph::Edge,bool> w;
39 concepts::ReadMap<concepts::Graph::Edge,int>(),
45 typedef ListGraph::Node Node;
46 typedef ListGraph::Edge Edge;
47 typedef ListGraph::NodeIt NodeIt;
48 typedef ListGraph::EdgeIt EdgeIt;
59 Edge e1 = G.addEdge(s, v1);
60 Edge e2 = G.addEdge(s, v2);
61 Edge e3 = G.addEdge(v1, v2);
62 Edge e4 = G.addEdge(v2, v1);
63 Edge e5 = G.addEdge(v1, v3);
64 Edge e6 = G.addEdge(v3, v2);
65 Edge e7 = G.addEdge(v2, v4);
66 Edge e8 = G.addEdge(v4, v3);
67 Edge e9 = G.addEdge(v3, t);
68 Edge e10 = G.addEdge(v4, t);
70 typedef ListGraph::EdgeMap<int> ECostMap;
71 typedef ListGraph::EdgeMap<bool> EBoolMap;
73 ECostMap edge_cost_map(G, 2);
77 //Test with const map.
78 check(kruskal(G, ConstMap<ListGraph::Edge,int>(2), tree_map)==10,
79 "Total cost should be 10");
80 //Test with a edge map (filled with uniform costs).
81 check(kruskal(G, edge_cost_map, tree_map)==10,
82 "Total cost should be 10");
84 edge_cost_map.set(e1, -10);
85 edge_cost_map.set(e2, -9);
86 edge_cost_map.set(e3, -8);
87 edge_cost_map.set(e4, -7);
88 edge_cost_map.set(e5, -6);
89 edge_cost_map.set(e6, -5);
90 edge_cost_map.set(e7, -4);
91 edge_cost_map.set(e8, -3);
92 edge_cost_map.set(e9, -2);
93 edge_cost_map.set(e10, -1);
95 vector<Edge> tree_edge_vec(5);
97 //Test with a edge map and inserter.
98 check(kruskal(G, edge_cost_map,
99 tree_edge_vec.begin())
101 "Total cost should be -31.");
103 tree_edge_vec.clear();
105 check(kruskal(G, edge_cost_map,
106 back_inserter(tree_edge_vec))
108 "Total cost should be -31.");
110 tree_edge_vec.clear();
112 //The above test could also be coded like this:
114 makeKruskalMapInput(G, edge_cost_map),
115 makeKruskalSequenceOutput(back_inserter(tree_edge_vec)))
117 "Total cost should be -31.");
119 check(tree_edge_vec.size()==5,"The tree should have 5 edges.");
121 check(tree_edge_vec[0]==e1 &&
122 tree_edge_vec[1]==e2 &&
123 tree_edge_vec[2]==e5 &&
124 tree_edge_vec[3]==e7 &&
125 tree_edge_vec[4]==e9,