benchmark/swap_bipartite_bench.cc
author deba
Wed, 12 Dec 2007 13:35:55 +0000
changeset 2541 e67ec65747fa
parent 2386 81b47fc5c444
child 2553 bfced05fa852
permissions -rw-r--r--
Bug fix
alpar@2391
     1
/* -*- C++ -*-
alpar@2391
     2
 *
alpar@2391
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@2391
     4
 *
alpar@2391
     5
 * Copyright (C) 2003-2007
alpar@2391
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@2391
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@2391
     8
 *
alpar@2391
     9
 * Permission to use, modify and distribute this software is granted
alpar@2391
    10
 * provided that this copyright notice appears in all copies. For
alpar@2391
    11
 * precise terms see the accompanying LICENSE file.
alpar@2391
    12
 *
alpar@2391
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@2391
    14
 * express or implied, and with no claim as to its suitability for any
alpar@2391
    15
 * purpose.
alpar@2391
    16
 *
alpar@2391
    17
 */
alpar@2391
    18
deba@2084
    19
#include <cstdlib>
deba@2084
    20
#include <iostream>
deba@2084
    21
#include <sstream>
deba@2084
    22
deba@2084
    23
#include <lemon/smart_graph.h>
alpar@2239
    24
#include <lemon/list_graph.h>
deba@2084
    25
deba@2084
    26
#include <lemon/bpugraph_adaptor.h>
deba@2084
    27
#include <lemon/bipartite_matching.h>
deba@2084
    28
deba@2084
    29
#include <lemon/graph_utils.h>
deba@2084
    30
#include <lemon/graph_to_eps.h>
deba@2084
    31
deba@2084
    32
#include <lemon/time_measure.h>
deba@2242
    33
#include <lemon/random.h>
deba@2084
    34
deba@2084
    35
using namespace std;
deba@2084
    36
using namespace lemon;
deba@2084
    37
deba@2084
    38
typedef SmartBpUGraph Graph;
alpar@2239
    39
typedef ListBpUGraph LGraph;
deba@2084
    40
BPUGRAPH_TYPEDEFS(Graph);
deba@2084
    41
deba@2084
    42
deba@2084
    43
int main() {
deba@2084
    44
deba@2084
    45
  for (int k = 1; k < 100; ++k) {
deba@2084
    46
    
deba@2084
    47
    int n = k * 100;
deba@2084
    48
    int m = (100 - k) * 100;
deba@2084
    49
    int e = 20000;
deba@2084
    50
    int s = 100;
deba@2084
    51
    
deba@2084
    52
    Timer nt(false), st(false);
alpar@2239
    53
    Timer lnt(false), lst(false);
deba@2084
    54
    
deba@2084
    55
    for (int i = 0; i < s; ++i) {
deba@2084
    56
      Graph graph;
alpar@2239
    57
      LGraph lgraph;
deba@2084
    58
      vector<Node> aNodes;
deba@2084
    59
      vector<Node> bNodes;  
alpar@2239
    60
      vector<LGraph::Node> laNodes;
alpar@2239
    61
      vector<LGraph::Node> lbNodes;  
deba@2084
    62
      
deba@2386
    63
      for (int j = 0; j < n; ++j) {
deba@2084
    64
        Node node = graph.addANode();
deba@2084
    65
        aNodes.push_back(node);
alpar@2239
    66
        LGraph::Node lnode = lgraph.addANode();
alpar@2239
    67
        laNodes.push_back(lnode);
deba@2084
    68
      }
deba@2386
    69
      for (int j = 0; j < m; ++j) {
deba@2084
    70
        Node node = graph.addBNode();
deba@2084
    71
        bNodes.push_back(node);
alpar@2239
    72
        LGraph::Node lnode = lgraph.addBNode();
alpar@2239
    73
        lbNodes.push_back(lnode);
deba@2084
    74
      }
deba@2386
    75
      for (int j = 0; j < e; ++j) {
alpar@2239
    76
        int a,b;
deba@2242
    77
	Node aNode = aNodes[a=rnd[n]];
deba@2242
    78
        Node bNode = bNodes[b=rnd[m]];
deba@2084
    79
        graph.addEdge(aNode, bNode);
alpar@2239
    80
	LGraph::Node laNode = laNodes[a];
alpar@2239
    81
        LGraph::Node lbNode = lbNodes[b];
alpar@2239
    82
        lgraph.addEdge(laNode, lbNode);
deba@2084
    83
      }
deba@2084
    84
deba@2084
    85
      {
deba@2084
    86
        MaxBipartiteMatching<Graph> bpmatch(graph);
deba@2084
    87
        
deba@2084
    88
        nt.start();
deba@2084
    89
        bpmatch.init();
deba@2084
    90
        bpmatch.start();
deba@2084
    91
        nt.stop();
deba@2084
    92
        
deba@2084
    93
      }
deba@2084
    94
deba@2084
    95
      {
deba@2084
    96
        typedef SwapBpUGraphAdaptor<Graph> SGraph;
deba@2084
    97
        SGraph sgraph(graph);
deba@2084
    98
        MaxBipartiteMatching<SGraph> bpmatch(sgraph);
deba@2084
    99
deba@2084
   100
        st.start();
deba@2084
   101
        bpmatch.init();
deba@2084
   102
        bpmatch.start();
deba@2084
   103
        st.stop();
deba@2084
   104
        
alpar@2239
   105
      }                 
alpar@2239
   106
      {
alpar@2239
   107
        MaxBipartiteMatching<LGraph> bpmatch(lgraph);
alpar@2239
   108
        
alpar@2239
   109
        lnt.start();
alpar@2239
   110
        bpmatch.init();
alpar@2239
   111
        bpmatch.start();
alpar@2239
   112
        lnt.stop();
alpar@2239
   113
        
deba@2084
   114
      }
deba@2084
   115
alpar@2239
   116
      {
alpar@2239
   117
        typedef SwapBpUGraphAdaptor<LGraph> SGraph;
alpar@2239
   118
        SGraph sgraph(lgraph);
alpar@2239
   119
        MaxBipartiteMatching<SGraph> bpmatch(sgraph);
alpar@2239
   120
alpar@2239
   121
        lst.start();
alpar@2239
   122
        bpmatch.init();
alpar@2239
   123
        bpmatch.start();
alpar@2239
   124
        lst.stop();
alpar@2239
   125
        
alpar@2239
   126
      }
alpar@2239
   127
     }
alpar@2239
   128
alpar@2239
   129
    cout << k * 100 << ' ' << nt.realTime() << ' ' << st.realTime()
alpar@2239
   130
	 << ' ' << lnt.realTime() << ' ' << lst.realTime()<< endl;
deba@2084
   131
deba@2084
   132
  }
deba@2084
   133
deba@2084
   134
  return 0;
deba@2084
   135
}