Ophidian
 All Classes Namespaces Functions
density_map.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_DENSITY_H
22 #define ophidian_DENSITY_H
23 
24 #include <boost/geometry/index/rtree.hpp>
25 #include "bins.h"
26 #include "placement.h"
27 #include "floorplan.h"
28 
29 namespace ophidian {
30 
31 
32  namespace density {
33  class density_map {
34  using point = geometry::point<double>;
35  using box = geometry::box<point>;
36  using rtree_node = std::pair<box, entity_system::entity>;
37  using rtree = boost::geometry::index::rtree<rtree_node, boost::geometry::index::rstar<16>>;
38 
39  floorplan::floorplan * m_floorplan;
40  placement::placement * m_placement;
41 
42  entity_system::entity_system m_bins_system;
43 
44  bins m_bins;
45  rtree m_bins_rtree;
46  rtree m_rows_rtree;
47 
48  unsigned m_skipped_bins;
49  public:
50 
51  density_map(floorplan::floorplan * floorplan, placement::placement * placement)
52  : m_floorplan(floorplan), m_placement(placement), m_bins(m_bins_system), m_skipped_bins(0) {
53  for (auto row : m_floorplan->rows_system()) {
54  point row_origin = m_floorplan->row_origin(row);
55  point row_dimensions = m_floorplan->row_dimensions(row);
56  box row_box(row_origin, {row_origin.x() + row_dimensions.x(), row_origin.y() + row_dimensions.y()});
57  m_rows_rtree.insert(std::make_pair(row_box, row));
58  }
59  }
60 
61  ~density_map() { }
62 
63  entity_system::entity bin_insert(point position, point dimension, double movable_utilization = 0.0, double fixed_utilization = 0.0, double free_space = 0.0);
64 
65  std::size_t bin_count() {
66  return m_bins_system.size();
67  }
68 
69  point bin_position(entity_system::entity bin) {
70  return m_bins.position(bin);
71  }
72 
73  point bin_dimension(entity_system::entity bin) {
74  return m_bins.dimension(bin);
75  }
76 
77  double bin_movable_utilization(entity_system::entity bin) {
78  return m_bins.movable_utilization(bin);
79  }
80 
81  double bin_fixed_utilization(entity_system::entity bin) {
82  return m_bins.fixed_utilization(bin);
83  }
84 
85  double bin_free_space(entity_system::entity bin) {
86  return m_bins.free_space(bin);
87  }
88 
89  double bin_area(entity_system::entity bin) {
90  double area = m_bins.dimension(bin).x() * m_bins.dimension(bin).y();
91  return area;
92  }
93 
94  void bin_movable_utilization(entity_system::entity bin, double movable_utilization);
95  void bin_fixed_utilization(entity_system::entity bin, double fixed_utilization);
96  void bin_free_space(entity_system::entity bin, double free_space);
97 
98  const bins & bins_properties() const {
99  return m_bins;
100  }
101 
102  const entity_system::entity_system & bins_system() const {
103  return m_bins_system;
104  }
105 
106  void intersecting_bins(box region, std::vector<entity_system::entity> & bins);
107 
108  void build_density_map(point max_bin_dimensions, std::vector<double> &utilizations, double bin_area_threshold = 0.2, double free_space_threshold = 0.2);
109 
110  unsigned skipped_bins() { return m_skipped_bins; }
111  };
112  }
113 }
114 
115 
116 #endif //ophidian_DENSITY_H
point row_origin(entity_system::entity row) const
Row origin getter.
Definition: floorplan.h:192
Placement class.
Definition: placement.h:35
point row_dimensions(entity_system::entity row) const
Row dimensions getter.
Definition: floorplan.cpp:91
entity_system class.
Definition: entity_system.h:40
Definition: density_map.h:33
std::size_t size() const
Returns the size of the system.
Definition: entity_system.h:82
Floorplan class.
Definition: floorplan.h:37
Definition: bins.h:31