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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 protected override PackingPosition FindPositionForItem(BinPacking3D bp, PackingItem item, bool useStackingConstraints)
 {
     return(bp.FindExtremePointForItem(item, rotated: false, stackingConstraints: useStackingConstraints));
 }