benchmark/min_cut.cc
author alpar
Tue, 23 Jan 2007 12:51:39 +0000
changeset 2350 eb371753e814
child 2391 14a343be7a5a
permissions -rw-r--r--
Several doc improvements.
deba@2341
     1
#include <lemon/list_graph.h>
deba@2341
     2
deba@2341
     3
#include <lemon/hao_orlin.h>
deba@2341
     4
#include <lemon/nagamochi_ibaraki.h>
deba@2341
     5
#include <lemon/time_measure.h>
deba@2341
     6
deba@2341
     7
using namespace lemon;
deba@2341
     8
deba@2341
     9
#include "min_cut_graphs.h"
deba@2341
    10
deba@2341
    11
deba@2341
    12
void testRegUGraph();
deba@2341
    13
void testNoiUGraph();
deba@2341
    14
void testBikeWheelUGraph();
deba@2341
    15
deba@2341
    16
int main() {
deba@2341
    17
  testRegUGraph();
deba@2341
    18
  testNoiUGraph();
deba@2341
    19
  testBikeWheelUGraph();
deba@2341
    20
  return 0;
deba@2341
    21
}
deba@2341
    22
deba@2341
    23
//#define int long long
deba@2341
    24
deba@2341
    25
deba@2341
    26
int cutValue(const ListUGraph& g, const ListUGraph::UEdgeMap<int>& c,
deba@2341
    27
           const ListUGraph::NodeMap<bool>& n) {
deba@2341
    28
  int v = 0;
deba@2341
    29
  for (ListUGraph::UEdgeIt e(g); e != INVALID; ++e) {
deba@2341
    30
    if (n[g.source(e)] != n[g.target(e)]) {
deba@2341
    31
      v += c[e];
deba@2341
    32
    }
deba@2341
    33
  }
deba@2341
    34
  return v;
deba@2341
    35
}
deba@2341
    36
deba@2341
    37
int cutSize(const ListUGraph& g, const ListUGraph::NodeMap<bool>& nm) {
deba@2341
    38
  int m = 0;
deba@2341
    39
  for (ListUGraph::NodeIt n(g); n != INVALID; ++n) {
deba@2341
    40
    if (nm[n]) {
deba@2341
    41
      ++m;
deba@2341
    42
    }
deba@2341
    43
  }
deba@2341
    44
  return m;
deba@2341
    45
}
deba@2341
    46
deba@2341
    47
int testNI(const ListUGraph& g, const ListUGraph::UEdgeMap<int>& c) {
deba@2341
    48
  TimeReport tr("Nagamochi-Ibaraki : ");
deba@2341
    49
  NagamochiIbaraki<ListUGraph, ListUGraph::UEdgeMap<int> > alg(g, c);
deba@2341
    50
  alg.run();
deba@2341
    51
  ListUGraph::NodeMap<bool> n(g);
deba@2341
    52
  alg.minCut(n);
deba@2341
    53
  std::cout << "Check : " << cutValue(g, c, n) << ' '
deba@2341
    54
            << cutSize(g, n) << std::endl;
deba@2341
    55
  return alg.minCut();
deba@2341
    56
}
deba@2341
    57
deba@2341
    58
int testHO(const ListUGraph& g, const ListUGraph::UEdgeMap<int>& c) {
deba@2341
    59
  TimeReport tr("Hao-Orlin : ");
deba@2341
    60
  HaoOrlin<ListUGraph, ListUGraph::UEdgeMap<int> > alg(g, c);
deba@2341
    61
  alg.init();
deba@2341
    62
  alg.calculateOut();
deba@2341
    63
  ListUGraph::NodeMap<bool> n(g);
deba@2341
    64
  alg.minCut(n);
deba@2341
    65
  std::cout << "Check : " << cutValue(g, c, n) << ' '
deba@2341
    66
            << cutSize(g, n) << std::endl;
deba@2341
    67
  return alg.minCut();
deba@2341
    68
}
deba@2341
    69
deba@2341
    70
void testBikeWheelUGraph(int n) {
deba@2341
    71
  ListUGraph g;
deba@2341
    72
  ListUGraph::UEdgeMap<int> c(g);
deba@2341
    73
  genBikeWheelUGraph(g, c, n);
deba@2341
    74
  std::cout << "Node number : " << n << std::endl;
deba@2341
    75
  std::cout << "Hao-Orlin : " << testHO(g, c) << std::endl;
deba@2341
    76
  std::cout << "Nagamochi-Ibaraki : " << testNI(g, c) << std::endl;
deba@2341
    77
}
deba@2341
    78
deba@2341
    79
void testBikeWheelUGraph() {
deba@2341
    80
  std::cout << "BikeWheelUGraph : " << std::endl;
deba@2341
    81
  for (int k = 10; k <= 13; ++k) {
deba@2341
    82
    int n = 1 << k;
deba@2341
    83
    testBikeWheelUGraph(n);
deba@2341
    84
  }
deba@2341
    85
}
deba@2341
    86
deba@2341
    87
