Skip to content

irregular: approximate the obstacles of periodic packing by rectangles - #726

Merged
fontanf merged 1 commit into
masterfrom
irregular-periodic-packing-rectangle-obstacles
Oct 20, 2026
Merged

fontanf merged 1 commit into
masterfrom
irregular-periodic-packing-rectangle-obstacles

Conversation

@fontanf

@fontanf fontanf commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Follow-up of #721 for the last comment of #720: tree_search_periodic_packing approximated the defects, borders and fixed items by their bounding boxes, so a fixed part with a hole covered its hole and no item could be placed in it.

Changes

  • Rectangles instead of bounding boxes. The obstacles are approximated by rectangles with shape's new outer_approximation_by_rectangles (Add outer_approximation_by_rectangles shape#149), computed once when the branching scheme is built. The maximum waste follows the same rule as the shape simplification: maximum_approximation_ratio × min(bin area, total item area). The ratio is a new parameter of TreeSearchPeriodicPackingParameters, set by optimize to the tree search's not_anytime_maximum_approximation_ratio (0.05). A rectangular frame is covered exactly by 4 rectangles, leaving its hole free.
  • Spacing in front of obstacles. The extent of a periodic block ends one item-item spacing past its items; the bin already compensates for it (usable_bin_bx()), but the obstacles didn't, so a block which fitted exactly in front of an obstacle was rejected. The left and bottom sides of the obstacle rectangles are now moved by one item-item spacing (at most to their middle). This also affected defects and borders with a non-zero item spacing.
  • Update shape to a4efbe93.

Results

The instance of the last comment of #720 (a 400 × 300 frame with a 320 × 220 hole, fixed, and 200 rectangles of 30 × 28), solutions checked with shapely (fixed item present, no overlap, minimum distance, inside the bin):

Before Periodic packing now Tree search
Spacing 0 1 item (the frame) 78 78
Spacing 3 1 item (the frame) 64 64

With the default selection, periodic packing is selected and gives these results.

With slanted fixed items, the tree search can still place a few more items, by nesting them partly next to the slanted edges, which periodic packing sees as a staircase of rectangles.

Tests

Two new periodic packing tests:

  • knapsack_fixed_item_with_hole: a 100 × 60 frame with an 80 × 40 hole; 32 squares fit in the hole, none before.
  • knapsack_fixed_item_with_hole_spacing: the same with an 80 × 38 hole and a spacing of 2, sized so that 3 rows of squares fit only with the spacing fix (it fails without it).

The irregular tests pass (15 + 16 + 4 + 24 + 74), built against the merged shape commit.

tree_search_periodic_packing approximated the defects, borders and fixed
items by their bounding boxes: a fixed item with a hole covered its hole,
so no item could be placed in it (#720).

The obstacles are now approximated by rectangles with shape's
outer_approximation_by_rectangles, within the same maximum waste as the
shape simplification: maximum_approximation_ratio times the smallest of
the bin area and of the total item area, the ratio being the
not_anytime_maximum_approximation_ratio of the tree search. A
rectangular frame is covered exactly by 4 rectangles.

Also give back one item-item spacing on the left and bottom sides of the
obstacles: the extent of a block already ends one spacing past its
items, so a block which fitted exactly in front of an obstacle was
rejected.

Update shape to a4efbe93 for outer_approximation_by_rectangles.
@fontanf
fontanf merged commit be6c319 into master Oct 20, 2026
8 checks passed
@fontanf
fontanf deleted the irregular-periodic-packing-rectangle-obstacles branch October 20, 2026 04:35
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