fix: resolve infinite loop in multi-plate autonest and wire into console

- Change while(true) to bounded for-loop (max 100 plates) in MainForm
- Use Drawing.Name comparison instead of reference equality for quantity deduction
- Add Math.Max(0, ...) guard to prevent negative quantities
- Tune SA parameters for faster convergence (cooling=0.995, minTemp=0.1, maxNoImprove=500)
- Add --autonest flag to OpenNest.Console for CLI-based NFP autonesting

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 08:29:02 -04:00
parent 3f3b07ef5d
commit 2632b3dbf7
3 changed files with 46 additions and 12 deletions
+7 -5
View File
@@ -680,8 +680,9 @@ namespace OpenNest.Forms
return;
var items = form.GetNestItems();
var maxPlates = 100;
while (true)
for (var plateCount = 0; plateCount < maxPlates; plateCount++)
{
var remaining = items.Where(i => i.Quantity > 0).ToList();
@@ -698,14 +699,15 @@ namespace OpenNest.Forms
break;
plate.Parts.AddRange(parts);
activeForm.Nest.UpdateDrawingQuantities();
// Reduce remaining quantities by how many were placed per drawing.
// Deduct placed quantities using Drawing.Name to avoid reference issues.
foreach (var item in remaining)
{
var placed = parts.Count(p => p.BaseDrawing == item.Drawing);
item.Quantity -= placed;
var placed = parts.Count(p => p.BaseDrawing.Name == item.Drawing.Name);
item.Quantity = System.Math.Max(0, item.Quantity - placed);
}
activeForm.Nest.UpdateDrawingQuantities();
}
}