mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-22 07:37:40 -05:00
Sheet-by-sheet look-ahead cost picks the densest sheet, and a sheet of small parts packs densest. On a braze casing mixing 35x57 to 65x89 plates with 5x28 angles and 9x4 tabs, sheet 1 took 109 small parts and the plates followed one or two to a sheet with empty strips beside them: 28 sheets, 220,032 sq in. Rectangles now also runs the job large parts first, splitting types at the widest drops in box area: the large types nest alone, each of their sheets is repacked with every waiting small part (keeping all its large parts), and leftovers get new sheets. The cheapest whole job wins; ties keep the cost-first run. The braze casing takes 27 sheets and 203,616 sq in, every sheet but the last a plate with small parts in its gaps. Problem-nest corpus (auto-nest): all saved layouts unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
2.3 KiB
C#
61 lines
2.3 KiB
C#
using System.Linq;
|
|
using OpenNest.Engine.Jobs;
|
|
using OpenNest.Engine.NestingEngines.Rectangles;
|
|
using static OpenNest.Engine.Tests.NestingEngines.JobBuilder;
|
|
using static OpenNest.Engine.Tests.NestingEngines.Shapes;
|
|
|
|
namespace OpenNest.Engine.Tests.NestingEngines;
|
|
|
|
/// <summary>
|
|
/// A job mixing large plates with small parts: cost alone picks the densest sheet first, a sheet of
|
|
/// small parts, and leaves the large plates' sheets nothing to fill their gaps with. The large-first
|
|
/// run nests the plates first and fills their gaps, so no sheet is spent on small parts alone.
|
|
/// </summary>
|
|
public class RectanglesLargeFirstTests
|
|
{
|
|
private static NestJob BrazeCasing() => Job(
|
|
new[]
|
|
{
|
|
Part("side-a", Rectangle(56.93, 88.99), 3),
|
|
Part("side-b", Rectangle(58.7, 56.93), 2),
|
|
Part("angle", Rectangle(5.3, 28.28), 30),
|
|
Part("tab", Rectangle(9, 3.75), 40),
|
|
},
|
|
new[]
|
|
{
|
|
Stock("60x120", 60, 120, spacing: 0.25),
|
|
Stock("72x144", 72, 144, spacing: 0.25),
|
|
});
|
|
|
|
private static readonly string[] Large = { "side-a", "side-b" };
|
|
|
|
[Fact]
|
|
public void CostAloneSpendsTheFirstSheetOnSmallParts()
|
|
{
|
|
var job = BrazeCasing();
|
|
|
|
var result = new RectanglesNestingEngine { LargeFirstRuns = false }.Solve(job);
|
|
|
|
LayoutAssert.Valid(job, result);
|
|
Assert.DoesNotContain(result.Plates[0].Placements, p => Large.Contains(p.PartId));
|
|
}
|
|
|
|
[Fact]
|
|
public void SmallPartsFillTheLargePlatesSheets()
|
|
{
|
|
var job = BrazeCasing();
|
|
|
|
var result = new RectanglesNestingEngine().Solve(job);
|
|
var costFirst = new RectanglesNestingEngine { LargeFirstRuns = false }.Solve(job);
|
|
|
|
LayoutAssert.Valid(job, result);
|
|
Assert.Equal(NestJobStatus.Complete, result.Status);
|
|
Assert.True(NestJobCost.Evaluate(job, result) <= NestJobCost.Evaluate(job, costFirst));
|
|
// Only the last sheet may hold small parts alone: those its predecessors had no room for.
|
|
Assert.All(result.Plates.Take(result.Plates.Count - 1),
|
|
sheet => Assert.Contains(sheet.Placements, p => Large.Contains(p.PartId)));
|
|
Assert.All(result.Plates.Take(result.Plates.Count - 1),
|
|
sheet => Assert.Contains(sheet.Placements, p => !Large.Contains(p.PartId)));
|
|
}
|
|
}
|