benchmark/min_cut_graphs.h
author deba
Mon, 12 Feb 2007 10:27:03 +0000
changeset 2359 97a5cd10ca16
child 2391 14a343be7a5a
permissions -rw-r--r--
Some spellcheck
deba@2341
     1
// -*- C++ -*-
deba@2341
     2
#include <lemon/random.h>
deba@2341
     3
deba@2341
     4
deba@2341
     5
template <typename UGraph, typename CapacityMap>
deba@2341
     6
void genNoiUGraph(UGraph& g, CapacityMap& c, 
deba@2341
     7
                  int n, int d, int k, int p) {
deba@2341
     8
  std::vector<typename UGraph::Node> nodes(n);
deba@2341
     9
  for (int i = 0; i < n; ++i) {
deba@2341
    10
    nodes[i] = g.addNode();
deba@2341
    11
  }
deba@2341
    12
  typename UGraph::template NodeMap<int> comp(g);
deba@2341
    13
  for (int i = 0; i < n; ++i) {
deba@2341
    14
    comp[nodes[i]] = rnd[k];
deba@2341
    15
  }
deba@2341
    16
  int m = (n * (n - 1) * d) / 200;
deba@2341
    17
  for (int i = 0; i < m; ++i) {
deba@2341
    18
    int s = rnd[n], t = rnd[n];
deba@2341
    19
    c[g.addEdge(nodes[s], nodes[t])] =
deba@2341
    20
      rnd[(comp[nodes[s]] == comp[nodes[t]] ? p : 1) * 100]; 
deba@2341
    21
  }
deba@2341
    22
}
deba@2341
    23
deba@2341
    24
template <typename UGraph, typename CapacityMap>
deba@2341
    25
void genBikeWheelUGraph(UGraph& g, CapacityMap& c, int n) {
deba@2341
    26
  std::vector<typename UGraph::Node> nodes(n);
deba@2341
    27
  for (int i = 0; i < n; ++i) {
deba@2341
    28
    nodes[i] = g.addNode();
deba@2341
    29
  }
deba@2341
    30
  for (int i = 0; i < n - 2; ++i) {
deba@2341
    31
    c[g.addEdge(nodes[i], nodes[n - 1 - (i % 2)])] = 2;
deba@2341
    32
  }
deba@2341
    33
  for (int i = 1; i < n - 2; ++i) {
deba@2341
    34
    c[g.addEdge(nodes[i - 1], nodes[i])] = n - 1;
deba@2341
    35
  }
deba@2341
    36
  c[g.addEdge(nodes[n - 3], nodes[0])] = n - 1;
deba@2341
    37
  c[g.addEdge(nodes[n - 2], nodes[n - 1])] = 2;
deba@2341
    38
}
deba@2341
    39
deba@2341
    40
template <typename UGraph, typename CapacityMap>
deba@2341
    41
void genRegUGraph(UGraph& g, CapacityMap& c, int n, int d) {
deba@2341
    42
  std::vector<typename UGraph::Node> nodes(n);
deba@2341
    43
  for (int i = 0; i < n; ++i) {
deba@2341
    44
    nodes[i] = g.addNode();
deba@2341
    45
  }
deba@2341
    46
  for (int k = 0; k < d; ++k) {
deba@2341
    47
    for (int i = 0; i < n; ++i) {
deba@2341
    48
      int r = rnd[n];
deba@2341
    49
      typename UGraph::Node t = nodes[r];
deba@2341
    50
      nodes[r] = nodes[i];
deba@2341
    51
      nodes[i] = t;
deba@2341
    52
    }
deba@2341
    53
    for (int i = 1; i < n; ++i) {
deba@2341
    54
      c[g.addEdge(nodes[i - 1], nodes[i])] = 1;
deba@2341
    55
    }
deba@2341
    56
    c[g.addEdge(nodes[n - 1], nodes[0])] = 1;
deba@2341
    57
  }
deba@2341
    58
}
deba@2341
    59
deba@2341
    60
template <typename UGraph, typename CapacityMap>
deba@2341
    61
void genCdgUGraph(UGraph& g, CapacityMap& c, int n, int d) {
deba@2341
    62
  std::vector<typename UGraph::Node> nodes(n);
deba@2341
    63
  for (int i = 0; i < n; ++i) {
deba@2341
    64
    nodes[i] = g.addNode();
deba@2341
    65
  }
deba@2341
    66
  std::vector<typename UGraph::Node> mix(n * d);
deba@2341
    67
  for (int i = 0; i < n; ++i) {
deba@2341
    68
    for (int j = 0; j < d; ++j) {
deba@2341
    69
      mix[i * d + j] = nodes[i];
deba@2341
    70
    }
deba@2341
    71
  }
deba@2341
    72
  while (mix.size() >= 2) {
deba@2341
    73
    int r;
deba@2341
    74
    r = rnd[mix.size()];
deba@2341
    75
    typename UGraph::Node s = mix[r];
deba@2341
    76
    mix[r] = mix.back(); mix.pop_back();
deba@2341
    77
    r = rnd[mix.size()];
deba@2341
    78
    typename UGraph::Node t = mix[r];
deba@2341
    79
    mix[r] = mix.back(); mix.pop_back();
deba@2341
    80
    c[g.addEdge(s, t)] = 1;
deba@2341
    81
  }
deba@2341
    82
}