mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-04 16:29:24 -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>
98 lines
4.6 KiB
C#
98 lines
4.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using OpenNest.CNC.Thermal;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Engine.Sequencing
|
|
{
|
|
/// <summary>
|
|
/// What the heat-aware order needs of one part: where its cut starts and ends, its cut extent
|
|
/// (where its heat goes) and how long the torch is on.
|
|
/// </summary>
|
|
internal readonly record struct HeatAwareItem(Vector Entry, Vector Exit, Box Extent, double TorchSeconds)
|
|
{
|
|
internal Vector Center => Extent.Center;
|
|
|
|
/// <summary>The heat's initial spread: a quarter of the extent's squared diagonal.</summary>
|
|
internal double Spread2 => (Extent.Length * Extent.Length + Extent.Width * Extent.Width) / 4;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Orders parts forward from a start point: each next part is the dependency-ready one with the
|
|
/// least travel seconds plus <c>weight</c> times the estimated heat (°C) at its center when the
|
|
/// tool gets there, from a <see cref="HeatSpreadEstimate"/> of the parts already cut. So the
|
|
/// route leaves a hot zone, but only as far as it must. Without a thickness, or with no weight,
|
|
/// it is a nearest-neighbor order by travel. It ignores whether a move passes over parts already
|
|
/// cut; see docs/plate-heat-map.md#sequencing.
|
|
/// </summary>
|
|
internal static class HeatAwareOrder
|
|
{
|
|
/// <param name="items">Every part's data, by ordinal.</param>
|
|
/// <param name="parts">The ordinals to order; prerequisites outside this set count as cut.</param>
|
|
/// <param name="start">The tool position before the first part.</param>
|
|
/// <param name="prerequisites">Ordinals that must come before each part; must be acyclic.</param>
|
|
/// <param name="done">Parts already cut, in order, from <paramref name="origin"/>: their heat
|
|
/// is laid down first. Null for none.</param>
|
|
/// <param name="origin">Where the tool was before <paramref name="done"/>.</param>
|
|
internal static int[] Plan(IReadOnlyList<HeatAwareItem> items, IReadOnlyList<int> parts, Vector start,
|
|
IReadOnlyList<IReadOnlyCollection<int>> prerequisites, ThermalParameters thermal, double weight,
|
|
CancellationToken token, IReadOnlyList<int> done = null, Vector? origin = null)
|
|
{
|
|
var estimate = new HeatSpreadEstimate(thermal ?? new ThermalParameters());
|
|
var heated = estimate.HasThickness && double.IsFinite(weight) && weight > 0;
|
|
|
|
var time = 0.0;
|
|
if (done is { Count: > 0 })
|
|
{
|
|
var position = origin ?? start;
|
|
foreach (var part in done)
|
|
{
|
|
var item = items[part];
|
|
time += estimate.TravelSeconds(position.DistanceTo(item.Entry)) + item.TorchSeconds;
|
|
estimate.Add(item.Center, item.Spread2, item.TorchSeconds, time);
|
|
position = item.Exit;
|
|
}
|
|
}
|
|
|
|
var pending = new HashSet<int>(parts);
|
|
var remaining = parts.ToList();
|
|
var order = new int[parts.Count];
|
|
var current = start;
|
|
for (var step = 0; step < order.Length; step++)
|
|
{
|
|
token.ThrowIfCancellationRequested();
|
|
var best = -1;
|
|
var bestCost = double.MaxValue;
|
|
foreach (var part in remaining)
|
|
{
|
|
if (prerequisites[part].Any(pending.Contains))
|
|
continue;
|
|
var item = items[part];
|
|
var travel = estimate.TravelSeconds(current.DistanceTo(item.Entry));
|
|
var cost = heated ? travel + weight * estimate.TemperatureAt(item.Center, time + travel) : travel;
|
|
// Strictly cheaper only, so ties keep the given order.
|
|
if (cost < bestCost)
|
|
{
|
|
best = part;
|
|
bestCost = cost;
|
|
}
|
|
}
|
|
if (best < 0)
|
|
throw new InvalidOperationException("Part prerequisites form a cycle.");
|
|
|
|
var chosen = items[best];
|
|
time += estimate.TravelSeconds(current.DistanceTo(chosen.Entry)) + chosen.TorchSeconds;
|
|
if (heated)
|
|
estimate.Add(chosen.Center, chosen.Spread2, chosen.TorchSeconds, time);
|
|
current = chosen.Exit;
|
|
order[step] = best;
|
|
pending.Remove(best);
|
|
remaining.Remove(best);
|
|
}
|
|
return order;
|
|
}
|
|
}
|
|
}
|