Ophidian
 All Classes Namespaces Functions
grid_3d.h
1 /*
2  * Copyright 2016 Ophidian
3 Licensed to the Apache Software Foundation (ASF) under one
4 or more contributor license agreements. See the NOTICE file
5 distributed with this work for additional information
6 regarding copyright ownership. The ASF licenses this file
7 to you under the Apache License, Version 2.0 (the
8 "License"); you may not use this file except in compliance
9 with the License. You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0
12 
13 Unless required by applicable law or agreed to in writing,
14 software distributed under the License is distributed on an
15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 KIND, either express or implied. See the License for the
17 specific language governing permissions and limitations
18 under the License.
19  */
20 
21 #ifndef OPHIDIAN_SRC_ROUTING_GRID_3D_H
22 #define OPHIDIAN_SRC_ROUTING_GRID_3D_H
23 
24 #include <lemon/grid_graph.h>
25 
26 #include <memory>
27 #include <assert.h>
28 
29 namespace ophidian{
31 namespace routing{
32 
34 
37 class grid_2d
38 {
39  friend class grid_3d;
40 
41  lemon::GridGraph m_graph;
42  lemon::GridGraph::EdgeMap<unsigned> m_edges_capacities;
43  lemon::GridGraph::EdgeMap<unsigned> m_edges_demands;
44 public:
46 
51  grid_2d(int width, int height);
52  virtual ~grid_2d();
53 };
54 
56 
62 class grid_3d
63 {
64  int m_width;
65  int m_height;
66  int m_depth;
67  std::vector<std::unique_ptr<grid_2d> > m_vector_of_grid_2D;
68 public:
70 
76  grid_3d(int width, int height, int depth);
77  ~grid_3d();
78 
80 
84  inline int width(){return m_width;}
85 
87 
91  inline int height(){return m_height;}
92 
94 
98  inline int depth(){return m_depth;}
99 
101 
104  void reset_edge_demands();
105 
107 
114  inline unsigned get_horizontal_edge_capacity(int x, int y, int z)
115  {
116  assert(x < m_width-1); //there is no boundary edge
117  assert(y < m_height);
118  assert(z < m_depth);
119 
120  auto & grid_2d = *m_vector_of_grid_2D.at(z);
121  auto arc = grid_2d.m_graph.right(grid_2d.m_graph(x, y));
122  return grid_2d.m_edges_capacities[arc];
123  }
124 
126 
133  inline unsigned get_vertical_edge_capacity(int x, int y, int z)
134  {
135  assert(x < m_width); //there is no boundary edge
136  assert(y < m_height-1);
137  assert(z < m_depth);
138 
139  auto & grid_2d = *m_vector_of_grid_2D.at(z);
140  auto arc = grid_2d.m_graph.up(grid_2d.m_graph(x, y));
141  return grid_2d.m_edges_capacities[arc];
142  }
143 
145 
152  inline void set_horizontal_edge_capacity(int x, int y, int z, unsigned capacity)
153  {
154  assert(x < m_width-1); //there is no boundary edge
155  assert(y < m_height);
156  assert(z < m_depth);
157 
158  auto & grid_2d = *m_vector_of_grid_2D.at(z);
159  auto arc = grid_2d.m_graph.right(grid_2d.m_graph(x, y));
160  grid_2d.m_edges_capacities[arc] = capacity;
161  }
162 
164 
171  inline void set_vertical_edge_capacity(int x, int y, int z, unsigned capacity)
172  {
173  assert(x < m_width); //there is no boundary edge
174  assert(y < m_height-1);
175  assert(z < m_depth);
176 
177  auto & grid_2d = *m_vector_of_grid_2D.at(z);
178  auto arc = grid_2d.m_graph.up(grid_2d.m_graph(x, y));
179  grid_2d.m_edges_capacities[arc] = capacity;
180  }
181 
183 
190  inline unsigned get_horizontal_edge_demand(int x, int y, int z)
191  {
192  assert(x < m_width-1); //there is no boundary edge
193  assert(y < m_height);
194  assert(z < m_depth);
195 
196  auto & grid_2d = *m_vector_of_grid_2D.at(z);
197  auto arc = grid_2d.m_graph.right(grid_2d.m_graph(x, y));
198  return grid_2d.m_edges_demands[arc];
199  }
200 
202 
209  unsigned get_vertical_edge_demand(int x, int y, int z)
210  {
211  assert(x < m_width); //there is no boundary edge
212  assert(y < m_height-1);
213  assert(z < m_depth);
214 
215  auto & grid_2d = *m_vector_of_grid_2D.at(z);
216  auto arc = grid_2d.m_graph.up(grid_2d.m_graph(x, y));
217  return grid_2d.m_edges_demands[arc];
218  }
219 
221 
228  inline void set_horizontal_edge_demand(int x, int y, int z, unsigned demand)
229  {
230  assert(x < m_width-1); //there is no boundary edge
231  assert(y < m_height);
232  assert(z < m_depth);
233 
234  auto & grid_2d = *m_vector_of_grid_2D.at(z);
235  auto arc = grid_2d.m_graph.right(grid_2d.m_graph(x, y));
236  grid_2d.m_edges_demands[arc] = demand;
237  }
238 
240 
247  inline void set_vertical_edge_demand(int x, int y, int z, unsigned demand)
248  {
249  assert(x < m_width); //there is no boundary edge
250  assert(y < m_height-1);
251  assert(z < m_depth);
252 
253  auto & grid_2d = *m_vector_of_grid_2D.at(z);
254  auto arc = grid_2d.m_graph.up(grid_2d.m_graph(x, y));
255  grid_2d.m_edges_demands[arc] = demand;
256  }
257 
259 
265  inline void increment_horizontal_edge_demand(int x, int y, int z)
266  {
267  assert(x < m_width-1); //there is no boundary edge
268  assert(y < m_height);
269  assert(z < m_depth);
270 
271  auto & grid_2d = *m_vector_of_grid_2D.at(z);
272  auto arc = grid_2d.m_graph.right(grid_2d.m_graph(x, y));
273  grid_2d.m_edges_demands[arc] += 1;
274  }
275 
277 
283  inline void increment_vertical_edge_demand(int x, int y, int z)
284  {
285  assert(x < m_width); //there is no boundary edge
286  assert(y < m_height-1);
287  assert(z < m_depth);
288 
289  auto & grid_2d = *m_vector_of_grid_2D.at(z);
290  auto arc = grid_2d.m_graph.up(grid_2d.m_graph(x, y));
291  grid_2d.m_edges_demands[arc] += 1;
292  }
293 
295 
302  inline int get_horizontal_edge_utilization_gap(int x, int y, int z)
303  {
304  assert(x < m_width-1); //there is no boundary edge
305  assert(y < m_height);
306  assert(z < m_depth);
307 
308  auto & grid_2d = *m_vector_of_grid_2D.at(z);
309  auto arc = grid_2d.m_graph.right(grid_2d.m_graph(x, y));
310  auto capacity = grid_2d.m_edges_capacities[arc];
311  auto demand = grid_2d.m_edges_demands[arc];
312  return capacity - demand;
313  }
314 
316 
323  inline int get_vertical_edge_utilization_gap(int x, int y, int z)
324  {
325  assert(x < m_width); //there is no boundary edge
326  assert(y < m_height-1);
327  assert(z < m_depth);
328 
329  auto & grid_2d = *m_vector_of_grid_2D.at(z);
330  auto arc = grid_2d.m_graph.up(grid_2d.m_graph(x, y));
331  auto capacity = grid_2d.m_edges_capacities[arc];
332  auto demand = grid_2d.m_edges_demands[arc];
333  return capacity - demand;
334  }
335 
337 
342  void get_max_and_total_edges_overflow(int & max_overflow, int & total_overflow);
343 };
344 
346 protected:
347  grid_3d & m_grid_3d;
348 public:
350  virtual ~edge_overflow_calculator();
351  void get_max_and_total_edges_overflow(int & max_overflow, int & total_overflow);
352 };
353 
354 } /* namespace routing */
355 } /* namespace ophidian */
356 
357 #endif // OPHIDIAN_SRC_ROUTING_GRID_3D_H
int depth()
Get grid depth.
Definition: grid_3d.h:98
Grid_3d class.
Definition: grid_3d.h:62
void set_horizontal_edge_capacity(int x, int y, int z, unsigned capacity)
Set the capacity of a given horizontal edge.
Definition: grid_3d.h:152
unsigned get_horizontal_edge_demand(int x, int y, int z)
Get the demand of a given horizontal edge.
Definition: grid_3d.h:190
void increment_horizontal_edge_demand(int x, int y, int z)
Increment the demand of a given horizontal edge.
Definition: grid_3d.h:265
grid_2d(int width, int height)
Constructor.
Definition: grid_3d.cpp:30
unsigned get_vertical_edge_demand(int x, int y, int z)
Get the demand of a given vertical edge.
Definition: grid_3d.h:209
unsigned get_vertical_edge_capacity(int x, int y, int z)
Get capacity of a given vertical edge.
Definition: grid_3d.h:133
int height()
Get grid height.
Definition: grid_3d.h:91
void set_vertical_edge_demand(int x, int y, int z, unsigned demand)
Set the demand of a given vertical edge.
Definition: grid_3d.h:247
int get_vertical_edge_utilization_gap(int x, int y, int z)
Get the utilization gap of a given vertical edge.
Definition: grid_3d.h:323
void set_vertical_edge_capacity(int x, int y, int z, unsigned capacity)
Set the capacity of a given vertical edge.
Definition: grid_3d.h:171
void set_horizontal_edge_demand(int x, int y, int z, unsigned demand)
Set the demand of a given horizontal edge.
Definition: grid_3d.h:228
unsigned get_horizontal_edge_capacity(int x, int y, int z)
Get capacity of a given horizontal edge.
Definition: grid_3d.h:114
void get_max_and_total_edges_overflow(int &max_overflow, int &total_overflow)
Get the maximum and total edge overflow in the 3d grid.
void increment_vertical_edge_demand(int x, int y, int z)
Increment the demand of a given vertical edge.
Definition: grid_3d.h:283
int get_horizontal_edge_utilization_gap(int x, int y, int z)
Get the utilization gap of a given horizontal edge.
Definition: grid_3d.h:302
Grid_2d class.
Definition: grid_3d.h:37
int width()
Get grid width.
Definition: grid_3d.h:84
void reset_edge_demands()
Reset all edge demands to zero.
Definition: grid_3d.cpp:51
grid_3d(int width, int height, int depth)
Constructor.
Definition: grid_3d.cpp:40