benchmark/swap_bipartite_bench.cc
author alpar
Thu, 12 Oct 2006 10:53:49 +0000
changeset 2236 9f329faa4aee
parent 2208 37b5c870a953
child 2239 18c24fe93b99
permissions -rw-r--r--
EdgeLookUp and AllEdgeLookUp tests added.
     1 #include <cstdlib>
     2 #include <iostream>
     3 #include <sstream>
     4 
     5 #include <lemon/smart_graph.h>
     6 
     7 #include <lemon/bpugraph_adaptor.h>
     8 #include <lemon/bipartite_matching.h>
     9 
    10 #include <lemon/graph_utils.h>
    11 #include <lemon/graph_to_eps.h>
    12 
    13 #include <lemon/time_measure.h>
    14 
    15 using namespace std;
    16 using namespace lemon;
    17 
    18 typedef SmartBpUGraph Graph;
    19 BPUGRAPH_TYPEDEFS(Graph);
    20 
    21 int _urandom_init() {
    22   int seed = time(0);
    23   srand(seed);
    24   return seed;
    25 }
    26 
    27 int urandom(int n) {
    28   static int seed = _urandom_init();
    29   ignore_unused_variable_warning(seed);
    30   return (int)(rand() / (1.0 + RAND_MAX) * n);
    31 }
    32 
    33 int main() {
    34 
    35   for (int k = 1; k < 100; ++k) {
    36     
    37     int n = k * 100;
    38     int m = (100 - k) * 100;
    39     int e = 20000;
    40     int s = 100;
    41     
    42     Timer nt(false), st(false);
    43     
    44     for (int i = 0; i < s; ++i) {
    45       Graph graph;
    46       vector<Node> aNodes;
    47       vector<Node> bNodes;  
    48       
    49       for (int i = 0; i < n; ++i) {
    50         Node node = graph.addANode();
    51         aNodes.push_back(node);
    52       }
    53       for (int i = 0; i < m; ++i) {
    54         Node node = graph.addBNode();
    55         bNodes.push_back(node);
    56       }
    57       for (int i = 0; i < e; ++i) {
    58         Node aNode = aNodes[urandom(n)];
    59         Node bNode = bNodes[urandom(m)];
    60         graph.addEdge(aNode, bNode);
    61       }
    62 
    63       {
    64         MaxBipartiteMatching<Graph> bpmatch(graph);
    65         
    66         nt.start();
    67         bpmatch.init();
    68         bpmatch.start();
    69         nt.stop();
    70         
    71       }
    72 
    73       {
    74         typedef SwapBpUGraphAdaptor<Graph> SGraph;
    75         SGraph sgraph(graph);
    76         MaxBipartiteMatching<SGraph> bpmatch(sgraph);
    77 
    78         st.start();
    79         bpmatch.init();
    80         bpmatch.start();
    81         st.stop();
    82         
    83       }
    84                   
    85     }
    86 
    87     cout << k * 100 << ' ' << nt.realTime() << ' ' << st.realTime() << endl;
    88 
    89   }
    90 
    91   return 0;
    92 }