Graybat  1.1
Graph Approach for Highly Generic Communication Schemes Based on Adaptive Topologies
Grid.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 Grid {
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 height;
24  const unsigned width;
25 
26  Grid(const unsigned height, const unsigned width) :
27  height(height),
28  width(width){
29 
30  }
31 
32  GraphDescription operator()(){
33 
34  const unsigned verticesCount = height * width;
35  std::vector<VertexDescription> vertices(verticesCount);
36  std::vector<EdgeDescription> edges;
37 
38  for(unsigned i = 0; i < vertices.size(); ++i){
39  vertices.at(i) = std::make_pair(i, VertexProperty());
40  }
41 
42  for(unsigned i = 0; i < vertices.size(); ++i){
43  if(i >= width){
44  unsigned up = i - width;
45  edges.push_back(std::make_pair(std::make_pair(vertices[i].first, vertices[up].first), EdgeProperty()));
46  }
47 
48  if(i < (verticesCount - width)){
49  unsigned down = i + width;
50  edges.push_back(std::make_pair(std::make_pair(vertices[i].first, vertices[down].first), EdgeProperty()));
51  }
52 
53 
54  if((i % width) != (width - 1)){
55  int right = i + 1;
56  edges.push_back(std::make_pair(std::make_pair(vertices[i].first, vertices[right].first), EdgeProperty()));
57  }
58 
59  if((i % width) != 0){
60  int left = i - 1;
61  edges.push_back(std::make_pair(std::make_pair(vertices[i].first, vertices[left].first), EdgeProperty()));
62  }
63 
64 
65  }
66 
67  return std::make_pair(vertices,edges);
68  }
69 
70  };
71 
72  } /* pattern */
73 
74 } /* graybat */
Definition: BiStar.hpp:8
Definition: Grid.hpp:14