protected BinPacking3D(BinPacking3D original, Cloner cloner)
     : base(original, cloner)
 {
     this.ResidualSpace = new Dictionary <PackingPosition, Tuple <int, int, int> >();
     foreach (var o in original.ResidualSpace)
     {
         this.ResidualSpace.Add(cloner.Clone(o.Key), Tuple.Create(o.Value.Item1, o.Value.Item2, o.Value.Item3));
     }
 }
Exemple #2
0
        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);
        }
Exemple #5
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);
        }
Exemple #6
0
 protected override PackingPosition FindPositionForItem(BinPacking3D bp, PackingItem item, bool useStackingConstraints)
 {
     return(bp.FindExtremePointForItem(item, rotated: false, stackingConstraints: useStackingConstraints));
 }
 protected override PackingPosition FindPositionForItem(BinPacking3D bp, PackingItem item, bool useStackingConstraints)
 {
     return(bp.FindPositionBySliding(item, rotated: false));
 }
 protected abstract PackingPosition FindPositionForItem(BinPacking3D bp, PackingItem item, bool useStackingConstraints);
 protected BinPacking3D(BinPacking3D original, Cloner cloner)
     : base(original, cloner)
 {
     this.ExtremePoints = new SortedSet <PackingPosition>(original.ExtremePoints.Select(p => cloner.Clone(p)));
 }