Repository navigation
Description
irregular: tree_search_periodic_packing ignores fixed items (fixed item missing from the solution, items placed on top of it)
Problem type: irregular
Interface: Command-line executable (also reached through a Python wrapper that calls it)
PackingSolver version or commit: a5ddea6 (master, 2026-10-17)
Description
When a single-bin instance has fixed items and auto-selection picks tree_search_periodic_packing,
the returned solution ignores the fixed items: they are missing from the certificate, and other items
are placed where they stand. The solution is therefore invalid (items overlap the fixed item's area).
Expected: the fixed items appear in the solution at their bl_corner, and no other item overlaps them,
as happens when tree_search is used.
What I found in the source: the auto-selection in src/irregular/optimize.cpp (single-bin branch)
enables periodic packing when the types with more than periodic_packing_copies_threshold (16) copies
cover more than 80% of the bin area or of the total item area, without looking at fixed items, and
tree_search_periodic_packing.cpp / periodic_packing.cpp contain no handling of fixed items at all.
Steps to reproduce
instance.json (one 200 x 100 bin, one fixed pentagon at (70, 10), 30 copies of a small pentagon,
knapsack, no spacing):
{"objective":"knapsack","bin_types":[{"type":"polygon","vertices":[{"x":0.0,"y":0.0},{"x":200.0,"y":0.0},{"x":200.0,"y":100.0},{"x":0.0,"y":100.0}],"fixed_items":[{"item_type_id":0,"bl_corner":{"x":70,"y":10},"angle":0.0,"mirror":false}]}],"item_types":[{"type":"polygon","vertices":[{"x":0.0,"y":0.0},{"x":60.0,"y":0.0},{"x":60.0,"y":60.0},{"x":30.0,"y":75.0},{"x":0.0,"y":60.0}]},{"type":"polygon","vertices":[{"x":0.0,"y":0.0},{"x":30.0,"y":0.0},{"x":30.0,"y":25.0},{"x":15.0,"y":32.0},{"x":0.0,"y":25.0}],"copies":30,"allowed_rotations":[{"start":0.0,"end":0.0,"mirror":false},{"start":90.0,"end":90.0,"mirror":false},{"start":180.0,"end":180.0,"mirror":false},{"start":270.0,"end":270.0,"mirror":false}]}]}packingsolver_irregular --input instance.json --certificate solution.json --time-limit 5 --verbosity-level 2Result: the certificate holds 18 items, all of item type 1; item type 0 (the fixed item) is absent,
and the placed type-1 items cover 3706.8 mm2 of the fixed item's area (intersection of the
certificate's item shapes with the fixed pentagon translated to (70, 10)).
Controls, same build:
| Run | Fixed item in certificate | Area of other items on the fixed item |
|---|---|---|
| 30 copies, default (periodic packing selected) | no | 3706.8 |
30 copies, --use-tree-search 1 |
yes | 0 |
| 17 copies, default (periodic packing not selected) | yes | 0 |
The same happens with item_item_minimum_spacing set (we first saw it with spacing 3 on a real
instance: 30 of 35 fixed items kept, two other items overlapping fixed items by 1083 and 798 mm2).
Log output
Instance
--------
Objective: Knapsack
Number of item types: 2
Number of items: 31
Number of fixed items: 1
Number of bin types: 1
Number of bins: 1
Item-item minimum spacing: 0
Total item area: 29700
Largest item copies: 30
Total bin area: 20000
Bin type Item type Angle Mirror X Y
-------- --------- ----- ------ - -
0 0 0 0 70 10
Time Profit # items Comment
---- ------ ------- -------
0.002 15390 18 TSPP n 1
Solution
--------
Number of items: 18 / 31 (58.0645%)With --use-tree-search 1 the solutions come from TS g 5 d 7 q 1 and include the fixed item.
Possible fix
Either skip tree_search_periodic_packing in auto-selection when any bin type has fixed items, or
treat fixed items as obstacles (like defects) inside periodic packing. As a workaround we pass
--use-tree-search 1 for instances with fixed items.
- This report was drafted with the help of an AI agent
Activity
irregular: support fixed items in tree_search_periodic_packing
fontanf commentedon Oct 18, 2026
Thanks for the detailed report and the reproduction, it made the fix straightforward.
This is fixed by #721 (merged in 0b2b69e).
tree_search_periodic_packingnow handles fixed items like defects: each fixed item is cut out of the free space, approximated by the bounding box of its shape inflated by the item-item spacing. The fixed items count against the copies of their item types, and they are included in the solutions.On your instance, the certificate now contains the fixed item at (70, 10), and no other item overlaps it. I also checked the case with
item_item_minimum_spacingset to 3, and instances with two fixed items whose bounding boxes overlap. A regression test was added for the latter.You shouldn't need the
--use-tree-search 1workaround anymore once you update to the latest version. Note that fixed items are approximated by their bounding boxes in this algorithm, so with large or irregular fixed items, the regular tree search may still give better solutions.HamzaYslmn commentedon Oct 19, 2026
Thanks for the quick fix! Confirmed on 0b2b69e: the fixed items are now in the solution, and nothing overlaps them, with and without
item_item_minimum_spacing.As you noted, the bounding-box approximation matters for us, so we keep
--use-tree-search 1on instances with fixed items. Our main use of fixed items is filling the holes of large parts: the large part is fixed and the small parts go inside its hole. With the bounding box, the hole is covered, so periodic packing places nothing there.Minimal case: a 400 x 300 frame with a 320 x 220 hole, fixed at (0, 0) on a 400 x 300 bin, plus 200 copies of a 30 x 28 rectangle (knapsack, no spacing).
{"objective":"knapsack","bin_types":[{"type":"polygon","vertices":[{"x":0.0,"y":0.0},{"x":400.0,"y":0.0},{"x":400.0,"y":300.0},{"x":0.0,"y":300.0}],"fixed_items":[{"item_type_id":0,"bl_corner":{"x":0,"y":0},"angle":0.0,"mirror":false}]}],"item_types":[{"type":"polygon","vertices":[{"x":400.0,"y":0.0},{"x":400.0,"y":300.0},{"x":0.0,"y":300.0},{"x":0.0,"y":0.0}],"holes":[{"type":"polygon","vertices":[{"x":360.0,"y":40.0},{"x":360.0,"y":260.0},{"x":40.0,"y":260.0},{"x":40.0,"y":40.0}]}]},{"type":"polygon","vertices":[{"x":30.0,"y":0.0},{"x":30.0,"y":28.0},{"x":0.0,"y":28.0},{"x":0.0,"y":0.0}],"copies":200,"allowed_rotations":[{"start":0.0,"end":0.0,"mirror":false},{"start":90.0,"end":90.0,"mirror":false},{"start":180.0,"end":180.0,"mirror":false},{"start":270.0,"end":270.0,"mirror":false}]}]}TSPP n 2, 1 / 201 items (only the fixed item).--use-tree-search 1:TS g 5 d 7 q 1, 78 / 201 items (77 rectangles in the hole).A wider check through the Python wrapper, each case at spacing 0 and 3, gave the same picture:
The
--use-tree-search 1workaround is fine for us. One possible improvement: auto-selection could skip periodic packing when a fixed item's bounding box covers free space that its shape leaves open, for example a fixed item with holes.HamzaYslmn commentedon Oct 19, 2026
@fontanf
irregular: approximate the obstacles of periodic packing by rectangles
fontanf commentedon Oct 20, 2026
Thanks for the follow-up and the minimal case, it pointed exactly at the limitation.
This is improved by #726 (merged in be6c319). Periodic packing no longer approximates the obstacles (fixed items, defects and bin borders) by their bounding boxes, but by sets of rectangles computed with a new function of the shape library. A frame like yours is covered exactly by 4 rectangles, so its hole stays free. For slanted or curved obstacles, the number of rectangles is limited by the same waste budget as the shape simplification.
While checking your case with spacing, I also found and fixed a second issue: periodic packing lost one item spacing in front of each obstacle, so a grid of items that fitted exactly next to a fixed item (or a defect) was rejected.
On your frame instance (200 rectangles of 30 × 28), with the default selection, which now picks periodic packing:
--use-tree-search 1So for fixed items with holes, you shouldn't need
--use-tree-search 1anymore. With slanted fixed items, the tree search can still place a few more items next to the slanted edges, since periodic packing only places rectangular grids of items.