From ad991edb9fbfe39ee430be4826ca1c71c7f41f41 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Thu, 3 Dec 2026 14:06:50 -0500 Subject: [PATCH] feat(planner): stride heat-aware grids and cut lattices apart from other parts With a heat start limit, a large grid's lines are now cut every third line per pass, filling the rest on later passes, and a plate's lattice (its most common part size, when it forms a grid beside other parts) is cut in those lines while the other parts keep the single-part rule, all in one heat walk. The rule alone tested only where a line starts, so a line began cool and ran into its neighbors' heat: on N26-2F2 (659 washers, 0.12 in, 20 C) line starts measured 7 C but the median part 87 C. Strided, every part's start P90/max falls from 105/145 to 89/102 C and the hottest zones by 13%, for +0.4% cut time and 8 more heat raises. Clusters change nothing on that plate, whose few other parts happen to bin into the lattice; they keep the line order on plates where one off-pitch part would drop the whole plate to the single-part rule. Limit 0 is unchanged: neither runs without a limit. The measurement harness can still compare strides and turn clusters off for its own flow of work. Co-Authored-By: Claude Opus 5.5 --- .../CuttingPlanning/CuttingGridStride.cs | 38 +++++++++++++------ .../CuttingPlanning/JointCuttingPlanSearch.cs | 22 +++++------ .../CuttingGridHeatOrderTests.cs | 12 +++--- .../HeatOrderMeasurementTests.cs | 18 ++++----- docs/cutting-planner.md | 12 +++++- docs/plate-heat-map.md | 30 +++++++++------ 6 files changed, 79 insertions(+), 53 deletions(-) diff --git a/OpenNest.Engine/CuttingPlanning/CuttingGridStride.cs b/OpenNest.Engine/CuttingPlanning/CuttingGridStride.cs index b479816e..149804d5 100644 --- a/OpenNest.Engine/CuttingPlanning/CuttingGridStride.cs +++ b/OpenNest.Engine/CuttingPlanning/CuttingGridStride.cs @@ -17,29 +17,43 @@ internal readonly record struct GridStride(int Lines, int Parts) } /// -/// Prototype: a large grid's lines cut in strided passes so the sheet's heat is spread before -/// any line is cut beside a hot one. The passes become the plain order the heat start limit walks -/// (), which keeps the next pass piece when it starts under -/// the limit, raising the head over parts already cut. Measured only: is set -/// by a measurement harness; unset, the serpentine stands. +/// With a heat start limit, a large grid's lines are cut in strided passes so the sheet's heat is +/// spread before any line is cut beside a hot one, and a plate's lattice is cut apart from its +/// other parts. The passes become the plain order the limit walks +/// (, ), which +/// keeps the next pass piece when it starts under the limit, raising the head over parts already +/// cut. Without a limit the serpentine stands. See docs/plate-heat-map.md#grid-strides-and-clusters. /// internal static class CuttingGridStride { + /// + /// Every third line per pass: on a 0.12 in washer grid it cut the hottest part start by about a + /// third for about 1% more cut time; every other part as well cooled more but multiplied travel. + /// + internal static readonly GridStride Default = new(3, 1); + private static readonly System.Threading.AsyncLocal stride = new(); - private static readonly System.Threading.AsyncLocal clusters = new(); + private static readonly System.Threading.AsyncLocal clusters = new(); /// - /// The stride a measurement harness asks for, for its own flow of work only; null keeps the - /// serpentine. + /// A stride a measurement harness asks for in place of , for its own flow + /// of work only; (1, 1) is the serpentine. /// internal static GridStride? Override { get => stride.Value; set => stride.Value = value; } + /// The stride a heat-aware grid order cuts with. + internal static GridStride Current => Override ?? Default; + /// - /// Set by a measurement harness: with a heat start limit, split a plate into its lattice (the - /// parts of its most common size, when they form a grid) and the rest, cut as single parts, in - /// one heat walk (). + /// Whether, with a heat start limit, a plate is split into its lattice (the parts of its most + /// common size, when they form a grid) and the rest, cut as single parts, in one heat walk + /// (). On unless a measurement harness turns it off + /// for its own flow of work. /// - internal static bool Clusters { get => clusters.Value; set => clusters.Value = value; } + internal static bool Clusters => ClustersOverride ?? true; + + /// Set by a measurement harness to compare with the clusters on or off. + internal static bool? ClustersOverride { get => clusters.Value; set => clusters.Value = value; } /// /// The serpentine's (neighbors on the plate next to each other in the diff --git a/OpenNest.Engine/CuttingPlanning/JointCuttingPlanSearch.cs b/OpenNest.Engine/CuttingPlanning/JointCuttingPlanSearch.cs index 591e5cc6..5d1dad97 100644 --- a/OpenNest.Engine/CuttingPlanning/JointCuttingPlanSearch.cs +++ b/OpenNest.Engine/CuttingPlanning/JointCuttingPlanSearch.cs @@ -329,11 +329,11 @@ internal static class JointCuttingPlanSearch return null; if (snapshot.Heat == null) return lines.SelectMany(line => line).ToArray(); - // Prototype: a measured stride spreads the lines in passes (CuttingGridStride). - var stride = CuttingGridStride.Override; - var planned = stride is { IsPlain: false }; + // The stride spreads the lines in passes (CuttingGridStride). + var stride = CuttingGridStride.Current; + var planned = !stride.IsPlain; if (planned) - lines = CuttingGridStride.Pieces(lines, stride.Value); + lines = CuttingGridStride.Pieces(lines, stride); var (order, jumps, moved) = CuttingHeatOrder.PlanLines(lines, snapshot.StartPoint, HeatItems(snapshot, nesting), snapshot.Heat, token, planned); snapshot.HeatMoved = moved; @@ -342,10 +342,10 @@ internal static class JointCuttingPlanSearch return order; } - // Prototype (CuttingGridStride.Clusters): with a heat start limit, the parts of the plate's most - // common size, when they form a grid and other parts remain, are cut as lattice lines (strided - // by CuttingGridStride.Override) and the rest as single parts along their travel tour, all in - // one heat walk. Null when the plate has no such lattice, has cut-offs or nested parts outside + // With a heat start limit (CuttingGridStride.Clusters), the parts of the plate's most common + // size, when they form a grid and other parts remain, are cut as lattice lines (strided by + // CuttingGridStride.Current) and the rest as single parts along their travel tour, all in one + // heat walk, so odd parts do not decide whether the lattice gets the line order. Null when the plate has no such lattice, has cut-offs or nested parts outside // it, or a lattice part takes part in a required order. private static int[] ClusterOrder(CuttingPlanSnapshot snapshot, Box[] extents, HashSet[] prerequisites, CuttingNestedOrder.Context nesting, CancellationToken token) @@ -368,10 +368,10 @@ internal static class JointCuttingPlanSearch is not { } local) return null; var lines = local.Select(line => line.Select(index => lattice[index]).ToArray()).ToArray(); - var stride = CuttingGridStride.Override; - var planned = stride is { IsPlain: false }; + var stride = CuttingGridStride.Current; + var planned = !stride.IsPlain; if (planned) - lines = CuttingGridStride.Pieces(lines, stride.Value); + lines = CuttingGridStride.Pieces(lines, stride); var singles = TravelTour(snapshot, rest, snapshot.StartPoint, nesting).Select(part => new[] { part }); var (order, jumps, moved) = CuttingHeatOrder.PlanPieces([.. singles, .. lines], snapshot.StartPoint, HeatItems(snapshot, nesting), nesting.Prerequisites, snapshot.Heat, token, planned); diff --git a/OpenNest.Tests/CuttingPlanning/CuttingGridHeatOrderTests.cs b/OpenNest.Tests/CuttingPlanning/CuttingGridHeatOrderTests.cs index 6d9ec364..b520f8cb 100644 --- a/OpenNest.Tests/CuttingPlanning/CuttingGridHeatOrderTests.cs +++ b/OpenNest.Tests/CuttingPlanning/CuttingGridHeatOrderTests.cs @@ -151,18 +151,16 @@ public class CuttingGridHeatOrderTests CuttingPlanResult Plan() => CuttingPlanService.Plan(CuttingPlanRequest.ForPlate(MixedGrid(), Vector.Zero, confirmedParameters: parameters)); - var single = Plan(); - CuttingPlanResult clustered; - CuttingGridStride.Clusters = true; - CuttingGridStride.Override = new GridStride(3, 1); + var clustered = Plan(); + CuttingPlanResult single; + CuttingGridStride.ClustersOverride = false; try { - clustered = Plan(); + single = Plan(); } finally { - CuttingGridStride.Clusters = false; - CuttingGridStride.Override = null; + CuttingGridStride.ClustersOverride = null; } Assert.Equal(CuttingPlanStatus.Ready, clustered.Status); diff --git a/OpenNest.Tests/CuttingPlanning/HeatOrderMeasurementTests.cs b/OpenNest.Tests/CuttingPlanning/HeatOrderMeasurementTests.cs index d8076f84..dbd2afa9 100644 --- a/OpenNest.Tests/CuttingPlanning/HeatOrderMeasurementTests.cs +++ b/OpenNest.Tests/CuttingPlanning/HeatOrderMeasurementTests.cs @@ -15,8 +15,8 @@ namespace OpenNest.Tests.CuttingPlanning; /// travel, cut time and head raises. Opt-in: set OPENNEST_HEAT_PLATES to "path.nest:2;other.nest:1" /// (1-based plate numbers) and optionally OPENNEST_HEAT_LIMITS to "0,15,30" (°C, 0 = off). On a grid, /// OPENNEST_HEAT_STRIDES "1x1,3x1,3x2" compares strided orders (lines x parts, ; -/// 1x1 is the serpentine) and OPENNEST_HEAT_GRID_ONLY=1 keeps only the parts of the plate's most -/// common size. OPENNEST_HEAT_CLUSTERS "0,1" compares cutting the lattice apart from the other parts +/// 1x1 is the serpentine; default ) and OPENNEST_HEAT_GRID_ONLY=1 keeps only the parts of the plate's most +/// common size. OPENNEST_HEAT_CLUSTERS "0,1" compares cutting the lattice apart from the other parts (default 1) /// (). See docs/plate-heat-map.md#sequencing. /// [Trait("Category", "HeatOrder")] @@ -28,10 +28,10 @@ public class HeatOrderMeasurementTests(ITestOutputHelper output) var plates = Environment.GetEnvironmentVariable("OPENNEST_HEAT_PLATES"); Skip.If(string.IsNullOrWhiteSpace(plates), "Set OPENNEST_HEAT_PLATES to measure heat-aware plans."); var limits = Numbers("OPENNEST_HEAT_LIMITS", "0,15,20,30,45"); - var strides = (Environment.GetEnvironmentVariable("OPENNEST_HEAT_STRIDES") ?? "1x1") + var strides = (Environment.GetEnvironmentVariable("OPENNEST_HEAT_STRIDES") ?? CuttingGridStride.Default.ToString()) .Split(',', StringSplitOptions.RemoveEmptyEntries).Select(Stride).ToArray(); var gridOnly = Environment.GetEnvironmentVariable("OPENNEST_HEAT_GRID_ONLY") == "1"; - var clusterModes = (Environment.GetEnvironmentVariable("OPENNEST_HEAT_CLUSTERS") ?? "0") + var clusterModes = (Environment.GetEnvironmentVariable("OPENNEST_HEAT_CLUSTERS") ?? "1") .Split(',', StringSplitOptions.RemoveEmptyEntries).Select(v => v.Trim() == "1").ToArray(); foreach (var item in plates!.Split(';', StringSplitOptions.RemoveEmptyEntries)) { @@ -42,10 +42,10 @@ public class HeatOrderMeasurementTests(ITestOutputHelper output) foreach (var stride in strides) foreach (var limit in limits) { - if ((clusters || !stride.IsPlain) && limit == 0) - continue; // Both walk the heat rule; with the limit off the serpentine stands. - CuttingGridStride.Override = stride.IsPlain ? null : stride; - CuttingGridStride.Clusters = clusters; + if (limit == 0 && (clusters != clusterModes[0] || stride != strides[0])) + continue; // With the limit off the serpentine stands: measure it once. + CuttingGridStride.Override = stride; + CuttingGridStride.ClustersOverride = clusters; try { var line = $"[{(clusters ? "clusters " : "")}{stride}] " + Measure(path, number, limit, gridOnly); @@ -55,7 +55,7 @@ public class HeatOrderMeasurementTests(ITestOutputHelper output) finally { CuttingGridStride.Override = null; - CuttingGridStride.Clusters = false; + CuttingGridStride.ClustersOverride = null; } } } diff --git a/docs/cutting-planner.md b/docs/cutting-planner.md index 2e0a69e1..9e73aa3e 100644 --- a/docs/cutting-planner.md +++ b/docs/cutting-planner.md @@ -933,8 +933,16 @@ ready. after a learned order rule, the parts already cut count for the heat and for crossings. - Grids: the pieces are the serpentine's lines (`CuttingGridOrder.Lines`). Each keeps its parts in order and is cut from whichever end lies nearer the tool; only which line comes next - changes. The estimate keeps every part's heat. On a plate of washers this is every other line - out and the rest back, without being told. + changes. The estimate keeps every part's heat. The plain order is strided + (`CuttingGridStride.Default`): every third line per pass, the lines skipped filled on later + passes, passes alternating direction; its next line is taken across parts already cut, with a + heat jump, when it starts under the limit, since the stride itself is what spreads the heat. +- Lattices: on a plate whose most common part size forms a grid of at least 200 parts beside + other parts, the lattice's strided lines and the other parts, as single parts along their + travel tour, are pieces of one walk (`CuttingHeatOrder.PlanPieces`), so a few odd parts no + 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). 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 diff --git a/docs/plate-heat-map.md b/docs/plate-heat-map.md index 6fb54021..760cfcc4 100644 --- a/docs/plate-heat-map.md +++ b/docs/plate-heat-map.md @@ -188,7 +188,8 @@ when the cut reaches it, median / P90 in °C: Second sheets of the thin and 30-part nests matched their first. No plan gained a fallback head raise. On the grid the limit lowers every line's start from about 63 °C to 6 °C for about 1.5% -more travel: every other line out and the rest back fell out of the rule. The hottest zones fall +more travel: every other line out and the rest back fell out of the rule (measured before grids +were strided; see [grid strides and clusters](#grid-strides-and-clusters)). The hottest zones fall less (−6%), since the heat right behind the torch cannot be fixed by order. Thin sheets gain most; on them every neighbor of a part just cut is over a low limit, so the rule leaves the tour for about every other part, and higher limits do not always take fewer raises, since the parts @@ -197,20 +198,22 @@ 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. -### Grid strides and clusters (prototype) +### 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 -washers, 0.12 in mild steel, 20 °C limit) its line starts measure 7 °C but the median part starts -at 87 °C: the line runs into heat its neighbors left. Two measured-only switches try to fix it, -both off outside the harness, so plans are unchanged: +washers, 0.12 in mild steel, 20 °C limit) the rule alone, cutting the nearest line under the limit, +measured line starts of 7 °C but a median part start of 87 °C: each line ran into heat its +neighbors left. With a limit on, the planner now cuts: -- `CuttingGridStride.Override` (`OPENNEST_HEAT_STRIDES`, lines x parts) cuts every Nth line per - pass and fills the rest on later passes, passes alternating direction; with parts above 1, each - line's parts are split the same way. The strided order becomes the plain order the limit walks, - and its next piece is taken with a head raise across cut parts when it starts under the limit. -- `CuttingGridStride.Clusters` (`OPENNEST_HEAT_CLUSTERS=1`) cuts the parts of the plate's most - common size as lattice lines and every other part as single parts in the same heat walk, so a +- strided lines (`CuttingGridStride.Default`, every third line per pass, the rest filled on later + passes, passes alternating direction). The strided order is the plain order the limit walks; + its next piece is taken with a head raise across cut parts when it starts under the limit. + `OPENNEST_HEAT_STRIDES` (lines x parts; 1x1 is the serpentine, x2 also splits each line's + parts) compares others. +- the plate's lattice apart from its other parts (`CuttingGridStride.Clusters`): the parts of its + most common size as lattice lines, every other part as a single part, in one heat walk, so a plate whose odd parts break the whole-plate grid check still gets the line order. + `OPENNEST_HEAT_CLUSTERS=0` measures without it. `HeatOrderMeasurementTests` also reports every part's mean temperature when its cut starts (median / P90 / max, °C). Default timing as above: @@ -224,10 +227,13 @@ both off outside the harness, so plans are unchanged: | Every 3rd line | 20 °C | 73 / 86 / 102 | 185 | 888 | 2,734 s | 26 | | Every 4th line | 20 °C | 73 / 92 / 102 | 146 | 971 | 2,750 s | 31 | | Every 4th line, clusters | 20 °C | 71 / 86 / 104 | 160 | 958 | 2,748 s | 30 | +| Every 3rd line, clusters (the default) | 10 °C | 73 / 87 / 124 | 185 | 927 | 2,741 s | 29 | +| Every 3rd line, clusters (the default) | 20 °C | 74 / 89 / 102 | 185 | 891 | 2,734 s | 28 | | Every 3rd line, every other part | 20 °C | 19 / 39 / 169 | 142 | 3,987 | 3,353 s | 280 | Line strides of 3 or 4 cut the hottest part start by about a third for 1–2% more cut time; the -median stays near 73 °C because the parts of one line still heat each other. Splitting the lines +median stays near 73 °C because the parts of one line still heat each other. Every 3rd line is +the default for its smaller travel; every 4th cools the hottest zones more for about 8% more. Splitting the lines brings the median to 19 °C, but in the fill passes every part sits between parts already cut, so the search routes around them: travel rises almost fivefold (+24% cut time at the default 300 in/min rapid) and the jumps raise the head 280 times. Clusters match the whole-plate grid on this