Repository navigation
irregular: keep the holes of item types copied from another instance - #627
Merged
Merged
Conversation
'InstanceBuilder::build' removes the holes smaller than the smallest item
area. But it only computed that area over the shapes it scales itself,
skipping the shapes of item types copied from another instance
('add_item_type(const Instance&, ItemTypeId)'), which are already scaled.
When all item types were copied, as in the reduced instance, the
smallest item area stayed infinite and every hole was removed.
Since the reduction is enabled by default, items were never placed
inside the holes of other items, and the bounds of the reduced instance,
computed with the holes filled, could prove a worse solution optimal.
This was referenced Oct 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Items were never placed inside the holes of other items. In
test_knapsack_hole, a 30x30 bin holds a 30x30 square with a 10x10 hole (profit 10) and a 10x10 square (profit 1). The solver returned profit 10 and reported it proven optimal, although 11 is feasible.InstanceBuilder::buildremoves the holes smaller than the smallest item area. That area was only computed over the shapesbuildscales itself. It skipped the shapes of item types copied from another instance (add_item_type(const Instance&, ItemTypeId)), which are already scaled. When every item type is copied, as in the reduced instance, the smallest item area stayed infinite, so every hole was removed.The reduction is enabled by default. So by default, the holes didn't exist in the instance actually solved, and the bounds computed on that instance could prove a worse solution optimal.
Fix
Also take the already-scaled shapes into account in the smallest item area.
Testing
test_knapsack_holeis no longer an expected failure. It now runs with and without the reduction.test_knapsack_items_in_hole: four 10x10 squares in the 20x20 hole of a 30x30 square.master.