- Rename Result to PackResult to avoid confusion with Result<T> - Add PackingRequest as immutable configuration replacing mutable engine state - Add PackingStrategy enum (AdvancedFit, BestFit, Exhaustive) - Implement pipeline pattern for composable packing steps - Rewrite AdvancedFitEngine as stateless using pipeline - Rewrite BestFitEngine as stateless - Add ExhaustiveFitEngine with symmetry breaking for optimal solutions - Tries all bin assignments to find minimum bins - Falls back to AdvancedFit for >20 items - Configurable threshold via constructor - Update IEngine/IEngineFactory interfaces for new pattern - Add strategy parameter to MCP tools Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
namespace CutList.Core.Nesting.Pipeline
|
|
{
|
|
/// <summary>
|
|
/// Implements the First-Fit Decreasing (FFD) bin packing algorithm.
|
|
/// Assumes items are already sorted by length descending.
|
|
/// Places each item in the first bin that has enough space.
|
|
/// </summary>
|
|
public class FirstFitDecreasingStep : IPackingStep
|
|
{
|
|
public void Execute(PackingContext context)
|
|
{
|
|
while (context.RemainingItems.Count > 0 && context.CanAddMoreBins())
|
|
{
|
|
var bin = context.CreateBin();
|
|
FillBin(bin, context.RemainingItems);
|
|
context.Bins.Add(bin);
|
|
}
|
|
}
|
|
|
|
private static void FillBin(Bin bin, List<BinItem> remainingItems)
|
|
{
|
|
for (int i = 0; i < remainingItems.Count; i++)
|
|
{
|
|
var item = remainingItems[i];
|
|
if (bin.RemainingLength >= item.Length)
|
|
{
|
|
bin.AddItem(item);
|
|
remainingItems.RemoveAt(i);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|