Skip to content

irregular: add a global nonlinear programming algorithm for continuous rotations - #815

Merged
fontanf merged 2 commits into
masterfrom
irregular-global-nonlinear-programming
Nov 7, 2026
Merged

fontanf merged 2 commits into
masterfrom
irregular-global-nonlinear-programming

Conversation

@fontanf

@fontanf fontanf commented Nov 6, 2026

Copy link
Copy Markdown
Owner

The tree search on relative positions proves nothing when items can be rotated by any angle. This PR adds an exact algorithm for the Feasibility objective with a single convex bin, including with continuous rotations, as a baseline for future exact algorithms with continuous rotations.

Model

Solved to global optimality by SCIP's spatial branch-and-bound (src/irregular/global_nonlinear_programming.{hpp,cpp}):

  • each item has the position of its center (x, y) and its rotation (c, s) with c² + s² = 1, so every point of an item is linear in its variables;
  • an allowed rotation range of width w and middle m is c cos m + s sin m ≥ cos(w/2); with several ranges, binaries select one;
  • containment in the convex bin is linear (convex-hull vertices only, bin shrunk by the item-bin spacing);
  • each pair of convex parts of different items gets a separating line (a, b, d), with bilinear constraints and a² + b² ≥ 1 (= 1 with an item-item spacing);
  • symmetry breaking: identical items ordered by x; first item in the left half when the bin is centrally symmetric and every item rotates freely.

As in the tree search on relative positions, the pairs of item types are solved first by decreasing area, then the growing subsets of the largest items, until a subset is proven infeasible. The solution with all the items is checked with the overlap check of the library before being returned.

Results are exact up to SCIP's feasibility tolerance (1e-6 relative to the bin size), which the documentation states. As in the literature (Cherri et al. 2018, Jones 2014), it handles only a few items: two quickly, three or more rarely.

Unsupported (throws): several bins, non-convex bins, defects, fixed items, mirrored rotations, circular arcs.

Selection and build

  • use_global_nonlinear_programming / --use-global-nonlinear-programming / Python; selected automatically in Exact mode when an item type has continuous rotations.
  • New CMake option PACKINGSOLVER_USE_SCIP, off by default since SCIP is built from source, on in the Build workflow. Without it, the algorithm throws and is never selected automatically.
  • mathoptsolverscmake updated to 2654c5e, which adds SCIP.

Tests

Parametrized test on five new fixtures, the expectation derived from whether a solution file exists:

fixture result
13×1 rectangle in a 10×10 bin feasible, at ~45°
13.5×1 rectangle proven infeasible
two 5.5 squares in a 10×10 bin proven infeasible
two L-shapes and a square feasible
4×6 item with rotations {0°, 90°} and a 4×4 square feasible, at 90°

Plus tests for an unsupported objective and a non-convex bin. The new tests run only with PACKINGSOLVER_USE_SCIP=ON; locally, all 211 tests of the irregular test binary pass with it. Weakening the separating-line constraint makes the feasible multi-item cases fail.

The documentation has a new page describing the model, and the algorithm selection page is updated.

…s rotations

The tree search on relative positions proves nothing when the items can be
rotated by any angle. Add an exact algorithm for the 'Feasibility' objective
with a single convex bin, including with continuous rotations: each item has
a position and a rotation given by its cosine and its sine, each pair of
convex parts of different items a separating line, and the nonconvex
quadratically constrained program is solved to global optimality by the
spatial branch-and-bound of SCIP. The allowed rotation ranges, the item-item
and item-bin spacings, and the symmetries of identical items and of
centrally symmetric bins are handled.

As in the tree search on relative positions, the pairs of item types, then
the increasing subsets of the largest items, are solved until a subset is
proven infeasible. The solution with all the items is checked before being
returned.

It only solves small instances; it is a baseline for exact algorithms with
continuous rotations. In the 'Exact' mode, it is selected if an item type
has continuous rotations.

It requires SCIP: add the CMake option 'PACKINGSOLVER_USE_SCIP', off by
default since SCIP is built from source, and on in the Build workflow.
Update mathoptsolverscmake to the version with SCIP.
The prebuilt static Ipopt libraries don't link on macOS: the gfortran
runtime they include needs libgcc. SCIP only uses Ipopt in its NLP
heuristics, not in its spatial branch-and-bound, so build it without.

Without these heuristics, finding a packing of the two L-shapes and the
square took 25 s: enlarge their bin so that the test stays fast.
@fontanf
fontanf merged commit f4072c9 into master Nov 7, 2026
16 checks passed
@fontanf
fontanf deleted the irregular-global-nonlinear-programming branch November 7, 2026 08:06
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