benchmark/hcube.cc
author marci
Sun, 13 Nov 2005 20:01:17 +0000
changeset 1787 932b8490caf0
parent 1689 f1795dafe42c
child 1847 7cbc12e42482
permissions -rw-r--r--
bugfix in setCol, getting dual values
alpar@708
     1
// -*- mode:C++ -*-
alpar@708
     2
alpar@1632
     3
#include<cmath>
alpar@921
     4
#include<lemon/list_graph.h>
alpar@921
     5
#include<lemon/smart_graph.h>
alpar@921
     6
#include<lemon/dijkstra.h>
alpar@921
     7
#include<lemon/preflow.h>
alpar@729
     8
alpar@711
     9
#include"bench_tools.h"
alpar@708
    10
alpar@708
    11
using namespace std;
alpar@921
    12
using namespace lemon;
alpar@708
    13
alpar@718
    14
inline int numOfOnes(int n,int dim)
alpar@718
    15
{
alpar@718
    16
  int s=0;
alpar@718
    17
  for(int i=0;i<dim;i++) {
alpar@718
    18
    s+=n%2;
alpar@718
    19
    n>>=1;
alpar@718
    20
  }
alpar@718
    21
  return s;
alpar@718
    22
}
alpar@718
    23
alpar@718
    24
inline int numOfZeros(int n,int dim)
alpar@718
    25
{
alpar@718
    26
  int s=dim;
alpar@718
    27
  for(int i=0;i<dim;i++) {
alpar@718
    28
    s-=n&1;
alpar@718
    29
    n>>=1;
alpar@718
    30
  }
alpar@718
    31
  return s;
alpar@718
    32
}
alpar@718
    33
alpar@708
    34
int main(int argc, char *argv[])
alpar@708
    35
{
alpar@708
    36
  //  typedef ListGraph Graph;
alpar@708
    37
  typedef SmartGraph Graph;
alpar@708
    38
alpar@1756
    39
  GRAPH_TYPEDEFS(Graph);
alpar@708
    40
alpar@708
    41
  Graph G;
alpar@708
    42
  
alpar@708
    43
  Timer T;
alpar@708
    44
  
alpar@708
    45
  if(argc!=2) {
alpar@708
    46
    cout << "Usage: " << argv[0] << " dim\n";
alpar@708
    47
    return 1;
alpar@708
    48
  }
alpar@708
    49
  
alpar@708
    50
  int dim=atoi(argv[1]);
alpar@708
    51
  
alpar@718
    52
//   cout << "Creating Hipercube ("<< (1<<dim) << " nodes, "
alpar@718
    53
//        << dim*(1<<dim) << " edges):";
alpar@708
    54
alpar@718
    55
  T.reset();
alpar@708
    56
  vector<Node> nodes;
alpar@1689
    57
  addBiDirHyperCube(G,dim,nodes);
alpar@718
    58
alpar@718
    59
  PrintTime("GENGRAPH",T);
alpar@718
    60
alpar@708
    61
  T.reset();
alpar@708
    62
  Graph::EdgeMap<int> map(G);
alpar@729
    63
  for(int i=0;i<5;i++) {
alpar@708
    64
    Primes P;
alpar@708
    65
    for(int i=0;i<dim*(1<<dim);i++) P();
alpar@708
    66
    
alpar@708
    67
    //  for(EdgeIt e(G);G.valid(e);G.next(e)) map[e]=P();
klao@946
    68
klao@946
    69
    ///\todo It must have been commented out because of
klao@946
    70
    ///setToId
klao@946
    71
//     Edge te;
klao@946
    72
//     for(int i=0;i<dim*(1<<dim);i++) {
klao@946
    73
//       te.setToId(((long long int)(i)*93505)%(dim*(1<<dim)));
klao@946
    74
//       //    map[Edge(((long long int)(i)*2987)%(dim*(1<<dim)))]=P();
klao@946
    75
//       map[te]=P();
klao@946
    76
//     }
alpar@905
    77
    
alpar@718
    78
//     for(int i=0;i<(1<<dim);i++) {
alpar@718
    79
//       int mul= (1<<(numOfZeros(i,dim)/4));
alpar@718
    80
//       for(OutEdgeIt e(G,nodes[i]);G.valid(e);G.next(e))
alpar@718
    81
// 	map[e]*=mul;
alpar@718
    82
//     }
alpar@708
    83
  }
alpar@708
    84
  
alpar@718
    85
  PrintTime("GENLENGTHS",T);
alpar@718
    86
alpar@708
    87
  T.reset();
alpar@708
    88
  {
alpar@708
    89
    Dijkstra<Graph> Dij(G,map);
alpar@729
    90
    for(int i=0;i<10;i++)
alpar@729
    91
      Dij.run(nodes[0]);
alpar@708
    92
  }
alpar@718
    93
  PrintTime("DIJKSTRA",T);
alpar@718
    94
alpar@718
    95
  T.reset();
alpar@718
    96
  {
alpar@718
    97
   Graph::EdgeMap<int> flow(G);
alpar@708
    98
   
alpar@840
    99
    Preflow<Graph,int> MF(G,nodes[0],nodes[1<<dim-1],map,flow);
alpar@729
   100
    for(int i=0;i<10;i++)
alpar@729
   101
      MF.run(MF.NO_FLOW);
alpar@718
   102
  }
alpar@718
   103
  PrintTime("PREFLOW",T);
alpar@718
   104
alpar@708
   105
}