#include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace lemon; typedef SmartBpUGraph Graph; typedef ListBpUGraph LGraph; BPUGRAPH_TYPEDEFS(Graph); int _urandom_init() { int seed = time(0); srand(seed); return seed; } int urandom(int n) { static int seed = _urandom_init(); ignore_unused_variable_warning(seed); return (int)(rand() / (1.0 + RAND_MAX) * n); } int main() { for (int k = 1; k < 100; ++k) { int n = k * 100; int m = (100 - k) * 100; int e = 20000; int s = 100; Timer nt(false), st(false); Timer lnt(false), lst(false); for (int i = 0; i < s; ++i) { Graph graph; LGraph lgraph; vector aNodes; vector bNodes; vector laNodes; vector lbNodes; for (int i = 0; i < n; ++i) { Node node = graph.addANode(); aNodes.push_back(node); LGraph::Node lnode = lgraph.addANode(); laNodes.push_back(lnode); } for (int i = 0; i < m; ++i) { Node node = graph.addBNode(); bNodes.push_back(node); LGraph::Node lnode = lgraph.addBNode(); lbNodes.push_back(lnode); } for (int i = 0; i < e; ++i) { int a,b; Node aNode = aNodes[a=urandom(n)]; Node bNode = bNodes[b=urandom(m)]; graph.addEdge(aNode, bNode); LGraph::Node laNode = laNodes[a]; LGraph::Node lbNode = lbNodes[b]; lgraph.addEdge(laNode, lbNode); } { MaxBipartiteMatching bpmatch(graph); nt.start(); bpmatch.init(); bpmatch.start(); nt.stop(); } { typedef SwapBpUGraphAdaptor SGraph; SGraph sgraph(graph); MaxBipartiteMatching bpmatch(sgraph); st.start(); bpmatch.init(); bpmatch.start(); st.stop(); } { MaxBipartiteMatching bpmatch(lgraph); lnt.start(); bpmatch.init(); bpmatch.start(); lnt.stop(); } { typedef SwapBpUGraphAdaptor SGraph; SGraph sgraph(lgraph); MaxBipartiteMatching bpmatch(sgraph); lst.start(); bpmatch.init(); bpmatch.start(); lst.stop(); } } cout << k * 100 << ' ' << nt.realTime() << ' ' << st.realTime() << ' ' << lnt.realTime() << ' ' << lst.realTime()<< endl; } return 0; }