Graybat  1.1
Graph Approach for Highly Generic Communication Schemes Based on Adaptive Topologies
HyperCube.hpp
1 # pragma once
2 
3 // STL
4 #include <utility> /* std::make_pair */
5 
6 // GRAYBAT
7 #include <graybat/graphPolicy/Traits.hpp>
8 
9 namespace graybat {
10 
11  namespace pattern {
12 
13  template<typename T_GraphPolicy>
14  struct HyperCube {
15 
16  using GraphPolicy = T_GraphPolicy;
17  using VertexDescription = graybat::graphPolicy::VertexDescription<GraphPolicy>;
18  using EdgeDescription = graybat::graphPolicy::EdgeDescription<GraphPolicy>;
19  using GraphDescription = graybat::graphPolicy::GraphDescription<GraphPolicy>;
20  using EdgeProperty = graybat::graphPolicy::EdgeProperty<GraphPolicy>;
21  using VertexProperty = graybat::graphPolicy::VertexProperty<GraphPolicy>;
22 
23  const unsigned dimension;
24 
25  HyperCube(const unsigned dimension) :
26  dimension(dimension){
27 
28  }
29 
30  unsigned hammingDistance(unsigned a, unsigned b){
31  unsigned abXor = a xor b;
32  return (unsigned) __builtin_popcount(abXor);
33  }
34 
35  GraphDescription operator()(){
36  assert(dimension >= 1);
37  std::vector<EdgeDescription> edges;
38 
39  unsigned verticesCount = pow(2, dimension);
40  std::vector<VertexDescription> vertices(verticesCount);
41 
42  for(unsigned i = 0; i < vertices.size(); ++i){
43  vertices.at(i) = std::make_pair(i, VertexProperty());
44  }
45 
46  for(unsigned i = 0; i < vertices.size(); ++i){
47  for(unsigned j = 0; j < vertices.size(); ++j){
48  if(hammingDistance(i, j) == 1){
49  edges.push_back(std::make_pair(std::make_pair(vertices[i].first, vertices[j].first), EdgeProperty()));
50  }
51 
52  }
53  }
54 
55  return std::make_pair(vertices,edges);
56  }
57 
58  };
59 
60  } /* pattern */
61 
62 } /* graybat */
Definition: HyperCube.hpp:14
Definition: BiStar.hpp:8