marci@617: // -*- c++ -*- marci@617: #include marci@617: #include marci@617: #include marci@617: #include marci@617: marci@617: #include marci@617: #include marci@617: #include marci@617: #include marci@617: marci@617: #include marci@648: #include marci@617: //#include marci@617: //#include alpar@921: #include marci@769: #include alpar@921: #include marci@617: #include alpar@921: #include alpar@921: #include marci@617: marci@770: using std::cin; marci@769: using std::cout; marci@769: using std::endl; marci@617: alpar@921: using namespace lemon; marci@617: marci@617: int main() { marci@617: //for leda graph marci@617: leda::graph lg; marci@617: //lg.make_undirected(); marci@617: typedef LedaGraphWrapper Graph; marci@617: Graph g(lg); marci@617: marci@648: //for UndirSageGraph marci@648: //typedef UndirSageGraph Graph; marci@617: //Graph g; marci@617: marci@617: typedef Graph::Node Node; marci@617: typedef Graph::NodeIt NodeIt; marci@617: typedef Graph::Edge Edge; marci@617: typedef Graph::EdgeIt EdgeIt; marci@617: typedef Graph::OutEdgeIt OutEdgeIt; marci@617: marci@617: std::vector s_nodes; marci@617: std::vector t_nodes; marci@617: marci@617: int a; marci@769: cout << "number of nodes in the first color class="; marci@770: cin >> a; marci@617: int b; marci@769: cout << "number of nodes in the second color class="; marci@770: cin >> b; marci@617: int m; marci@769: cout << "number of edges="; marci@770: cin >> m; marci@617: int k; marci@769: cout << "A bipartite graph is a random group graph if the color classes \nA and B are partitiones to A_0, A_1, ..., A_{k-1} and B_0, B_1, ..., B_{k-1} \nas equally as possible \nand the edges from A_i goes to A_{i-1 mod k} and A_{i+1 mod k}.\n"; marci@769: cout << "number of groups in LEDA random group graph="; marci@770: cin >> k; marci@769: cout << endl; marci@617: marci@617: leda_list lS; marci@617: leda_list lT; marci@617: random_bigraph(lg, a, b, m, lS, lT, k); marci@617: marci@617: Graph::NodeMap ref_map(g, -1); marci@617: IterableBoolMap< Graph::NodeMap > bipartite_map(ref_map); marci@617: marci@617: //generating leda random group graph marci@617: leda_node ln; marci@617: forall(ln, lS) bipartite_map.insert(ln, false); marci@617: forall(ln, lT) bipartite_map.insert(ln, true); marci@617: marci@617: //making bipartite graph marci@617: typedef BipartiteGraphWrapper BGW; marci@617: BGW bgw(g, bipartite_map); marci@617: marci@617: marci@617: //st-wrapper marci@768: typedef stBipartiteGraphWrapper stGW; marci@617: stGW stgw(bgw); marci@617: ConstMap const1map(1); marci@617: stGW::EdgeMap flow(stgw); marci@617: marci@617: Timer ts; marci@617: marci@617: ts.reset(); marci@617: FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0); marci@617: MaxFlow, stGW::EdgeMap > marci@617: max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow/*, true*/); marci@617: max_flow_test.run(); alpar@921: cout << "LEMON max matching algorithm based on preflow." << endl marci@617: << "Size of matching: " marci@769: << max_flow_test.flowValue() << endl; marci@769: cout << "elapsed time: " << ts << endl << endl; marci@617: marci@617: ts.reset(); marci@617: leda_list ml=MAX_CARD_BIPARTITE_MATCHING(lg); marci@769: cout << "LEDA max matching algorithm." << endl marci@617: << "Size of matching: " marci@769: << ml.size() << endl; marci@769: cout << "elapsed time: " << ts << endl << endl; marci@617: marci@617: // ts.reset(); marci@617: // FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0); marci@648: // typedef SageGraph MutableGraph; marci@617: // while (max_flow_test.augmentOnBlockingFlow()) { } alpar@921: // cout << "LEMON max matching algorithm based on blocking flow augmentation." marci@769: // << endl << "Matching size: " marci@769: // << max_flow_test.flowValue() << endl; marci@769: // cout << "elapsed time: " << ts << endl << endl; marci@617: marci@617: { marci@648: SageGraph hg; marci@648: SageGraph::Node s=hg.addNode(); marci@648: SageGraph::Node t=hg.addNode(); marci@648: BGW::NodeMap b_s_nodes(bgw); marci@648: BGW::NodeMap b_t_nodes(bgw); marci@617: marci@617: FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, BGW::S_CLASS) { marci@617: b_s_nodes.set(n, hg.addNode()); marci@617: hg.addEdge(s, b_s_nodes[n]); marci@617: } marci@617: FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, BGW::T_CLASS) { marci@617: b_t_nodes.set(n, hg.addNode()); marci@617: hg.addEdge(b_t_nodes[n], t); marci@617: } marci@617: marci@617: FOR_EACH_LOC(BGW::EdgeIt, e, bgw) alpar@986: hg.addEdge(b_s_nodes[bgw.source(e)], b_t_nodes[bgw.target(e)]); marci@617: marci@648: ConstMap cm(1); marci@648: SageGraph::EdgeMap flow(hg); //0 marci@617: marci@617: Timer ts; marci@617: marci@617: ts.reset(); marci@648: MaxFlow, marci@648: SageGraph::EdgeMap > marci@617: max_flow_test(hg, s, t, cm, flow); marci@617: max_flow_test.run(); alpar@921: cout << "LEMON max matching algorithm on SageGraph by copying the graph, based on preflow." marci@769: << endl marci@617: << "Size of matching: " marci@769: << max_flow_test.flowValue() << endl; marci@769: cout << "elapsed time: " << ts << endl << endl; marci@617: } marci@617: marci@617: return 0; marci@617: }