# HG changeset patch # User deba # Date 1152872726 0 # Node ID 54043fa66bce127f9e44bb6654d27a4299bed307 # Parent 4f64d6b3e9ecc5e50633539222f3e9fec5f0e352 Using fixed bipartite graph diff -r 4f64d6b3e9ec -r 54043fa66bce test/bipartite_matching_test.cc --- a/test/bipartite_matching_test.cc Fri Jul 14 09:37:48 2006 +0000 +++ b/test/bipartite_matching_test.cc Fri Jul 14 10:25:26 2006 +0000 @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include @@ -16,17 +16,34 @@ using namespace std; using namespace lemon; -typedef ListBpUGraph Graph; +typedef SmartBpUGraph Graph; BPUGRAPH_TYPEDEFS(Graph); -int main(int argc, const char *argv[]) { +const int n = 10; +const int m = 10; +const int e = 52; +const int c = 100; + +const int sa[e] = { 6, 5, 6, 4, 1, 0, 9, 5, 2, 4, 4, 3, 5, + 2, 3, 8, 3, 4, 9, 6, 9, 4, 3, 1, 5, 8, + 4, 8, 9, 2, 2, 3, 0, 5, 2, 3, 6, 3, 8, + 8, 4, 0, 9, 9, 6, 2, 1, 2, 7, 1, 9, 4}; + +const int ta[e] = { 2, 7, 4, 8, 6, 3, 4, 1, 7, 7, 0, 1, 6, + 3, 2, 6, 8, 3, 5, 6, 3, 1, 8, 7, 2, 0, + 6, 9, 6, 7, 8, 3, 3, 4, 5, 8, 6, 4, 1, + 4, 3, 3, 8, 7, 7, 3, 7, 7, 3, 5, 1, 6}; + +const int wa[e] = { 3, 99, 85, 16, 79, 52, 83, 99, 62, 6, 42, 6, 95, + 13, 34, 9, 5, 38, 39, 75, 99, 12, 73, 35, 93, 43, + 54, 91, 45, 26, 77, 47, 11, 22, 50, 74, 37, 64, 91, + 60, 6, 92, 29, 46, 34, 84, 67, 34, 45, 0, 39, 47}; + + +int main() { Graph graph; vector aNodes; vector bNodes; - int n = argc > 1 ? atoi(argv[1]) : 10; - int m = argc > 2 ? atoi(argv[2]) : 10; - int e = argc > 3 ? atoi(argv[3]) : (int)((n+m) * log(n+m)); - int c = argc > 4 ? atoi(argv[4]) : 100; Graph::UEdgeMap weight(graph); @@ -44,12 +61,13 @@ bNodes.push_back(node); } for (int i = 0; i < e; ++i) { - Node aNode = aNodes[urandom(n)]; - Node bNode = bNodes[urandom(m)]; + Node aNode = aNodes[sa[i]]; + Node bNode = bNodes[ta[i]]; UEdge uedge = graph.addEdge(aNode, bNode); - weight[uedge] = urandom(c); + weight[uedge] = wa[i]; } + { MaxBipartiteMatching bpmatch(graph); @@ -271,7 +289,6 @@ Graph::UEdgeMap cost(graph); cost = subMap(constMap(c), weight); - { MinCostMaxBipartiteMatching bpmatch(graph, cost); @@ -284,6 +301,11 @@ bpmatch.matching(mm); bpmatch.potential(pm); + min_cost_matching = bpmatch.matchingCost(); + check(max_cardinality == bpmatch.matchingSize(), "WRONG SIZE"); + check(max_cardinality * c - max_cardinality_max_weight + == bpmatch.matchingCost(), "WRONG SIZE"); + for (UEdgeIt it(graph); it != INVALID; ++it) { if (mm[it]) { check(pm[graph.aNode(it)] + cost[it] - pm[graph.bNode(it)] == 0,