diff -r 1d3a11622365 -r a5e9303a5511 src/work/marci/bipartite_matching_try_3.cc --- a/src/work/marci/bipartite_matching_try_3.cc Thu Aug 19 11:34:48 2004 +0000 +++ b/src/work/marci/bipartite_matching_try_3.cc Mon Aug 23 11:06:00 2004 +0000 @@ -17,6 +17,9 @@ using namespace hugo; +using std::cout; +using std::endl; + int main() { //typedef UndirListGraph Graph; typedef BipartiteGraph Graph; @@ -30,53 +33,54 @@ Graph g; int a; - std::cout << "number of nodes in the first color class="; + cout << "number of nodes in the first color class="; std::cin >> a; int b; - std::cout << "number of nodes in the second color class="; + cout << "number of nodes in the second color class="; std::cin >> b; int m; - std::cout << "number of edges="; + cout << "number of edges="; std::cin >> m; - std::cout << "Generatig a random bipartite graph..." << std::endl; + cout << "Generatig a random bipartite graph..." << endl; random_init(); randomBipartiteGraph(g, a, b, m); -// std::cout << "Edges of the bipartite graph:" << std::endl; -// FOR_EACH_LOC(EdgeIt, e, g) std::cout << e << " "; -// std::cout << std::endl; +// cout << "Edges of the bipartite graph:" << endl; +// FOR_EACH_LOC(EdgeIt, e, g) cout << e << " "; +// cout << endl; -// std::cout << "Nodes:" << std::endl; -// FOR_EACH_LOC(Graph::NodeIt, v, g) std::cout << v << " "; -// std::cout << std::endl; -// std::cout << "Nodes in T:" << std::endl; -// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) std::cout << v << " "; -// std::cout << std::endl; -// std::cout << "Nodes in S:" << std::endl; -// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) std::cout << v << " "; -// std::cout << std::endl; +// cout << "Nodes:" << endl; +// FOR_EACH_LOC(Graph::NodeIt, v, g) cout << v << " "; +// cout << endl; +// cout << "Nodes in T:" << endl; +// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " "; +// cout << endl; +// cout << "Nodes in S:" << endl; +// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " "; +// cout << endl; -// std::cout << "Erasing the first node..." << std::endl; +// cout << "Erasing the first node..." << endl; // NodeIt n; // g.first(n); // g.erase(n); -// std::cout << "Nodes of the bipartite graph:" << std::endl; -// FOR_EACH_GLOB(n, g) std::cout << n << " "; -// std::cout << std::endl; +// cout << "Nodes of the bipartite graph:" << endl; +// FOR_EACH_GLOB(n, g) cout << n << " "; +// cout << endl; -// std::cout << "Nodes in T:" << std::endl; -// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) std::cout << v << " "; -// std::cout << std::endl; -// std::cout << "Nodes in S:" << std::endl; -// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) std::cout << v << " "; -// std::cout << std::endl; +// cout << "Nodes in T:" << endl; +// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " "; +// cout << endl; +// cout << "Nodes in S:" << endl; +// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " "; +// cout << endl; - typedef stGraphWrapper stGW; + typedef stBipartiteGraphWrapper stGW; stGW stgw(g); ConstMap const1map(1); Timer ts; + cout << "max bipartite matching with stGraphWrapper..." << endl; ts.reset(); stGW::EdgeMap flow(stgw); MaxFlow, stGW::EdgeMap > @@ -86,14 +90,14 @@ // typedef ListGraph MutableGraph; // while (max_flow_test.augmentOnBlockingFlow1()) { // while (max_flow_test.augmentOnBlockingFlow2()) { -// std::cout << max_flow_test.flowValue() << std::endl; +// cout << max_flow_test.flowValue() << endl; // } - std::cout << "max flow value: " << max_flow_test.flowValue() << std::endl; - std::cout << "elapsed time: " << ts << std::endl; + cout << "matching value: " << max_flow_test.flowValue() << endl; + cout << "elapsed time: " << ts << endl; // FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { -// if (flow[e]) std::cout << e << std::endl; +// if (flow[e]) cout << e << endl; // } - std::cout << std::endl; + cout << endl; typedef ConstMap EdgeCap; EdgeCap ge1(1); @@ -104,12 +108,13 @@ typedef Graph::NodeMap NodeFlow; NodeFlow gnf(g); //0 - typedef stGraphWrapper::EdgeMapWrapper CapMap; - typedef stGraphWrapper::EdgeMapWrapper FlowMap; + typedef stGW::EdgeMapWrapper CapMap; + typedef stGW::EdgeMapWrapper FlowMap; CapMap cm(ge1, gn1); FlowMap fm(gef, gnf); //Timer ts; + cout << "max bipartite matching with stGraphWrapper..." << endl; ts.reset(); //stGW::EdgeMap flow(stgw); MaxFlow @@ -119,15 +124,16 @@ // typedef ListGraph MutableGraph; // while (max_flow_test.augmentOnBlockingFlow1()) { // while (max_flow_test.augmentOnBlockingFlow2()) { -// std::cout << max_flow_test.flowValue() << std::endl; +// cout << max_flow_test.flowValue() << endl; // } - std::cout << "max flow value: " << max_flow_test1.flowValue() << std::endl; - std::cout << "elapsed time: " << ts << std::endl; + cout << "matching value: " << max_flow_test1.flowValue() << endl; + cout << "elapsed time: " << ts << endl; // FOR_EACH_LOC(Graph::EdgeIt, e, g) { -// if (gef[e]) std::cout << e << std::endl; +// if (gef[e]) cout << e << endl; // } - std::cout << std::endl; + cout << endl; + cout << "max bipartite matching with stGraphWrapper..." << endl; ts.reset(); FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0); FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0); @@ -136,27 +142,41 @@ matching_test(g, ge1, gn1, gef, gnf); matching_test.run(); - std::cout << "max flow value: " << matching_test.matchingValue() << std::endl; - std::cout << "elapsed time: " << ts << std::endl; + cout << "matching value: " << matching_test.matchingValue() << endl; + cout << "elapsed time: " << ts << endl; // FOR_EACH_LOC(Graph::EdgeIt, e, g) { -// if (gef[e]) std::cout << e << std::endl; +// if (gef[e]) cout << e << endl; // } - std::cout << std::endl; + cout << endl; + cout << "max bipartite matching with MaxBipartiteMatching..." << endl; ts.reset(); FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0); //FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0); - MaxBipartiteMatching, ConstMap, - Graph::EdgeMap, Graph::NodeMap > - matching_test_1(g, ge1, gn1, gef/*, gnf*/); + typedef MaxBipartiteMatching, + ConstMap, + Graph::EdgeMap, Graph::NodeMap > MaxBipartiteMatching; + MaxBipartiteMatching matching_test_1(g, ge1, gn1, gef/*, gnf*/); matching_test_1.run(); - std::cout << "max flow value: " << matching_test_1.matchingValue() << std::endl; - std::cout << "elapsed time: " << ts << std::endl; + cout << "matching value: " << matching_test_1.matchingValue() << endl; + cout << "elapsed time: " << ts << endl; // FOR_EACH_LOC(Graph::EdgeIt, e, g) { -// if (gef[e]) std::cout << e << std::endl; +// if (gef[e]) cout << e << endl; // } - std::cout << std::endl; + cout << endl; + + cout << "testing optimality with MaxBipartiteMatching..." << endl; + ts.reset(); + matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING); + cout << "matching value: " << matching_test_1.matchingValue() << endl; + cout << "elapsed time: " << ts << endl; + + cout << "testing optimality with MaxBipartiteMatching..." << endl; + ts.reset(); + matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING_WITH_GOOD_NODE_FLOW); + cout << "matching value: " << matching_test_1.matchingValue() << endl; + cout << "elapsed time: " << ts << endl; return 0; }