[2084] | 1 | #include <cstdlib> |
---|
| 2 | #include <iostream> |
---|
| 3 | #include <sstream> |
---|
| 4 | |
---|
| 5 | #include <lemon/smart_graph.h> |
---|
[2239] | 6 | #include <lemon/list_graph.h> |
---|
[2084] | 7 | |
---|
| 8 | #include <lemon/bpugraph_adaptor.h> |
---|
| 9 | #include <lemon/bipartite_matching.h> |
---|
| 10 | |
---|
| 11 | #include <lemon/graph_utils.h> |
---|
| 12 | #include <lemon/graph_to_eps.h> |
---|
| 13 | |
---|
| 14 | #include <lemon/time_measure.h> |
---|
[2242] | 15 | #include <lemon/random.h> |
---|
[2084] | 16 | |
---|
| 17 | using namespace std; |
---|
| 18 | using namespace lemon; |
---|
| 19 | |
---|
| 20 | typedef SmartBpUGraph Graph; |
---|
[2239] | 21 | typedef ListBpUGraph LGraph; |
---|
[2084] | 22 | BPUGRAPH_TYPEDEFS(Graph); |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | int main() { |
---|
| 26 | |
---|
| 27 | for (int k = 1; k < 100; ++k) { |
---|
| 28 | |
---|
| 29 | int n = k * 100; |
---|
| 30 | int m = (100 - k) * 100; |
---|
| 31 | int e = 20000; |
---|
| 32 | int s = 100; |
---|
| 33 | |
---|
| 34 | Timer nt(false), st(false); |
---|
[2239] | 35 | Timer lnt(false), lst(false); |
---|
[2084] | 36 | |
---|
| 37 | for (int i = 0; i < s; ++i) { |
---|
| 38 | Graph graph; |
---|
[2239] | 39 | LGraph lgraph; |
---|
[2084] | 40 | vector<Node> aNodes; |
---|
| 41 | vector<Node> bNodes; |
---|
[2239] | 42 | vector<LGraph::Node> laNodes; |
---|
| 43 | vector<LGraph::Node> lbNodes; |
---|
[2084] | 44 | |
---|
| 45 | for (int i = 0; i < n; ++i) { |
---|
| 46 | Node node = graph.addANode(); |
---|
| 47 | aNodes.push_back(node); |
---|
[2239] | 48 | LGraph::Node lnode = lgraph.addANode(); |
---|
| 49 | laNodes.push_back(lnode); |
---|
[2084] | 50 | } |
---|
| 51 | for (int i = 0; i < m; ++i) { |
---|
| 52 | Node node = graph.addBNode(); |
---|
| 53 | bNodes.push_back(node); |
---|
[2239] | 54 | LGraph::Node lnode = lgraph.addBNode(); |
---|
| 55 | lbNodes.push_back(lnode); |
---|
[2084] | 56 | } |
---|
| 57 | for (int i = 0; i < e; ++i) { |
---|
[2239] | 58 | int a,b; |
---|
[2242] | 59 | Node aNode = aNodes[a=rnd[n]]; |
---|
| 60 | Node bNode = bNodes[b=rnd[m]]; |
---|
[2084] | 61 | graph.addEdge(aNode, bNode); |
---|
[2239] | 62 | LGraph::Node laNode = laNodes[a]; |
---|
| 63 | LGraph::Node lbNode = lbNodes[b]; |
---|
| 64 | lgraph.addEdge(laNode, lbNode); |
---|
[2084] | 65 | } |
---|
| 66 | |
---|
| 67 | { |
---|
| 68 | MaxBipartiteMatching<Graph> bpmatch(graph); |
---|
| 69 | |
---|
| 70 | nt.start(); |
---|
| 71 | bpmatch.init(); |
---|
| 72 | bpmatch.start(); |
---|
| 73 | nt.stop(); |
---|
| 74 | |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | { |
---|
| 78 | typedef SwapBpUGraphAdaptor<Graph> SGraph; |
---|
| 79 | SGraph sgraph(graph); |
---|
| 80 | MaxBipartiteMatching<SGraph> bpmatch(sgraph); |
---|
| 81 | |
---|
| 82 | st.start(); |
---|
| 83 | bpmatch.init(); |
---|
| 84 | bpmatch.start(); |
---|
| 85 | st.stop(); |
---|
| 86 | |
---|
[2239] | 87 | } |
---|
| 88 | { |
---|
| 89 | MaxBipartiteMatching<LGraph> bpmatch(lgraph); |
---|
| 90 | |
---|
| 91 | lnt.start(); |
---|
| 92 | bpmatch.init(); |
---|
| 93 | bpmatch.start(); |
---|
| 94 | lnt.stop(); |
---|
| 95 | |
---|
[2084] | 96 | } |
---|
| 97 | |
---|
[2239] | 98 | { |
---|
| 99 | typedef SwapBpUGraphAdaptor<LGraph> SGraph; |
---|
| 100 | SGraph sgraph(lgraph); |
---|
| 101 | MaxBipartiteMatching<SGraph> bpmatch(sgraph); |
---|
| 102 | |
---|
| 103 | lst.start(); |
---|
| 104 | bpmatch.init(); |
---|
| 105 | bpmatch.start(); |
---|
| 106 | lst.stop(); |
---|
| 107 | |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | cout << k * 100 << ' ' << nt.realTime() << ' ' << st.realTime() |
---|
| 112 | << ' ' << lnt.realTime() << ' ' << lst.realTime()<< endl; |
---|
[2084] | 113 | |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | return 0; |
---|
| 117 | } |
---|