feat(cutting): route around tabbed parts before passing over them

A tabbed part stays in the sheet, so rapids were free to pass over it and
the planner never looked for a way around. Plan Cutting now searches first
with every tabbed outside as an obstacle once its part is cut. Where a pass
stalls at a part whose approach crosses a tabbed part, only the crossed
parts become crossable and the search goes on along the same order. A
capture that search cannot plan is planned as before. Plates without
tabbed outsides are searched once, unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Fable 5.2 committed 2026-11-16 20:00:50 -05:00
1 parent a84f8d1298
commit 92bf653c8f
9 files changed
+305 -16

No files matched your search

@@ -265,9 +265,11 @@ public sealed class CuttingPlanBatch
// A replayed proposal whose only warnings are fixed emissions passed every strict
// check; fixed emissions never steer the search, so the full pass cannot improve it.
// A plan keeping tab lead-outs is not taken from the short pass: the full pass may
// still find a clean route.
// still find a clean route. Nor is one that passes over tabbed parts: the full pass
// may still find a route around them.
if (first.IndependentlyReplayed && first.Status is CuttingPlanStatus.Ready or CuttingPlanStatus.BestEffort
&& !first.Findings.Any(f => f.Kind == PostVerificationKind.TabLeadOut)
&& (first.Snapshot is { AvoidsTabbedParts: true, CrossableTabbedParts.Count: 0 } || !snapshot.HasTabbedParts)
|| first.Status == CuttingPlanStatus.Canceled)
return first;
}
@@ -91,10 +91,51 @@ public sealed class CuttingPlanSnapshot
/// <summary>
/// An empty rapid checker for this capture. A tabbed part counts as steady once cut, so
/// rapids may cross it as its retained material allows.
/// rapids may cross it as its retained material allows; with <see cref="AvoidsTabbedParts"/>
/// its outside is an obstacle all the same.
/// </summary>
internal ReleasedContourState NewReleasedState() =>
new(reportMissingLeadIns: false, null, CommonLineMembers.Count == 0 ? null : CommonLineMembers.Contains);
new(reportMissingLeadIns: false, null, CommonLineMembers.Count == 0 ? null : CommonLineMembers.Contains)
{
AvoidTabbedPart = AvoidsTabbedParts ? part => !CrossableTabbedParts.Contains(part) : null,
};
/// <summary>
/// Whether rapids keep off tabbed parts already cut, as they do off parts cut free. Planning
/// tries this first (<see cref="WithTabbedPartsAvoided"/>) and lets rapids cross only the
/// tabbed parts it finds no way around (<see cref="CrossableTabbedParts"/>).
/// </summary>
internal bool AvoidsTabbedParts { get; init; }
/// <summary>
/// With <see cref="AvoidsTabbedParts"/>, the part numbers (source ordinal + 1) of the tabbed
/// parts rapids may still pass over. The one search planning this capture adds the parts it
/// finds no route around (<see cref="AllowCrossing"/>); its checkers, cut-off placement and the
/// replay of its plan all read this same set. Nothing else may change it.
/// </summary>
internal HashSet<int> CrossableTabbedParts { get; init; } = [];
/// <summary>
/// Lets rapids pass over tabbed part <paramref name="partNumber"/> from here on. False when
/// this capture does not avoid tabbed parts or the part was crossable already.
/// </summary>
internal bool AllowCrossing(int partNumber) => AvoidsTabbedParts && CrossableTabbedParts.Add(partNumber);
/// <summary>Whether any regenerated part's outside is tabbed, so avoiding tabbed parts changes the search.</summary>
internal bool HasTabbedParts => Placements.Any(placement => placement.Prepared is { PerimeterTabbed: true });
/// <summary>The same capture planned with rapids kept off tabbed parts already cut.</summary>
internal CuttingPlanSnapshot WithTabbedPartsAvoided() =>
new(Placements, StartPoint, ExpansionBudget, Failure, Findings, Regeneration,
PreservePartOrder, MaxEntries, ExpansionObserver, PlateState, OwnedParameters,
Dependencies, BestEffort)
{
SupportTabsSkipped = SupportTabsSkipped,
CommonLineMembers = CommonLineMembers,
CommonLineOrder = CommonLineOrder,
AcceptsTabLeadOuts = AcceptsTabLeadOuts,
AvoidsTabbedParts = true,
};
/// <summary>
/// Part numbers (source ordinal + 1) of the members of common-line groups cut once
@@ -146,6 +187,8 @@ public sealed class CuttingPlanSnapshot
CommonLineMembers = CommonLineMembers,
CommonLineOrder = CommonLineOrder,
AcceptsTabLeadOuts = AcceptsTabLeadOuts,
AvoidsTabbedParts = AvoidsTabbedParts,
CrossableTabbedParts = [.. CrossableTabbedParts],
};
/// <summary>
@@ -162,6 +205,8 @@ public sealed class CuttingPlanSnapshot
CommonLineMembers = CommonLineMembers,
CommonLineOrder = CommonLineOrder,
AcceptsTabLeadOuts = true,
AvoidsTabbedParts = AvoidsTabbedParts,
CrossableTabbedParts = [.. CrossableTabbedParts],
};
/// <summary>Whether this capture accepts tab lead-outs (see <see cref="WithTabLeadOuts"/>).</summary>
@@ -180,6 +225,8 @@ public sealed class CuttingPlanSnapshot
CommonLineMembers = CommonLineMembers,
CommonLineOrder = CommonLineOrder,
AcceptsTabLeadOuts = AcceptsTabLeadOuts,
AvoidsTabbedParts = AvoidsTabbedParts,
CrossableTabbedParts = [.. CrossableTabbedParts],
};
}
@@ -290,6 +290,22 @@ public static class CuttingPlanService
/// <summary>Worker-only planning uses owned values; live identities are never dereferenced.</summary>
public static CuttingPlanResult Plan(CuttingPlanSnapshot snapshot, CancellationToken token = default)
{
// A tabbed part stays in the sheet and may be passed over, but a route around it is safer:
// look for one first, with tabbed parts as obstacles, and cross them only without it.
// Where the search finds no way around one, that part alone becomes crossable and the
// search goes on, so a boxed-in part does not give up the rest. A plan it still cannot
// find is searched for as before, with every tabbed part crossable.
if (snapshot is { AvoidsTabbedParts: false, Regeneration: true, BestEffort: false, Failure: null, HasTabbedParts: true })
{
var avoiding = snapshot.WithTabbedPartsAvoided();
var clear = PlanCaptured(avoiding, token);
if (clear.IndependentlyReplayed && clear.Status is CuttingPlanStatus.Ready or CuttingPlanStatus.BestEffort
|| clear.Status == CuttingPlanStatus.Canceled)
{
clear.Snapshot = avoiding;
return clear;
}
}
var result = PlanCaptured(snapshot, token);
result.Snapshot = snapshot;
// Refused only for configured lead-outs that may cut their tabs free: plan again keeping
@@ -94,16 +94,36 @@ internal static class JointCuttingPlanSearch
if (snapshot.PreservePartOrder)
{
var keptSequence = Enumerable.Range(0, count).ToArray();
if (preferEndpoints)
// The order is fixed, so a tabbed part an approach cannot get around is passed over:
// each pass that stops at one goes on from there with that part crossable.
Node keptResume = null;
while (true)
{
var preferred = walk.Follow(keptSequence, stall, null, preferredOnly: true);
if (preferred.Order != null)
return walk.Ready(preferred.Order);
var recovered = walk.Follow(keptSequence, stall, null, contourRecovery: true);
if (recovered.Order != null)
return walk.Ready(recovered.Order);
var stopped = new List<Attempt>();
if (preferEndpoints)
{
var preferred = walk.Follow(keptSequence, stall, keptResume, preferredOnly: true);
if (preferred.Order != null)
return walk.Ready(preferred.Order);
var recovered = walk.Follow(keptSequence, stall, keptResume, contourRecovery: true);
if (recovered.Order != null)
return walk.Ready(recovered.Order);
stopped.AddRange([preferred, recovered]);
}
else
{
// The full pass below never stalls; this one only finds where a tabbed part blocks.
var plain = snapshot.AvoidsTabbedParts ? walk.Follow(keptSequence, stall, keptResume) : null;
if (plain?.Order != null)
return walk.Ready(plain.Order);
if (plain != null)
stopped.Add(plain);
}
if (PassOver(snapshot, stopped) is not { } onward)
break;
keptResume = onward;
}
var kept = walk.Follow(keptSequence, null, null, expansionLimit: FallbackLimit());
var kept = walk.Follow(keptSequence, null, keptResume, expansionLimit: FallbackLimit());
return kept.Order != null ? walk.Ready(kept.Order) : walk.Exhausted();
}
@@ -129,6 +149,7 @@ internal static class JointCuttingPlanSearch
// A pass that teaches an order rule ends the round: the heavier passes would
// only repeat the same blocked approach along the same order.
Attempt attempt = null;
Node onward = null;
foreach (var (preferredOnly, contourRecovery) in preferEndpoints
? new[] { (true, false), (false, true), (false, false) }
: doorAlone ? [(false, true), (false, false)] : [(false, false)])
@@ -136,12 +157,24 @@ internal static class JointCuttingPlanSearch
var pass = walk.Follow(sequence, stall, resume, preferredOnly, contourRecovery, prerequisites);
if (pass.Order != null)
return walk.Ready(pass.Order);
// Stopped at a tabbed part still avoided, after trying the entries that might
// clear it: pass over it and go on from there along the same order. It teaches
// no order rule, and the heavier passes are not tried first: on a plate of
// tabbed parts either costs far more search than it saves crossings.
onward = PassOver(snapshot, [pass]);
if (onward != null)
break;
if (Learn(pass, sequence, prerequisites, revoked, swaps))
{
attempt = pass;
break;
}
}
if (onward != null)
{
resume = onward;
continue;
}
// Nothing new to learn after a swap: take back the newest swap and learn the plain
// rule its attempt would have taught instead, backing up from that attempt.
while (attempt == null && swaps.Count != 0)
@@ -232,6 +265,29 @@ internal static class JointCuttingPlanSearch
}, token, exits);
}
// Whether the pass stopped at a part whose approach crossed a tabbed part the capture still
// avoids (see CuttingPlanSnapshot.AvoidsTabbedParts).
private static bool StoppedAtTabbed(CuttingPlanSnapshot snapshot, Attempt pass) =>
snapshot.AvoidsTabbedParts && pass.Blocked != null
&& pass.CrossedTabbed.Any(part => !snapshot.CrossableTabbedParts.Contains(part + 1));
// Lets rapids pass over the tabbed parts still avoided that the heaviest of these stopped
// passes crossed on its blocked approach. Returns the part boundary that pass was blocked at,
// to go on from; null when no pass stopped at a tabbed part still avoided.
private static Node PassOver(CuttingPlanSnapshot snapshot, IReadOnlyList<Attempt> stopped)
{
for (var index = stopped.Count - 1; index >= 0; index--)
{
var pass = stopped[index];
if (!StoppedAtTabbed(snapshot, pass))
continue;
foreach (var part in pass.CrossedTabbed.Order())
snapshot.AllowCrossing(part + 1);
return pass.Boundary;
}
return null;
}
// When the approach crossed the part cut just before the one it left from, and no part but
// those two, the tool went on past that part and came back across it: "cut those two the
// other way round", so the tool leaves from the nearer one (two stacked strips, cut far one
@@ -1791,6 +1847,15 @@ internal static class JointCuttingPlanSearch
/// <summary>Parts whose completed contours the blocked part's motions crossed (it can be among them).</summary>
internal HashSet<int> Crossed { get; } = [];
/// <summary>
/// The parts among <see cref="Crossed"/> whose tabbed outside was crossed while tabbed parts
/// are avoided (<see cref="ReleasedContourState.AvoidedTabbedPart"/>).
/// </summary>
internal HashSet<int> CrossedTabbed { get; } = [];
/// <summary>The deepest whole-part boundary reached, where the blocked part's approach starts.</summary>
internal Node Boundary => Deepest;
// Records a node that gets further along the order than any before. True when it does.
internal bool Advance(Node node)
{
@@ -1802,6 +1867,7 @@ internal static class JointCuttingPlanSearch
{
Deepest = node;
Crossed.Clear();
CrossedTabbed.Clear();
}
return true;
}
@@ -1811,6 +1877,7 @@ internal static class JointCuttingPlanSearch
progress = -1;
Deepest = null;
Crossed.Clear();
CrossedTabbed.Clear();
}
internal void NoteCrossings(int ordinal, IEnumerable<PostVerificationFinding> findings)
@@ -1819,7 +1886,11 @@ internal static class JointCuttingPlanSearch
return;
foreach (var finding in findings)
if (finding.Kind == PostVerificationKind.RapidCrossing && finding.OtherPartNumber is int other)
{
Crossed.Add(other - 1);
if (ReleasedContourState.AvoidedTabbedPart(finding) != null)
CrossedTabbed.Add(other - 1);
}
}
/// <summary>The part boundary at <paramref name="depth"/> on the way to the deepest one.</summary>