Graybat  1.1
Graph Approach for Highly Generic Communication Schemes Based on Adaptive Topologies
GridDiagonal.hpp
1 # pragma once
2 
3 // STL
4 #include <utility> /* std::make_pair */
5 
6 // GRAYBAT
7 #include <graybat/graphPolicy/Traits.hpp>
8 
9 
10 namespace graybat {
11 
12  namespace pattern {
13 
14  template<typename T_GraphPolicy>
15  struct GridDiagonal {
16 
17  using GraphPolicy = T_GraphPolicy;
18  using VertexDescription = graybat::graphPolicy::VertexDescription<GraphPolicy>;
19  using EdgeDescription = graybat::graphPolicy::EdgeDescription<GraphPolicy>;
20  using GraphDescription = graybat::graphPolicy::GraphDescription<GraphPolicy>;
21  using EdgeProperty = graybat::graphPolicy::EdgeProperty<GraphPolicy>;
22  using VertexProperty = graybat::graphPolicy::VertexProperty<GraphPolicy>;
23 
24  const unsigned height;
25  const unsigned width;
26 
27  GridDiagonal(const unsigned height, const unsigned width) :
28  height(height),
29  width(width){
30 
31  }
32 
33  GraphDescription operator()(){
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 
44  // UP
45  if(i >= width){
46  unsigned up = i - width;
47  edges.push_back(std::make_pair(std::make_pair(vertices[i].first, vertices[up].first), EdgeProperty()));
48  }
49 
50  // UP LEFT
51  if(i >= width and (i % width) != 0){
52  unsigned up_left = i - width - 1;
53  edges.push_back(std::make_pair(std::make_pair(vertices[i].first, vertices[up_left].first), EdgeProperty()));
54  }
55 
56  // UP RIGHT
57  if(i >= width and (i % width) != (width - 1)){
58  unsigned up_right = i - width + 1;
59  edges.push_back(std::make_pair(std::make_pair(vertices[i].first, vertices[up_right].first), EdgeProperty()));
60  }
61 
62  // DOWN
63  if(i < (verticesCount - width)){
64  unsigned down = i + width;
65  edges.push_back(std::make_pair(std::make_pair(vertices[i].first, vertices[down].first), EdgeProperty()));
66  }
67 
68  // DOWN LEFT
69  if(i < (verticesCount - width) and (i % width) != 0){
70  unsigned down_left = i + width - 1;
71  edges.push_back(std::make_pair(std::make_pair(vertices[i].first, vertices[down_left].first), EdgeProperty()));
72  }
73 
74  // DOWN RIGHT
75  if(i < (verticesCount - width) and (i % width) != (width - 1)){
76  unsigned down_right = i + width + 1;
77  edges.push_back(std::make_pair(std::make_pair(vertices[i].first, vertices[down_right].first), EdgeProperty()));
78  }
79 
80  // RIGHT
81  if((i % width) != (width - 1)){
82  int right = i + 1;
83  edges.push_back(std::make_pair(std::make_pair(vertices[i].first, vertices[right].first), EdgeProperty()));
84  }
85 
86  // LEFT
87  if((i % width) != 0){
88  int left = i - 1;
89  edges.push_back(std::make_pair(std::make_pair(vertices[i].first, vertices[left].first), EdgeProperty()));
90  }
91 
92  }
93  return std::make_pair(vertices,edges);
94  }
95 
96  };
97 
98  } /* pattern */
99 
100 } /* graybat */
Definition: GridDiagonal.hpp:15
Definition: BiStar.hpp:8