void testNoiUGraph(int n, int d, int k, int p) {
deba@2341
    88
  ListUGraph g;
deba@2341
    89
  ListUGraph::UEdgeMap<int> c(g);
deba@2341
    90
  genNoiUGraph(g, c, n, d, k, p);
deba@2341
    91
  std::cout << "Node number : " << n << std::endl;
deba@2341
    92
  std::cout << "Density : " << d << std::endl;
deba@2341
    93
  std::cout << "Tight components : " << k << std::endl;
deba@2341
    94
  std::cout << "Scale : " << p << std::endl;
deba@2341
    95
  std::cout << "Hao-Orlin : " << testHO(g, c) << std::endl;
deba@2341
    96
  std::cout << "Nagamochi-Ibaraki : " << testNI(g, c) << std::endl;
deba@2341
    97
}
deba@2341
    98
deba@2341
    99
deba@2341
   100
void testNoiUGraph() {
deba@2341
   101
  std::cout << "NoiUGraph : " << std::endl; 
deba@2341
   102
  std::cout << "Serial 1 : " << std::endl;
deba@2341
   103
  for (int n = 300; n <= 1000; n += 100) {
deba@2341
   104
    testNoiUGraph(n, 50, 1, n);
deba@2341
   105
  }
deba@2341
   106
  std::cout << "Serial 2 : " << std::endl;
deba@2341
   107
  for (int n = 300; n <= 1000; n += 100) {
deba@2341
   108
    testNoiUGraph(n, 50, 2, n);
deba@2341
   109
  }
deba@2341
   110
  std::cout << "Serial 3 : " << std::endl;
deba@2341
   111
  int da3[] = { 5, 10, 25, 50, 75, 100 };
deba@2341
   112
  int dn3 = sizeof(da3) / sizeof(da3[0]);
deba@2341
   113
  for (int d = 0; d < dn3; ++d) {
deba@2341
   114
    testNoiUGraph(1000, da3[d], 1, 1000);
deba@2341
   115
  }
deba@2341
   116
  std::cout << "Serial 4 : " << std::endl;
deba@2341
   117
  for (int d = 0; d < dn3; ++d) {
deba@2341
   118
    testNoiUGraph(1000, da3[d], 2, 1000);
deba@2341
   119
  }
deba@2341
   120
  std::cout << "Serial 5 : " << std::endl;
deba@2341
   121
  int ka5[] = {1, 2, 3, 5, 7, 10, 20, 30, 33, 35, 
deba@2341
   122
               40, 50, 100, 200, 300, 400, 500};
deba@2341
   123
  int kn5 = sizeof(ka5) / sizeof(ka5[0]);
deba@2341
   124
  for (int k = 0; k < kn5; ++k) {
deba@2341
   125
    testNoiUGraph(1000, 50, ka5[k], 1000);
deba@2341
   126
  }
deba@2341
   127
  std::cout << "Serial 6 : " << std::endl;
deba@2341
   128
  int pa6[] = { 5000, 2000, 1000, 500, 250, 100, 50, 10, 1};
deba@2341
   129
  int pn6 = sizeof(pa6) / sizeof(pa6[0]);
deba@2341
   130
  for (int p = 0; p < pn6; ++p) {
deba@2341
   131
    testNoiUGraph(1000, 50, 2, pa6[p]);
deba@2341
   132
  }  
deba@2341
   133
  
deba@2341
   134
}
deba@2341
   135
deba@2341
   136
void testRegUGraph(int n, int d) {
deba@2341
   137
  ListUGraph g;
deba@2341
   138
  ListUGraph::UEdgeMap<int> c(g);
deba@2341
   139
  genRegUGraph(g, c, n, d);
deba@2341
   140
  std::cout << "Node number : " << n << std::endl;
deba@2341
   141
  std::cout << "Number of cycles : " << d << std::endl;
deba@2341
   142
  std::cout << "Hao-Orlin : " << testHO(g, c) << std::endl;
deba@2341
   143
  std::cout << "Nagamochi-Ibaraki : " << testNI(g, c) << std::endl;
deba@2341
   144
}
deba@2341
   145
deba@2341
   146
void testRegUGraph() {
deba@2341
   147
  std::cout << "RegUGraph : " << std::endl; 
deba@2341
   148
  std::cout << "Serial 1 : " << std::endl;
deba@2341
   149
  int da1[] = { 1, 3, 10, 33, 100, 333, 1000};
deba@2341
   150
  int dn1 = sizeof(da1) / sizeof(da1[0]);
deba@2341
   151
  for (int d = 0; d < dn1; ++d) {
deba@2341
   152
    testRegUGraph(1001, da1[d]);
deba@2341
   153
  }
deba@2341
   154
  std::cout << "Serial 2 : " << std::endl;
deba@2341
   155
  int na2[] = { 50, 100, 200, 400, 800};
deba@2341
   156
  int nn2 = sizeof(na2) / sizeof(na2[0]);
deba@2341
   157
  for (int n = 0; n < nn2; ++n) {
deba@2341
   158
    testRegUGraph(na2[n], 50);
deba@2341
   159
  }
deba@2341
   160
  std::cout << "Serial 3 : " << std::endl;
deba@2341
   161
  for (int n = 8; n <= 14; ++n) {
deba@2341
   162
    testRegUGraph(1 << n, 2);
deba@2341
   163
  }
deba@2341
   164
  std::cout << "Serial 4 : " << std::endl;
deba@2341
   165
  for (int n = 7; n <= 11; ++n) {
deba@2341
   166
    testRegUGraph(1 << n, 1 << (n - 4));
deba@2341
   167
  }  
deba@2341
   168
}
deba@2341
   169