feat(planner): order a part's holes by the heat start limit

Dense hole patterns heat one area when cut row after row, and the part
order cannot spread that heat. With the limit on, a part's holes follow
the same start rule, lattices in strided rows; jumps over cut holes are
emitted head up and counted as heat raises. On a vent-pan nest the
hottest zones fell 43% for 3% more cut time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-12-03 19:20:22 -05:00
1 parent 4a5c96f011
commit 2c9b458761
10 files changed
+243 -11

No files matched your search

@@ -59,4 +59,55 @@ internal static class CuttingHoleOrder
var route = CuttingPartOrder.Plan(centers, arrival, prerequisites, token, perimeterEntry);
return route.Select(index => holes[index]).ToArray();
}
/// <summary>
/// The heat start limit's hole order (docs/cutting-planner.md#heat-start-limit): the rule
/// <see cref="CuttingHeatOrder"/> applies to parts, applied to the part's holes, with the plain
/// <paramref name="route"/> as the order it walks. Holes that form a lattice of at least
/// <see cref="CuttingGridOrder.MinimumParts"/> are cut as strided lines
/// (<see cref="CuttingGridStride.Pieces"/>), each from its nearer end; others one by one. The
/// estimate holds this part's holes alone, from when the tool reaches the part. A move whose
/// straight rapid passes over a hole already cut (its box widened by the largest hole's
/// half-size, since the tool leaves a hole from its edge, not its center) is a jump: that hole's
/// arrival is raised. The perimeter's is raised when the rapid onto it from the last hole passes
/// over one. A limit the estimate never reaches keeps <paramref name="route"/> with no jumps.
/// </summary>
internal static (int[] Route, IReadOnlySet<int> Jumps, bool RaisePerimeter) PlanHeat(PreparedContours prepared,
int[] route, IReadOnlyList<Vector> centersByOrdinal, Vector arrival, Vector perimeterEntry, CuttingHeat heat,
CancellationToken token)
{
var none = (route, (IReadOnlySet<int>)new HashSet<int>(), false);
if (heat == null || route.Length < 2)
return none;
var count = prepared.PerimeterOrdinal;
var bounds = Enumerable.Range(0, count).Select(prepared.ContourBounds).ToArray();
var margin = route.Max(hole => System.Math.Max(bounds[hole].Width, bounds[hole].Length)) / 2;
var items = new CuttingHeatItem[count];
foreach (var hole in route)
{
var box = bounds[hole];
items[hole] = new(centersByOrdinal[hole], centersByOrdinal[hole],
new Box(box.X - margin, box.Y - margin, box.Width + 2 * margin, box.Length + 2 * margin),
prepared.ContourLength(hole), 1);
}
int[] order;
int[] jumps;
var lines = route.Length >= CuttingGridOrder.MinimumParts
? CuttingGridOrder.Lines(route.Select(hole => bounds[hole]).ToArray(), arrival, token) : null;
if (lines != null)
{
var stride = CuttingGridStride.Current;
var pieces = (stride.IsPlain ? lines : CuttingGridStride.Pieces(lines, stride))
.Select(line => line.Select(index => route[index]).ToArray()).ToArray();
(order, jumps, _) = CuttingHeatOrder.PlanPieces(pieces, arrival, items, null, heat, token, !stride.IsPlain);
}
else
(order, jumps, _) = CuttingHeatOrder.Plan(route, arrival, items, null, heat, token);
if (ReferenceEquals(order, route) || order.SequenceEqual(route) && jumps.Length == 0)
return none;
var last = order[^1];
var raisePerimeter = order.Any(hole => hole != last
&& CuttingHeatOrder.SegmentHitsBox(items[last].Exit, perimeterEntry, items[hole].Extent));
return (order, jumps.ToHashSet(), raisePerimeter);
}
}
@@ -628,7 +628,8 @@ public static class CuttingPlanService
var (strict, fixedFindings, raised, tabLeadOuts) = checker.Check(execution, position,
source.SourceOrdinal + 1, source.IsCutOff, isFixed, token, snapshot.WarnsTabLeadOuts(source));
// A rapid the heat-aware order raised to jump to this part is designed, not a last resort.
if (!safestRoute && snapshot.HeatJumps.Contains(source.SourceOrdinal))
if (!safestRoute && (snapshot.HeatJumps.Contains(source.SourceOrdinal)
|| proposal.ContourChoices?.Any(choice => choice.RaisesArrival) == true))
{
raises.AddRange(RaisedRapids.HeatNotes(snapshot, source, raised));
heatRaises += RaisedRapids.Count(raised);
@@ -998,7 +998,8 @@ internal static class JointCuttingPlanSearch
if (node.Active?.Perimeter is { } perimeter)
{
if (contour == prepared.PerimeterOrdinal)
entries = [perimeter];
entries = [preference.RaisesPerimeter && !perimeter.RaisesArrival
? perimeter with { RaisesArrival = true } : perimeter];
else
{
contourRank = preference.RankOf(contour);
@@ -1017,6 +1018,8 @@ internal static class JointCuttingPlanSearch
if (preference.Entries.TryGetValue(contour, out var preferred))
entries = entries.OrderBy(e => e.Point.DistanceTo(preferred.Point)
<= PostVerificationGeometry.Epsilon ? 0 : 1).ToArray();
if (preference.Jumps.Contains(contour))
entries = entries.Select(e => Raised(e, preference.Jumps)).ToArray();
}
}
}
@@ -1787,18 +1790,23 @@ internal static class JointCuttingPlanSearch
var entries = new Dictionary<int, ContourChoice>();
var pierces = holes.ToDictionary(h => h, h => centers[h]);
var route = holes;
IReadOnlySet<int> jumps = new HashSet<int>();
var raisePerimeter = false;
try
{
CountExpansion(source);
endpoint = PreferredContourEntries.Pierce(prepared, perimeter, token);
route = CuttingHoleOrder.Plan(holes, centers, localArrival, endpoint, token).ToArray();
// With a heat start limit, the holes are cut where the part is cool, jumps head up.
(route, jumps, raisePerimeter) = CuttingHoleOrder.PlanHeat(prepared, route, centers, localArrival,
endpoint, snapshot.Heat, token);
var proposal = PreferredContourEntries.TryPlan(prepared, perimeter, route, centers,
localArrival, candidate => Evaluate(source, candidate), token);
if (proposal.IsPreferred)
foreach (var choice in proposal.HoleChoices)
{
CountExpansion(source);
entries.Add(choice.ContourOrdinal, choice);
entries.Add(choice.ContourOrdinal, Raised(choice, jumps));
pierces[choice.ContourOrdinal] = PreferredContourEntries.Pierce(prepared, choice, token);
}
else
@@ -1812,9 +1820,13 @@ internal static class JointCuttingPlanSearch
rejected.Add(Finding(source, PostVerificationKind.Incomplete,
$"Preferred hole path unavailable: {ex.Message}"));
}
return new(route, entries, pierces, endpoint);
return new(route, entries, pierces, endpoint) { Jumps = jumps, RaisesPerimeter = raisePerimeter };
}
// The choice with its arrival raised when the heat-aware hole order jumps to its contour.
private static ContourChoice Raised(ContourChoice choice, IReadOnlySet<int> jumps) =>
jumps.Contains(choice.ContourOrdinal) && !choice.RaisesArrival ? choice with { RaisesArrival = true } : choice;
/// <summary>
/// The order with segments placed, where each holed part cut straight after a segment
/// takes the hole route and entries planned from the segment's end, where the tool
@@ -2253,6 +2265,12 @@ internal static class JointCuttingPlanSearch
private sealed record HolePreference(int[] Route, IReadOnlyDictionary<int, ContourChoice> Entries,
IReadOnlyDictionary<int, Vector> Pierces, Vector PerimeterPierce)
{
/// <summary>The holes a heat-aware hole order reaches head up (<see cref="CuttingHoleOrder.PlanHeat"/>).</summary>
internal IReadOnlySet<int> Jumps { get; init; } = new HashSet<int>();
/// <summary>Whether the rapid from the heat-aware order's last hole onto the perimeter is made head up.</summary>
internal bool RaisesPerimeter { get; init; }
private readonly Dictionary<int, int> ranks = Route.Select((contour, rank) => (contour, rank))
.DistinctBy(r => r.contour).ToDictionary(r => r.contour, r => r.rank);
@@ -170,6 +170,11 @@ internal static class RaisedRapids
{
var parts = rapid.Select(f => f.OtherPartNumber).OfType<int>().Distinct().Order().ToArray();
var other = parts.Length == 1 ? snapshot.Placements[parts[0] - 1] : null;
// A heat-aware hole order's jump passes over the part's own holes.
if (other != null && other.SourceOrdinal == source.SourceOrdinal)
return new CuttingPlanFinding(source.SourceOrdinal, source.SourcePart, null, null, null,
"A rapid raises the head over holes already cut to cut a cooler area of the part next.")
{ Witness = rapid.First() };
var over = other != null ? "a part already cut" : $"parts {string.Join(", ", parts)}, already cut,";
return new CuttingPlanFinding(source.SourceOrdinal, source.SourcePart, other?.SourceOrdinal,
other?.SourcePart, null, $"A rapid raises the head over {over} to cut a cooler area of the sheet next.")