Skip to content

irregular: keep the holes of item types copied from another instance - #627

Merged
fontanf merged 1 commit into
masterfrom
irregular-keep-holes-of-copied-item-types
Oct 2, 2026
Merged

fontanf merged 1 commit into
masterfrom
irregular-keep-holes-of-copied-item-types

Conversation

@fontanf

@fontanf fontanf commented Oct 2, 2026

Copy link
Copy Markdown
Owner

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::build removes the holes smaller than the smallest item area. That area was only computed over the shapes build scales 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_hole is no longer an expected failure. It now runs with and without the reduction.
  • New test_knapsack_items_in_hole: four 10x10 squares in the 20x20 hole of a 30x30 square.
  • C++ irregular unit tests: 123 passed. Python tests: 352 passed, 13 skipped, no expected failures left.
  • Holes are now kept in every sub-instance built from an existing instance, so the benchmark outputs of the irregular instances with holes may differ from master.

'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.
@fontanf
fontanf merged commit e2e6b42 into master Oct 2, 2026
11 checks passed
@fontanf
fontanf deleted the irregular-keep-holes-of-copied-item-types branch October 2, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant