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