protected override BinPacking3D CreatePacking( Solution partialSolution, ref IList <int> remainingIDs, IList <PackingItem> items, bool useStackingConstraints) { var bp = new BinPacking3D(partialSolution.BinShape); bp.ExtremePointBasedPacking(ref remainingIDs, items, useStackingConstraints); return(bp); }
public Solution Decode(Permutation permutation, PackingShape binShape, IList <PackingItem> items, bool useStackingConstraints) { Solution result = new Solution(binShape, useExtremePoints: true, stackingConstraints: useStackingConstraints); IList <int> remainingIDs = new List <int>(permutation); while (remainingIDs.Count > 0) { var bp = new BinPacking3D(binShape); bp.ExtremePointBasedPacking(ref remainingIDs, items, stackingConstraints: useStackingConstraints); result.Bins.Add(bp); } result.UpdateBinPackings(); return(result); }
public static Solution Apply(Permutation permutation, PackingShape binShape, IList <PackingItem> items, bool useStackingConstraints) { Solution result = new Solution(binShape, useExtremePoints: true, stackingConstraints: useStackingConstraints); IList <int> remainingIDs = new List <int>(permutation); var bpg = new BinPacking3D(binShape); bpg.ExtremePointBasedPacking(ref remainingIDs, items, stackingConstraints: useStackingConstraints); result.Bins.Add(bpg); foreach (int ID in remainingIDs) { var item = items[ID]; var points = GetResidualSpaceAllPoints(result, item); var sortedPoints = points.OrderBy(x => x.Item3); var packed = false; foreach (var p in sortedPoints) { packed = p.Item1.PackItemIfFeasible(ID, item, p.Item2, useStackingConstraints); if (packed) { break; } } if (!packed) { // pack item in a new bin var bp = new BinPacking3D(binShape); var positionFound = bp.FindExtremePointForItem(item, false, useStackingConstraints); if (positionFound != null) { bp.PackItem(ID, item, positionFound); } else { throw new InvalidOperationException("Item " + ID + " cannot be packed in an empty bin."); } result.Bins.Add(bp); } } result.UpdateBinPackings(); return(result); }
public static Solution Apply(Permutation permutation, PackingShape binShape, IList <PackingItem> items, bool useStackingConstraints) { Solution result = new Solution(binShape, useExtremePoints: true, stackingConstraints: useStackingConstraints); IList <int> remainingIDs = new List <int>(permutation); var bpg = new BinPacking3D(binShape); bpg.ExtremePointBasedPacking(ref remainingIDs, items, stackingConstraints: useStackingConstraints); result.Bins.Add(bpg); foreach (int ID in remainingIDs) { var sortedBins = result.Bins.OrderBy(x => x.FreeVolume); var item = items[ID]; var posFound = false; foreach (var bp in sortedBins) { var pos = bp.FindExtremePointForItem(item, false, useStackingConstraints); posFound = pos != null; if (posFound) { bp.PackItem(ID, item, pos); break; } } if (!posFound) { var bp = new BinPacking3D(binShape); var pos = bp.FindExtremePointForItem(item, false, useStackingConstraints); if (pos == null) { throw new InvalidOperationException("Item " + ID + " cannot be packed in empty bin."); } bp.PackItem(ID, item, pos); result.Bins.Add(bp); } } result.UpdateBinPackings(); return(result); }