benchmark/min_cut_graphs.h
author deba
Wed, 07 Mar 2007 12:00:59 +0000
changeset 2400 b199ded24c19
parent 2341 46a6311ceffa
child 2553 bfced05fa852
permissions -rw-r--r--
Steiner 2-approximation demo
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@2341
    19
#include <lemon/random.h>
deba@2341
    20
deba@2341
    21
deba@2341
    22
template <typename UGraph, typename CapacityMap>
deba@2341
    23
void genNoiUGraph(UGraph& g, CapacityMap& c, 
deba@2341
    24
                  int n, int d, int k, int p) {
deba@2341
    25
  std::vector<typename UGraph::Node> nodes(n);
deba@2341
    26
  for (int i = 0; i < n; ++i) {
deba@2341
    27
    nodes[i] = g.addNode();
deba@2341
    28
  }
deba@2341
    29
  typename UGraph::template NodeMap<int> comp(g);
deba@2341
    30
  for (int i = 0; i < n; ++i) {
deba@2341
    31
    comp[nodes[i]] = rnd[k];
deba@2341
    32
  }
deba@2341
    33
  int m = (n * (n - 1) * d) / 200;
deba@2341
    34
  for (int i = 0; i < m; ++i) {
deba@2341
    35
    int s = rnd[n], t = rnd[n];
deba@2341
    36
    c[g.addEdge(nodes[s], nodes[t])] =
deba@2341
    37
      rnd[(comp[nodes[s]] == comp[nodes[t]] ? p : 1) * 100]; 
deba@2341
    38
  }
deba@2341
    39
}
deba@2341
    40
deba@2341
    41
template <typename UGraph, typename CapacityMap>
deba@2341
    42
void genBikeWheelUGraph(UGraph& g, CapacityMap& c, int n) {
deba@2341
    43
  std::vector<typename UGraph::Node> nodes(n);
deba@2341
    44
  for (int i = 0; i < n; ++i) {
deba@2341
    45
    nodes[i] = g.addNode();
deba@2341
    46
  }
deba@2341
    47
  for (int i = 0; i < n - 2; ++i) {
deba@2341
    48
    c[g.addEdge(nodes[i], nodes[n - 1 - (i % 2)])] = 2;
deba@2341
    49
  }
deba@2341
    50
  for (int i = 1; i < n - 2; ++i) {
deba@2341
    51
    c[g.addEdge(nodes[i - 1], nodes[i])] = n - 1;
deba@2341
    52
  }
deba@2341
    53
  c[g.addEdge(nodes[n - 3], nodes[0])] = n - 1;
deba@2341
    54
  c[g.addEdge(nodes[n - 2], nodes[n - 1])] = 2;
deba@2341
    55
}
deba@2341
    56
deba@2341
    57
template <typename UGraph, typename CapacityMap>
deba@2341
    58
void genRegUGraph(UGraph& g, CapacityMap& c, int n, int d) {
deba@2341
    59
  std::vector<typename UGraph::Node> nodes(n);
deba@2341
    60
  for (int i = 0; i < n; ++i) {
deba@2341
    61
    nodes[i] = g.addNode();
deba@2341
    62
  }
deba@2341
    63
  for (int k = 0; k < d; ++k) {
deba@2341
    64
    for (int i = 0; i < n; ++i) {
deba@2341
    65
      int r = rnd[n];
deba@2341
    66
      typename UGraph::Node t = nodes[r];
deba@2341
    67
      nodes[r] = nodes[i];
deba@2341
    68
      nodes[i] = t;
deba@2341
    69
    }
deba@2341
    70
    for (int i = 1; i < n; ++i) {
deba@2341
    71
      c[g.addEdge(nodes[i - 1], nodes[i])] = 1;
deba@2341
    72
    }
deba@2341
    73
    c[g.addEdge(nodes[n - 1], nodes[0])] = 1;
deba@2341
    74
  }
deba@2341
    75
}
deba@2341
    76
deba@2341
    77
template <typename UGraph, typename CapacityMap>
deba@2341
    78
void genCdgUGraph(UGraph& g, CapacityMap& c, int n, int d) {
deba@2341
    79
  std::vector<typename UGraph::Node> nodes(n);
deba@2341
    80
  for (int i = 0; i < n; ++i) {
deba@2341
    81
    nodes[i] = g.addNode();
deba@2341
    82
  }
deba@2341
    83
  std::vector<typename UGraph::Node> mix(n * d);
deba@2341
    84
  for (int i = 0; i < n; ++i) {
deba@2341
    85
    for (int j = 0; j < d; ++j) {
deba@2341
    86
      mix[i * d + j] = nodes[i];
deba@2341
    87
    }
deba@2341
    88
  }
deba@2341
    89
  while (mix.size() >= 2) {
deba@2341
    90
    int r;
deba@2341
    91
    r = rnd[mix.size()];
deba@2341
    92
    typename UGraph::Node s = mix[r];
deba@2341
    93
    mix[r] = mix.back(); mix.pop_back();
deba@2341
    94
    r = rnd[mix.size()];
deba@2341
    95
    typename UGraph::Node t = mix[r];
deba@2341
    96
    mix[r] = mix.back(); mix.pop_back();
deba@2341
    97
    c[g.addEdge(s, t)] = 1;
deba@2341
    98
  }
deba@2341
    99
}