14#ifndef OR_TOOLS_SAT_2D_RECTANGLE_PRESOLVE_H_
15#define OR_TOOLS_SAT_2D_RECTANGLE_PRESOLVE_H_
21#include "absl/algorithm/container.h"
22#include "absl/container/flat_hash_map.h"
23#include "absl/container/inlined_vector.h"
24#include "absl/types/span.h"
38 absl::Span<const RectangleInRange> non_fixed_boxes,
39 std::vector<Rectangle>* fixed_boxes);
102 absl::Span<const RectangleInRange> non_fixed_boxes,
103 absl::Span<const Rectangle> fixed_boxes,
int max_num_components);
119 std::vector<Rectangle>* optional_rectangles);
126 std::vector<Rectangle>* mandatory_rectangles,
127 std::vector<Rectangle>* optional_rectangles);
131template <
typename Sink>
138 sink.Append(
"RIGHT");
141 sink.Append(
"BOTTOM");
175 return std::tie(a.
x_min, a.
x_max) > std::tie(
b.x_min,
b.x_max);
177 return std::tie(a.
x_min, a.
x_max) < std::tie(
b.x_min,
b.x_max);
179 return std::tie(a.
y_min, a.
y_max) < std::tie(
b.y_min,
b.y_max);
181 return std::tie(a.
y_min, a.
y_max) > std::tie(
b.y_min,
b.y_max);
188 absl::Span<const Rectangle> rectangles,
189 absl::Span<
const std::tuple<int, EdgePosition, int>> neighbors)
190 : size_(rectangles.size()) {
191 for (
const auto& [box_index, edge, neighbor] : neighbors) {
192 neighbors_[edge][box_index].push_back(neighbor);
194 for (
int edge = 0; edge < 4; ++edge) {
195 for (
auto& [box_index, neighbors] : neighbors_[edge]) {
196 absl::c_sort(neighbors, [&rectangles, edge](
int a,
int b) {
198 rectangles[a], rectangles[
b]);
209 if (
auto it = neighbors_[edge].find(rectangle_index);
210 it != neighbors_[edge].end()) {
218 absl::flat_hash_map<int, absl::InlinedVector<int, 3>> neighbors_[4];
225 const Neighbours& neighbours);
248std::vector<SingleShape>
BoxesToShapes(absl::Span<const Rectangle> rectangles,
CompareClockwise(EdgePosition edge)
bool operator()(const Rectangle &a, const Rectangle &b) const
int NumRectangles() const
absl::Span< const int > GetSortedNeighbors(int rectangle_index, EdgePosition edge) const
Neighbors are sorted in the clockwise order.
Neighbours(absl::Span< const Rectangle > rectangles, absl::Span< const std::tuple< int, EdgePosition, int > > neighbors)
bool ReduceNumberOfBoxesExactMandatory(std::vector< Rectangle > *mandatory_rectangles, std::vector< Rectangle > *optional_rectangles)
std::vector< std::vector< int > > SplitInConnectedComponents(const Neighbours &neighbours)
std::vector< SingleShape > BoxesToShapes(absl::Span< const Rectangle > rectangles, const Neighbours &neighbours)
Disjoint2dPackingResult DetectDisjointRegionIn2dPacking(absl::Span< const RectangleInRange > non_fixed_boxes, absl::Span< const Rectangle > fixed_boxes, int max_num_components)
bool ReduceNumberofBoxesGreedy(std::vector< Rectangle > *mandatory_rectangles, std::vector< Rectangle > *optional_rectangles)
std::vector< Rectangle > CutShapeIntoRectangles(SingleShape shape)
void AbslStringify(Sink &sink, EdgePosition e)
Neighbours BuildNeighboursGraph(absl::Span< const Rectangle > rectangles)
bool PresolveFixed2dRectangles(absl::Span< const RectangleInRange > non_fixed_boxes, std::vector< Rectangle > *fixed_boxes)
In SWIG mode, we don't want anything besides these top-level includes.
std::vector< Rectangle > bin_area
std::vector< Rectangle > fixed_boxes
Fixed boxes that the non-fixed boxes in this bin cannot overlap with.
std::vector< int > non_fixed_box_indexes
Non-fixed boxes on the original problem to copy to this new constraint.
std::vector< std::pair< IntegerValue, IntegerValue > > step_points
The two vectors should have exactly the same size.
std::vector< int > touching_box_index
std::vector< ShapePath > holes