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

+1 -1
View File
@@ -59,7 +59,7 @@ Releases: follow [the release procedure](docs/releasing.md) and `scripts/Publish
- Cutoffs persist as definitions on `Plate.CutOffs`; apply through `RegenerateCutOffs`, never preview parts. Preserve sequence positions. Batch planning must finish before mutation and roll back on failure. Cut order comes from Plan Cutting or the user (no automatic part sequencers); use `PlateSequencing.OrderCutOffsFirst`/`PlaceCutOffs` for cutoff dependencies, with nominal spans/reference identity rather than trimmed geometry/names.
- A cutoff starts only at the origin-side edge: stock can be oversize, so the far edge is unknown. Only a head-locked overcut (`CutOff.HeadLockOvercut`, `HeadHeightLock` markers) may start its far-edge segment there; posts refuse it without lock codes.
- Fixed emissions (locked programs, drawing-pinned contours) are accepted as given: their violations warn on an UNVERIFIED proposal and never steer the search, while every planner-chosen motion stays strict. Plates without them must keep the `PlanningCharacterizationTests` digests.
- A `HeadRaise` marker (a rapid made head-up over cut parts) is the safest-route fallback's last resort, added only after the strict search fails; the strict search never marks a rapid. Designed raises are the rapid out of a cutout's slug after its lead-out, marked at emission (see the cutting planner doc; no lead-out or an overcut keeps the head down), and the heat jumps an opt-in `HeatStartLimit` (°C) plans to cooler parts or grid lines (counted in `HeatRaises`; limit 0 must stay byte-identical). Every post must raise before a marked rapid or refuse the nest.
- A `HeadRaise` marker (a rapid made head-up over cut parts) is the safest-route fallback's last resort, added only after the strict search fails; the strict search never marks a rapid. Designed raises are the rapid out of a cutout's slug after its lead-out, marked at emission (see the cutting planner doc; no lead-out or an overcut keeps the head down), and the heat jumps an opt-in `HeatStartLimit` (°C) plans to cooler parts, grid lines or holes (counted in `HeatRaises`; limit 0 must stay byte-identical). Every post must raise before a marked rapid or refuse the nest.
- An empty diagnostic is not a clear result unless `IsComplete`. Posting must run checks before writing CNC output; warnings require explicit per-attempt consent, never a persisted bypass. Keep inputs stable through analysis/cancellation.
- Preserve symbolic G-code variable definitions/references in file round trips. Keep training bitmaps by default; inference checks predictor availability before scalar-only extraction.
@@ -23,6 +23,14 @@ public sealed record ContourChoice(int ContourOrdinal, int EntityOrdinal, Vector
/// pierced has no lead-out. Null for every other choice.
/// </summary>
public Vector? Pierce { get; internal init; }
/// <summary>
/// Whether the rapid onto this contour is made head up (<see cref="HeadRaise"/>): a heat-aware
/// hole order's jump across cutouts already cut to a cooler area of the part (see
/// docs/cutting-planner.md#heat-start-limit). Emission marks it; the checks then treat its
/// crossings as raised.
/// </summary>
public bool RaisesArrival { get; internal init; }
}
/// <summary>
@@ -1225,6 +1233,9 @@ public sealed class PreparedContours
/// <summary>The bounding box of contour <paramref name="contourOrdinal"/>, local. A routing hint only.</summary>
internal Box ContourBounds(int contourOrdinal) => GetShape(contourOrdinal).BoundingBox;
/// <summary>The length of contour <paramref name="contourOrdinal"/>, without leads. A heat estimate's input only.</summary>
internal double ContourLength(int contourOrdinal) => GetShape(contourOrdinal).Length;
/// <summary>
/// Whether <paramref name="point"/> lies inside the internal contour <paramref name="contourOrdinal"/>.
/// A routing hint only (chorded at the overlap check's tolerance), never a clearance verdict.
@@ -337,7 +337,7 @@ namespace OpenNest.CNC.CuttingStrategy
shapes[perimeterOrdinal].Entities[choice.EntityOrdinal], ContourType.External,
exactCirclePrograms: true, scrapPierce: choice.Pierce, stopAtCenterLine: false,
memoContour: choice.ContourOrdinal);
if (inSlug && start < result.Codes.Count && result.Codes[start] is RapidMove)
if ((inSlug || choice.RaisesArrival) && start < result.Codes.Count && result.Codes[start] is RapidMove)
result.Codes.Insert(start, new Comment(HeadRaise.Marker));
inSlug = false;
continue;
@@ -348,7 +348,7 @@ namespace OpenNest.CNC.CuttingStrategy
Parameters = shared;
var first = result.Codes.Count;
EmitCommonLinePerimeter(result, shapes[perimeterOrdinal], commonLine);
if (inSlug && first < result.Codes.Count && result.Codes[first] is RapidMove)
if ((inSlug || choice.RaisesArrival) && first < result.Codes.Count && result.Codes[first] is RapidMove)
result.Codes.Insert(first, new Comment(HeadRaise.Marker));
inSlug = false;
continue;
@@ -368,8 +368,8 @@ namespace OpenNest.CNC.CuttingStrategy
memoContour: choice.ContourOrdinal);
// A cutout's lead-out ends in its slug, which may drop or tip once cut free, so
// the rapid out over the cut is made head up. An overcut or no lead-out leaves
// from the cut itself and stays head down.
if (inSlug && arrival < result.Codes.Count && result.Codes[arrival] is RapidMove or SubProgramCall)
// from the cut itself and stays head down. A heat-aware jump is made head up too.
if ((inSlug || choice.RaisesArrival) && arrival < result.Codes.Count && result.Codes[arrival] is RapidMove or SubProgramCall)
result.Codes.Insert(arrival, new Comment(HeadRaise.Marker));
inSlug = leftInSlug;
}
@@ -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.")
@@ -0,0 +1,114 @@
using OpenNest.CNC;
using OpenNest.CNC.CuttingPlanning;
using OpenNest.CNC.Thermal;
using OpenNest.Engine.CuttingPlanning;
using OpenNest.Geometry;
namespace OpenNest.Tests.CuttingPlanning;
/// <summary>The heat start limit's order of a part's holes (<see cref="CuttingHoleOrder.PlanHeat"/>).</summary>
public class CuttingHoleHeatOrderTests
{
private const int Columns = 20;
private const int Rows = 12;
private static CuttingHeat Heat(double limit) => CuttingHeat.For(limit,
ThermalParameters.For("Mild Steel", null, 0.06, Units.Inches), CutParameters.Default);
// A 22 x 14 in panel with a lattice of 0.25 in holes one inch apart, row by row.
private static Program Panel()
{
var program = LeadPathValidationTests.Rectangle(0, 0, Columns + 2, Rows + 2);
for (var row = 0; row < Rows; row++)
for (var column = 0; column < Columns; column++)
{
var center = new Vector(1.5 + column, 1.5 + row);
program.MoveTo(center.X + 0.125, center.Y);
program.ArcTo(center.X + 0.125, center.Y, center.X, center.Y, RotationType.CCW);
}
return program;
}
private static (PreparedContours Prepared, int[] Route, Vector[] Centers) Route()
{
var prepared = PreparedContours.Capture(Panel(), HoleLookAheadTests.Parameters());
var holes = Enumerable.Range(0, prepared.PerimeterOrdinal).ToArray();
var centers = CuttingHoleOrder.Centers(prepared, new Vector(-1, -1), CancellationToken.None);
var route = CuttingHoleOrder.Plan(holes, centers, new Vector(-1, -1), new Vector(0, 0)).ToArray();
return (prepared, route, centers);
}
[Fact]
public void NoLimit_KeepsTheRoute()
{
var (prepared, route, centers) = Route();
var (order, jumps, raisePerimeter) = CuttingHoleOrder.PlanHeat(prepared, route, centers, new Vector(-1, -1),
Vector.Zero, null, CancellationToken.None);
Assert.Same(route, order);
Assert.Empty(jumps);
Assert.False(raisePerimeter);
}
[Fact]
public void Limit_CutsTheLatticeInStridedRows()
{
var (prepared, route, centers) = Route();
var (order, jumps, _) = CuttingHoleOrder.PlanHeat(prepared, route, centers, new Vector(-1, -1),
Vector.Zero, Heat(20), CancellationToken.None);
Assert.Equal(route.Order(), order.Order());
int Row(int hole) => (int)System.Math.Round(centers[hole].Y - 1.5);
var rows = order.Select(Row).Where((row, index) => index == 0 || row != Row(order[index - 1])).ToArray();
// Each row is cut whole, and the second is not beside the first.
Assert.Equal(Rows, rows.Length);
Assert.Equal(Enumerable.Range(0, Rows), rows.Order());
Assert.True(System.Math.Abs(rows[1] - rows[0]) > 1);
Assert.NotEmpty(jumps);
Assert.All(jumps, jump => Assert.Contains(jump, order));
}
[Fact]
public void RaisedChoice_IsEmittedHeadUp()
{
var prepared = PreparedContours.Capture(Panel(), HoleLookAheadTests.Parameters());
var choices = Enumerable.Range(0, prepared.Count)
.Select(contour => prepared.ClosestEntry(contour, Vector.Zero)).ToArray();
Assert.False(HeadRaise.IsMarked(prepared.Emit(choices)));
choices[5] = choices[5] with { RaisesArrival = true };
Assert.True(HeadRaise.IsMarked(prepared.Emit(choices)));
}
private static CuttingPlanResult Plan(double limit)
{
var plate = new Plate(40, 30);
plate.Parts.Add(new Part(new Drawing("panel", Panel()), new Vector(2, 2)));
var parameters = ExplicitContourTests.Parameters();
parameters.MaterialName = "Mild Steel";
parameters.Thickness = 0.06;
parameters.HeatStartLimit = limit;
return CuttingPlanService.Plan(CuttingPlanRequest.ForPlate(plate, Vector.Zero, confirmedParameters: parameters));
}
[Fact]
public void Limit_PlansThePanelReadyWithMarkedHeatRaises()
{
var plain = Plan(0);
var heated = Plan(20);
Assert.Equal(CuttingPlanStatus.Ready, plain.Status);
Assert.Equal(0, plain.HeatRaises);
Assert.False(HeadRaise.IsMarked(plain.ProposedOrder[0].CopyProgram()));
Assert.Equal(CuttingPlanStatus.Ready, heated.Status);
Assert.False(heated.IsSafestRouteFallback);
Assert.Equal(0, heated.HeadRaises);
Assert.True(heated.HeatRaises > 0);
Assert.True(HeadRaise.IsMarked(heated.ProposedOrder[0].CopyProgram()));
Assert.NotEqual(plain.ProposedOrder[0].ContourChoices.Select(c => c.ContourOrdinal),
heated.ProposedOrder[0].ContourChoices.Select(c => c.ContourOrdinal));
Assert.Contains(heated.Findings, f => f.Message.Contains("holes already cut"));
}
}
+10
View File
@@ -943,6 +943,16 @@ ready.
longer decide whether the lattice gets the line order. A plate whose lattice parts take part in
a required order, or whose other parts are nested in one another or are cut-offs, keeps the
rules above. See [grid strides and clusters](plate-heat-map.md#grid-strides-and-clusters).
- Holes: a part's holes follow the same rule inside the part (`CuttingHoleOrder.PlanHeat`), with
the plain hole tour as the order walked and an estimate holding that part's holes alone, from
when the tool reaches it. Holes forming a lattice of at least 200 are cut as strided lines like
a grid's, each from its nearer end; fewer go one by one. 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) is a jump: that hole's `ContourChoice.RaisesArrival` is set and emission writes
`HEAD RAISE` before its rapid or sub-program call, so the search, replay and posts all treat its
crossings as raised. The rapid from the last hole onto the perimeter is raised the same way when it
passes over a hole. These raises are counted in `HeatRaises` and noted as raised over holes
already cut. See [hole order](plate-heat-map.md#hole-order).
A leg of the plain order is checked for crossings only against parts the rule cut ahead of it
and parts cut before a re-plan; the plain order's own legs over parts it cut in order are the
+24 -2
View File
@@ -122,8 +122,8 @@ bed, and its heat label says whether the sheet is cooled by air only or by air a
Plan Cutting's part order keeps work from starting where the sheet is hot when the cutting
parameters set `HeatStartLimit` (an estimated temperature rise in °C, 0 = off, saved per material
and thickness on the Tabs & Pierce tab as "Don't start above (°C rise)"). Before each part, or
each line of a large grid, the order estimates the temperature where it starts: the tour's next
and thickness on the Tabs & Pierce tab as "Don't start above (°C rise)"). Before each part, each
line of a large grid, or each hole or row of holes in a part ([hole order](#hole-order)), the order estimates the temperature where it starts: the tour's next
piece when that is at or under the limit, else the nearest under it, else the coolest. A move
across parts already cut raises the head (`HEAD RAISE`, counted as heat raises). See
[heat start limit](cutting-planner.md#heat-start-limit). This simulation only scores finished
@@ -198,6 +198,28 @@ the limit off. Leaving the part just cut out of the estimate (the heat right beh
was tried for single parts and dropped: it halved the raises on the thin sheet but left the
starts' P90 at 32–36 °C, where counting it brings them to about 3 °C.
### Hole order
The part order cannot cool a part whose own holes hold most of its heat. On P241017-01 (three
bakery vent pans of 1,709 0.25 in holes each, 1 in apart in staggered rows 0.75 in apart, beside
ten small squares; 0.06 in mild steel), the plain hole tour cuts row after row and the part-level
limit alone moved the hottest zones by 2%. With the limit on, each part's holes are walked by the
same rule ([heat start limit](cutting-planner.md#heat-start-limit)): lattices in strided rows, the
jumps across cut holes made head up. `HeatOrderMeasurementTests` also reports the mean temperature
within 0.5 in of every pierce when it starts. Default timing, 20 °C limit:
| Order | Zone P95 | Zone P75 | Pierces median / P90 / P99 / max | Travel | Cut time | Heat raises |
|-------|----------|----------|----------------------------------|--------|----------|-------------|
| Off | 248 | 211 | 70 / 119 / 148 / 189 | 4,406 | 6,595 s | 0 |
| Parts only (before holes were ordered) | 243 | 211 | | 4,506 | 6,615 s | 6 |
| Rows, not strided (1x1) | 156 | 138 | 38 / 50 / 52 / 121 | 5,146 | 6,743 s | 20 |
| Every 3rd row (the default) | 142 | 120 | 18 / 38 / 80 / 121 | 5,411 | 6,796 s | 65 |
| Every 4th row | 133 | 104 | 10 / 29 / 71 / 121 | 5,335 | 6,781 s | 76 |
Every plan was Ready with no fallback raise, planned in about 3 s. The 3rd-row stride cuts the hottest
zones by 43% and the median pierce from 70 to 18 °C for 3% more cut time; the stride is the grid's
(`CuttingGridStride.Current`), so `OPENNEST_HEAT_STRIDES` compares both together.
### Grid strides and clusters
The line rule tests only where a line starts. On N26-2F2 (666 parts, 659 of them 1.15 x 0.75 in