mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-05 16:29:27 -05:00
Add SequenceMethod.HeatAware (100, outside PEP's numbering) and SequenceParameters.HeatWeight. HeatAwareSequencer orders parts forward by travel seconds plus the weight times the heat estimated where each part is cut, from HeatSpreadEstimate: a Gaussian blob per finished part that widens with conduction and fades with surface loss. Without a thickness it is nearest neighbor. PlateSequencing.Apply takes the sheet's thermal parameters for it and still places cut-offs as before. The method and weight persist in the cutting settings DTO. Plan Cutting does not use the method and no UI offers it: its strict search refuses rapids over parts cut free, so a heat-spreading order needs 53-78 head raises per plate on the measured nests. docs/plate-heat-map.md records the numbers; revisit once thermal readings calibrate the model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
168 lines
6.1 KiB
C#
168 lines
6.1 KiB
C#
using OpenNest.CNC.CuttingStrategy;
|
|
using OpenNest.CNC.Thermal;
|
|
using OpenNest.CutOffs;
|
|
using OpenNest.Engine.Sequencing;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Tests.Sequencing;
|
|
|
|
public class HeatAwareSequencerTests
|
|
{
|
|
private static readonly ThermalParameters QuarterInchSteel = ThermalParameters.For("Mild steel", "A36", 0.25, Units.Inches);
|
|
|
|
private static readonly IReadOnlyCollection<int>[] NoPrerequisites = [[], [], []];
|
|
|
|
// A long hot part beside a short cool one, and another short one far along.
|
|
private static HeatAwareItem[] HotNeighbor() =>
|
|
[
|
|
Item(1, 0, 60),
|
|
Item(2, 0, 10),
|
|
Item(20, 0, 10),
|
|
];
|
|
|
|
private static HeatAwareItem Item(double x, double y, double seconds) =>
|
|
new(new Vector(x, y), new Vector(x, y), new Box(x - 0.5, y - 0.5, 1, 1), seconds);
|
|
|
|
[Fact]
|
|
public void WithoutWeight_ItIsNearestNeighbor()
|
|
{
|
|
var order = HeatAwareOrder.Plan(HotNeighbor(), [0, 1, 2], Vector.Zero, NoPrerequisites,
|
|
QuarterInchSteel, 0, default);
|
|
|
|
Assert.Equal([0, 1, 2], order);
|
|
}
|
|
|
|
[Fact]
|
|
public void WithoutThickness_ItIsNearestNeighbor()
|
|
{
|
|
var order = HeatAwareOrder.Plan(HotNeighbor(), [0, 1, 2], Vector.Zero, NoPrerequisites,
|
|
ThermalParameters.For("Mild steel", "A36", 0, Units.Inches), 0.15, default);
|
|
|
|
Assert.Equal([0, 1, 2], order);
|
|
}
|
|
|
|
[Fact]
|
|
public void AHotNeighbor_IsLeftUntilTheRouteComesBack()
|
|
{
|
|
var order = HeatAwareOrder.Plan(HotNeighbor(), [0, 1, 2], Vector.Zero, NoPrerequisites,
|
|
QuarterInchSteel, 0.15, default);
|
|
|
|
Assert.Equal([0, 2, 1], order);
|
|
}
|
|
|
|
[Fact]
|
|
public void ItGoesOnlyAsFarAsTheHotZone()
|
|
{
|
|
// Two cool parts beyond the hot neighbor: the nearer one clear of the heat comes next,
|
|
// not the farthest.
|
|
HeatAwareItem[] items = [Item(1, 0, 60), Item(2, 0, 10), Item(12, 0, 10), Item(40, 0, 10)];
|
|
|
|
var order = HeatAwareOrder.Plan(items, [0, 1, 2, 3], Vector.Zero, [[], [], [], []],
|
|
QuarterInchSteel, 0.15, default);
|
|
|
|
Assert.Equal(0, order[0]);
|
|
Assert.Equal(2, order[1]);
|
|
}
|
|
|
|
[Fact]
|
|
public void APrerequisite_StillComesFirst()
|
|
{
|
|
// The hot neighbor must follow the first part (as a nested part precedes its host).
|
|
IReadOnlyCollection<int>[] prerequisites = [[], [0], []];
|
|
|
|
var order = HeatAwareOrder.Plan(HotNeighbor(), [1, 0, 2], Vector.Zero, prerequisites,
|
|
QuarterInchSteel, 0.15, default);
|
|
|
|
Assert.True(Array.IndexOf(order, 0) < Array.IndexOf(order, 1));
|
|
Assert.Equal([0, 1, 2], order.Order());
|
|
}
|
|
|
|
[Fact]
|
|
public void PartsAlreadyCut_LeaveTheirHeat()
|
|
{
|
|
// Re-planning parts 1 and 2 after part 0 was cut: part 1 sits in part 0's heat.
|
|
var order = HeatAwareOrder.Plan(HotNeighbor(), [1, 2], new Vector(1, 0), NoPrerequisites,
|
|
QuarterInchSteel, 0.15, default, done: [0], origin: Vector.Zero);
|
|
|
|
Assert.Equal([2, 1], order);
|
|
}
|
|
|
|
[Fact]
|
|
public void Estimate_FadesAndSpreadsWithTime()
|
|
{
|
|
var estimate = new HeatSpreadEstimate(QuarterInchSteel);
|
|
estimate.Add(Vector.Zero, 0.5, 30, 0);
|
|
|
|
var atOnce = estimate.TemperatureAt(Vector.Zero, 0);
|
|
var later = estimate.TemperatureAt(Vector.Zero, 60);
|
|
var aside = estimate.TemperatureAt(new Vector(3, 0), 0);
|
|
var asideLater = estimate.TemperatureAt(new Vector(3, 0), 60);
|
|
|
|
Assert.True(atOnce > later);
|
|
Assert.True(aside < atOnce);
|
|
Assert.True(asideLater > aside, "Heat conducts outward.");
|
|
}
|
|
|
|
[Fact]
|
|
public void Sequencer_ReturnsTheForwardOrderExitFirst()
|
|
{
|
|
var plate = new Plate(60, 30);
|
|
var parts = Enumerable.Range(0, 3).Select(i => TestHelpers.MakePartAt(5 + i * 10, 5)).ToList();
|
|
foreach (var part in parts)
|
|
plate.Parts.Add(part);
|
|
|
|
// No thickness: nearest neighbor from the plate's origin corner.
|
|
var result = new HeatAwareSequencer(new SequenceParameters { Method = SequenceMethod.HeatAware }, null)
|
|
.Sequence(parts, plate);
|
|
|
|
Assert.Equal(new[] { parts[2], parts[1], parts[0] }, result.Select(r => r.Part));
|
|
}
|
|
|
|
[Fact]
|
|
public void Apply_CutsAHotNeighborLater()
|
|
{
|
|
// Ten small squares in a row; with a heavy weight the next part is never the one beside
|
|
// the part just cut.
|
|
var plate = new Plate(120, 20);
|
|
var parts = Enumerable.Range(0, 10).Select(i => TestHelpers.MakePartAt(1 + i * 1.5, 1)).ToList();
|
|
foreach (var part in parts)
|
|
plate.Parts.Add(part);
|
|
var parameters = new SequenceParameters { Method = SequenceMethod.HeatAware, HeatWeight = 5 };
|
|
|
|
PlateSequencing.Apply(plate, parameters, QuarterInchSteel);
|
|
|
|
var order = plate.Parts.Select(part => parts.IndexOf(part)).ToArray();
|
|
Assert.Equal(Enumerable.Range(0, 10), order.Order());
|
|
Assert.Equal(0, order[0]);
|
|
Assert.Contains(order.Zip(order.Skip(1)), pair => System.Math.Abs(pair.First - pair.Second) > 1);
|
|
}
|
|
|
|
[Fact]
|
|
public void Apply_KeepsCutOffsBeforeThePartsTheyCross()
|
|
{
|
|
var plate = new Plate(60, 30);
|
|
var left = TestHelpers.MakePartAt(5, 5);
|
|
var right = TestHelpers.MakePartAt(40, 5);
|
|
plate.Parts.Add(left);
|
|
plate.Parts.Add(right);
|
|
plate.CutOffs.Add(new CutOff(new Vector(20, 0), CutOffAxis.Vertical));
|
|
plate.RegenerateCutOffs(new CutOffSettings());
|
|
|
|
PlateSequencing.Apply(plate, new SequenceParameters { Method = SequenceMethod.HeatAware }, QuarterInchSteel);
|
|
|
|
var applied = plate.Parts.ToList();
|
|
Assert.Contains(applied, p => p.BaseDrawing.IsCutOff);
|
|
Assert.Equal(2, applied.Count(p => !p.BaseDrawing.IsCutOff));
|
|
// The cut-off rules already hold: applying them again changes nothing.
|
|
Assert.Equal(applied, PlateSequencing.OrderCutOffsFirst(applied, plate));
|
|
}
|
|
|
|
[Fact]
|
|
public void Factory_CreatesTheHeatAwareSequencer()
|
|
{
|
|
var sequencer = PartSequencerFactory.Create(new SequenceParameters { Method = SequenceMethod.HeatAware });
|
|
|
|
Assert.IsType<HeatAwareSequencer>(sequencer);
|
|
}
|
|
}
|