feat(engine): choose which edge strips count as offcut

Equal-cost plans break ties by the largest edge offcut, from any of the
four edges. A caller that wants the leftover off one way, such as a
shop that keeps only end drops, or a benchmark scoring the used sheet
height, had no way to say so. On the converted Nestbolt jobs the
extended Irregular search then found plans whose larger offcut is a
strip down the side, which Nestbolt scores as worse: b-blaz1-strip
3.601 -> 3.867, b-shirts-strip 2.674 -> 2.995.

NestJobOptions.OffcutCut (a CutOffAxis, default null) counts only the
strips one cut along that axis frees, for salvage credit and the
compactness tie-break alike: Horizontal the full-width bottom and top
strips, Vertical the full-length sides. PlateRemnant.LargestOffcut takes
the axis; NestJobCost, the time limit and clamp-removal recovery pass
it on. Unset, nothing changes.

Benchmark manifests accept "offcutCut": "horizontal" or "vertical".
With horizontal, one CPU, 20 s limit, Default:
  b-blaz1-strip  3.934 -> 3.333
  b-shirts-strip 2.995 -> 2.610
  m-box-deep     1.918 -> 1.276 (Nestbolt 1.251)

Manifests accept only the words horizontal or vertical (any case); a
list such as "horizontal,vertical" is rejected. PlateRemnant rejects an
undefined axis. Fixed strategies keep their own no-salvage tie-break
and ignore the option; desktop, Console and MCP do not offer it yet.

Mutation reds: 14/14 (offcut-mutations.py).
This commit is contained in:
aj committed 2026-10-31 13:29:50 -04:00
1 parent 63bcd89d35
commit 561f5be06c
13 files changed
+208 -14

No files matched your search

@@ -92,6 +92,23 @@ public class DefaultNestingEngineTests
Assert.Equal("first", error.Message);
}
[Theory]
[InlineData(null, 0.0)]
[InlineData(CutOffAxis.Horizontal, 1.0)]
public void TheOffcutCutDecidesWhichEqualCostLayoutWins(CutOffAxis? cut, double expectedY)
{
// Stacked squares leave a 6 x 10 strip at the side and only 10 x 1 on top; a raised row
// leaves 10 x 5 on top. Counting every strip picks the stack; counting only full-width
// strips (a horizontal cut) picks the row.
var plain = SquaresJob();
var job = new NestJob(plain.Parts, plain.Plates, new NestJobOptions(offcutCut: cut));
var result = Choose(job,
Returns(j => Layout(j, Sheet((0, 0), (0, 5)))), Returns(j => Raised(j, 1)));
Assert.Equal(expectedY, result.Plates[0].Placements[0].Y);
}
[Fact]
public void NearTiesAreChosenInTieBreakOrderWhateverTheRunOrder()
{