marci@771: // -*- c++ -*- marci@771: #include marci@771: #include marci@771: #include marci@771: marci@771: #include marci@771: //#include marci@771: //#include alpar@921: #include marci@771: #include marci@771: #include marci@771: #include alpar@921: #include alpar@921: #include marci@771: #include marci@771: #include marci@771: alpar@921: using namespace lemon; marci@771: marci@771: using std::cin; marci@771: using std::cout; marci@771: using std::endl; marci@771: marci@771: int main() { marci@771: //typedef UndirListGraph Graph; marci@771: typedef BipartiteGraph Graph; marci@771: marci@771: typedef Graph::Node Node; marci@771: typedef Graph::NodeIt NodeIt; marci@771: typedef Graph::Edge Edge; marci@771: typedef Graph::EdgeIt EdgeIt; marci@771: typedef Graph::OutEdgeIt OutEdgeIt; marci@771: marci@771: Graph g; marci@771: marci@771: int a; marci@771: cout << "number of nodes in the first color class="; marci@771: cin >> a; marci@771: int b; marci@771: cout << "number of nodes in the second color class="; marci@771: cin >> b; marci@771: int m; marci@771: cout << "number of edges="; marci@771: cin >> m; marci@771: marci@771: cout << "Generatig a random bipartite graph..." << endl; marci@771: random_init(); marci@771: randomBipartiteGraph(g, a, b, m); marci@771: marci@771: // cout << "Edges of the bipartite graph:" << endl; marci@771: // FOR_EACH_LOC(EdgeIt, e, g) cout << e << " "; marci@771: // cout << endl; marci@771: marci@771: // cout << "Nodes:" << endl; marci@771: // FOR_EACH_LOC(Graph::NodeIt, v, g) cout << v << " "; marci@771: // cout << endl; marci@771: // cout << "Nodes in T:" << endl; marci@771: // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " "; marci@771: // cout << endl; marci@771: // cout << "Nodes in S:" << endl; marci@771: // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " "; marci@771: // cout << endl; marci@771: marci@771: // cout << "Erasing the first node..." << endl; marci@771: // NodeIt n; marci@771: // g.first(n); marci@771: // g.erase(n); marci@771: // cout << "Nodes of the bipartite graph:" << endl; marci@771: // FOR_EACH_GLOB(n, g) cout << n << " "; marci@771: // cout << endl; marci@771: marci@771: // cout << "Nodes in T:" << endl; marci@771: // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " "; marci@771: // cout << endl; marci@771: // cout << "Nodes in S:" << endl; marci@771: // FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " "; marci@771: // cout << endl; marci@771: marci@771: typedef stBipartiteGraphWrapper stGW; marci@771: stGW stgw(g); marci@771: ConstMap const1map(1); marci@771: marci@771: Timer ts; marci@771: cout << "max bipartite matching with stGraphWrapper..." << endl; marci@771: ts.reset(); marci@771: stGW::EdgeMap flow(stgw); marci@771: MaxFlow, stGW::EdgeMap > marci@771: max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow); marci@771: max_flow_test.run(); marci@771: // while (max_flow_test.augmentOnShortestPath()) { } marci@771: // typedef ListGraph MutableGraph; marci@771: // while (max_flow_test.augmentOnBlockingFlow1()) { marci@771: // while (max_flow_test.augmentOnBlockingFlow2()) { marci@771: // cout << max_flow_test.flowValue() << endl; marci@771: // } marci@771: cout << "matching value: " << max_flow_test.flowValue() << endl; marci@771: cout << "elapsed time: " << ts << endl; marci@771: // FOR_EACH_LOC(stGW::EdgeIt, e, stgw) { marci@771: // if (flow[e]) cout << e << endl; marci@771: // } marci@771: cout << endl; marci@771: marci@771: typedef ConstMap EdgeCap; marci@771: EdgeCap ge1(1); marci@771: typedef ConstMap NodeCap; marci@771: NodeCap gn1(1); marci@771: typedef Graph::EdgeMap EdgeFlow; marci@771: EdgeFlow gef(g); //0 marci@771: typedef Graph::NodeMap NodeFlow; marci@771: NodeFlow gnf(g); //0 marci@771: marci@771: typedef stGW::EdgeMapWrapper CapMap; marci@771: typedef stGW::EdgeMapWrapper FlowMap; marci@771: CapMap cm(ge1, gn1); marci@771: FlowMap fm(gef, gnf); marci@771: marci@771: //Timer ts; marci@771: cout << "max bipartite matching with stGraphWrapper..." << endl; marci@771: ts.reset(); marci@771: //stGW::EdgeMap flow(stgw); marci@771: MaxFlow marci@771: max_flow_test1(stgw, stgw.S_NODE, stgw.T_NODE, cm, fm); marci@771: max_flow_test1.run(); marci@771: // while (max_flow_test.augmentOnShortestPath()) { } marci@771: // typedef ListGraph MutableGraph; marci@771: // while (max_flow_test.augmentOnBlockingFlow1()) { marci@771: // while (max_flow_test.augmentOnBlockingFlow2()) { marci@771: // cout << max_flow_test.flowValue() << endl; marci@771: // } marci@771: cout << "matching value: " << max_flow_test1.flowValue() << endl; marci@771: cout << "elapsed time: " << ts << endl; marci@771: // FOR_EACH_LOC(Graph::EdgeIt, e, g) { marci@771: // if (gef[e]) cout << e << endl; marci@771: // } marci@771: cout << endl; marci@771: marci@771: cout << "max bipartite matching with stGraphWrapper..." << endl; marci@771: ts.reset(); marci@771: FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0); marci@771: FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0); marci@771: MaxBipartiteMatching, ConstMap, marci@771: Graph::EdgeMap, Graph::NodeMap > marci@771: matching_test(g, ge1, gn1, gef, gnf); marci@771: matching_test.run(); marci@771: marci@771: cout << "matching value: " << matching_test.matchingValue() << endl; marci@771: cout << "elapsed time: " << ts << endl; marci@771: // FOR_EACH_LOC(Graph::EdgeIt, e, g) { marci@771: // if (gef[e]) cout << e << endl; marci@771: // } marci@771: cout << endl; marci@771: marci@771: cout << "max bipartite matching with MaxBipartiteMatching..." << endl; marci@771: ts.reset(); marci@771: FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0); marci@771: //FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0); marci@771: typedef MaxBipartiteMatching, marci@771: ConstMap, marci@771: Graph::EdgeMap, Graph::NodeMap > MaxBipartiteMatching; marci@771: MaxBipartiteMatching matching_test_1(g, ge1, gn1, gef/*, gnf*/); marci@771: matching_test_1.run(); marci@771: marci@771: cout << "matching value: " << matching_test_1.matchingValue() << endl; marci@771: cout << "elapsed time: " << ts << endl; marci@771: // FOR_EACH_LOC(Graph::EdgeIt, e, g) { marci@771: // if (gef[e]) cout << e << endl; marci@771: // } marci@771: cout << endl; marci@771: marci@771: cout << "testing optimality with MaxBipartiteMatching..." << endl; marci@771: ts.reset(); marci@771: matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING); marci@771: cout << "matching value: " << matching_test_1.matchingValue() << endl; marci@771: cout << "elapsed time: " << ts << endl; marci@771: marci@771: cout << "testing optimality with MaxBipartiteMatching..." << endl; marci@771: ts.reset(); marci@771: matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING_WITH_GOOD_NODE_FLOW); marci@771: cout << "matching value: " << matching_test_1.matchingValue() << endl; marci@771: cout << "elapsed time: " << ts << endl; marci@771: marci@771: return 0; marci@771: }