diff --git a/doc/internals/irregular/tree_search_maximal_spaces.rst b/doc/internals/irregular/tree_search_maximal_spaces.rst index efa9b6c7b..7081925e9 100644 --- a/doc/internals/irregular/tree_search_maximal_spaces.rst +++ b/doc/internals/irregular/tree_search_maximal_spaces.rst @@ -108,7 +108,7 @@ The insertions of a node are computed as follows. **2. Candidate blocks.** The candidate blocks are the valid blocks which may fit in the selected empty space. -**3. Candidate supporting parts.** The candidate supporting parts are the ones which touch the bottom side of the empty space: they overlap it horizontally, and their lowest point is at or below it while their highest point is at or above it. They are searched among the supporting parts of the bin and of the blocks already packed (only for the blocks whose bounding box crosses the bottom side of the empty space). The bottom side of an empty space is usually the top of a rectangle covering an item, which is also the top of the item, so the supporting part of the item at the top of this rectangle touches it. +**3. Candidate supporting parts.** The candidate supporting parts are the ones which touch the bottom side of the empty space: they overlap it horizontally, and their lowest point is at or below it while their highest point is at or above it. They are searched among the supporting parts of the bin and of the blocks already packed (only for the blocks for which the bounding box of their supporting parts crosses the bottom side of the empty space; the supporting parts are computed on the inflated shapes, so with an item-item spacing, this bounding box goes above the bounding box of the items). The bottom side of an empty space is usually the top of a rectangle covering an item, which is also the top of the item inflated by the item-item spacing, so the supporting part of the item at the top of this rectangle touches it. **4. Obstacles.** For each candidate supporting part, the trapezoids which a block resting on it may overlap are selected among the trapezoids of the node: the ones whose right is to the right of the left side of the empty space minus the width of the widest candidate block, and which overlap vertically the supporting part extended, above and below, by the height of the highest candidate block. The other trapezoids can't be reached by the slides below. diff --git a/src/irregular/tree_search_maximal_spaces.cpp b/src/irregular/tree_search_maximal_spaces.cpp index 9e8448450..08806d416 100644 --- a/src/irregular/tree_search_maximal_spaces.cpp +++ b/src/irregular/tree_search_maximal_spaces.cpp @@ -315,6 +315,7 @@ BranchingSchemeMaximalSpaces::Block BranchingSchemeMaximalSpaces::build_block( if (covered(item_pos, support.aabb, true)) continue; block_trapezoid_set.supporting_parts.push_back(block.supporting_parts.size()); + block.supporting_parts_aabb = shape::merge(block.supporting_parts_aabb, support.aabb); block.supporting_parts.push_back(support); } } @@ -545,11 +546,8 @@ void BranchingSchemeMaximalSpaces::select_empty_space( } for (const Node::PlacedBlock& placed_block: node.placed_blocks) { const Block& block = blocks_[placed_block.block_id]; - AxisAlignedBoundingBox block_aabb; - block_aabb.x_min = placed_block.x + block.trapezoid_set.x_min; - block_aabb.x_max = placed_block.x + block.trapezoid_set.x_max; - block_aabb.y_min = placed_block.y + block.trapezoid_set.y_min; - block_aabb.y_max = placed_block.y + block.trapezoid_set.y_max; + AxisAlignedBoundingBox block_aabb = block.supporting_parts_aabb; + block_aabb.shift(placed_block.x, placed_block.y); if (!touches_bottom(block_aabb)) continue; for (const Support& support: block.supporting_parts) { diff --git a/src/irregular/tree_search_maximal_spaces.hpp b/src/irregular/tree_search_maximal_spaces.hpp index 94c437130..6a07ec3e3 100644 --- a/src/irregular/tree_search_maximal_spaces.hpp +++ b/src/irregular/tree_search_maximal_spaces.hpp @@ -95,6 +95,12 @@ class BranchingSchemeMaximalSpaces */ std::vector supporting_parts; + /** + * Bounding box of the supporting parts, which are computed on the + * inflated shapes of the items, relative to the block. + */ + AxisAlignedBoundingBox supporting_parts_aabb; + /** * Supported parts with which the block rests on a supporting part, * relative to the block. diff --git a/test/irregular/tree_search_maximal_spaces_test.cpp b/test/irregular/tree_search_maximal_spaces_test.cpp index e97811f1c..d5e6b1ebc 100644 --- a/test/irregular/tree_search_maximal_spaces_test.cpp +++ b/test/irregular/tree_search_maximal_spaces_test.cpp @@ -143,4 +143,11 @@ INSTANTIATE_TEST_SUITE_P( // worse than packing item types 0 and 2 (150). fs::path("data") / "irregular" / "tests" / "knapsack_penalized_resource.json", fs::path("data") / "irregular" / "tests" / "knapsack_penalized_resource_solution.json" + }, { + // With the item-item spacing, the empty spaces above the items + // start above the bounding boxes of their non-inflated shapes, + // at the top of their inflated shapes, where their supporting + // parts are: the second row of items rests on them. + fs::path("data") / "irregular" / "tests" / "knapsack_item_item_minimum_spacing.json", + fs::path("data") / "irregular" / "tests" / "knapsack_item_item_minimum_spacing_solution.json" }}));