src/benchmark/hcube.cc
changeset 769 eb61fbc64c16
parent 729 a9b1c49440f7
child 840 10002fa8847a
equal deleted inserted replaced
3:4eda1fd69e69 4:68af475de274
     8 
     8 
     9 #include"bench_tools.h"
     9 #include"bench_tools.h"
    10 
    10 
    11 using namespace std;
    11 using namespace std;
    12 using namespace hugo;
    12 using namespace hugo;
    13 
       
    14 template<class Graph>
       
    15 void addHiperCube(Graph &G,int dim,vector<typename Graph::Node> &nodes)
       
    16 {
       
    17   GRAPH_TYPEDEF_FACTORY(Graph);
       
    18   
       
    19   vector<int> bits(dim+1);
       
    20   bits[0]=1;
       
    21   for(int i=1;i<=dim;i++) bits[i]=2*bits[i-1];
       
    22   
       
    23   for(int i=0;i<bits[dim];i++) {
       
    24     nodes.push_back(G.addNode());
       
    25     for(int j=0;j<dim;j++) if(i&bits[j]) G.addEdge(nodes[i-bits[j]],nodes[i]);
       
    26   }
       
    27 }
       
    28 
       
    29 template<class Graph>
       
    30 void addBiDirHiperCube(Graph &G,int dim,vector<typename Graph::Node> &nodes)
       
    31 {
       
    32   GRAPH_TYPEDEF_FACTORY(Graph);
       
    33   
       
    34   vector<int> bits(dim+1);
       
    35   bits[0]=1;
       
    36   for(int i=1;i<=dim;i++) bits[i]=2*bits[i-1];
       
    37   
       
    38   for(int i=0;i<bits[dim];i++) {
       
    39     nodes.push_back(G.addNode());
       
    40     for(int j=0;j<dim;j++) if(i&bits[j]) {
       
    41       G.addEdge(nodes[i-bits[j]],nodes[i]);
       
    42       G.addEdge(nodes[i],nodes[i-bits[j]]);
       
    43     }
       
    44     
       
    45   }
       
    46 }
       
    47 
    13 
    48 inline int numOfOnes(int n,int dim)
    14 inline int numOfOnes(int n,int dim)
    49 {
    15 {
    50   int s=0;
    16   int s=0;
    51   for(int i=0;i<dim;i++) {
    17   for(int i=0;i<dim;i++) {