Ejemplo n.º 1
0
        public void TestInsertAndCount()
        {
            var box   = Factory.CreateBox("Box", 10, 10, 10, 0, 10, 10, 10, 100);
            var itemA = Factory.CreateItem("Item A", 5, 10, 10, 10, true);
            var itemB = Factory.CreateItem("Item B", 5, 10, 10, 20, true);

            var packedItemA = new PackedItem(itemA, 0, 0, 0, 5, 10, 10);
            var packedItemB = new PackedItem(itemB, 0, 0, 0, 5, 10, 10);

            var packedItemListA = new PackedItemList();

            packedItemListA.Insert(packedItemA);
            var packedBoxA = new PackedBox(box, packedItemListA);

            var packedItemListB = new PackedItemList();

            packedItemListB.Insert(packedItemB);
            var packedBoxB = new PackedBox(box, packedItemListB);

            var packedBoxList = new PackedBoxList();

            packedBoxList.Insert(packedBoxA);
            packedBoxList.Insert(packedBoxB);

            Assert.Equal(2, packedBoxList.Count);
        }
Ejemplo n.º 2
0
        public void TestTop()
        {
            var box   = Factory.CreateBox("Box", 10, 10, 10, 0, 10, 10, 10, 100);
            var itemA = Factory.CreateItem("Item A", 5, 10, 10, 10, true);
            var itemB = Factory.CreateItem("Item B", 5, 10, 10, 20, true);

            var packedItemA = new PackedItem(itemA, 0, 0, 0, 5, 10, 10);
            var packedItemB = new PackedItem(itemB, 0, 0, 0, 5, 10, 10);

            var packedItemListA = new PackedItemList();

            packedItemListA.Insert(packedItemA);
            var packedBoxA = new PackedBox(box, packedItemListA);

            var packedItemListB = new PackedItemList();

            packedItemListB.Insert(packedItemB);
            var packedBoxB = new PackedBox(box, packedItemListB);

            var pBoxArray = new PackedBox[] { packedBoxA, packedBoxB };

            var packedBoxList = new PackedBoxList();

            packedBoxList.Insert(packedBoxA);
            packedBoxList.Insert(packedBoxB);

            Assert.Equal(packedBoxA, packedBoxList.Top());
        }
Ejemplo n.º 3
0
        public void TestGetters()
        {
            var box   = Factory.CreateBox("Box", 370, 375, 60, 140, 364, 374, 40, 3000);
            var oItem = new OrientatedItem(
                Factory.CreateItem("Item", 230, 330, 6, 320, true),
                230,
                330,
                6
                );

            var packedItemList = new PackedItemList();

            packedItemList.Insert(PackedItem.FromOrientatedItem(oItem, 0, 0, 0));

            var pBox = new PackedBox(box, packedItemList);

            Assert.Equal(box.Reference, pBox.Box.Reference);
            Assert.Equal(460, pBox.TotalWeight);

            Assert.Equal(134, pBox.RemainingWidth);
            Assert.Equal(44, pBox.RemainingLength);
            Assert.Equal(34, pBox.RemainingDepth);

            Assert.Equal(2540, pBox.RemainingWeight);

            Assert.Equal(5445440, pBox.InnerVolume);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Generate a single list of items packed.
        /// </summary>
        /// <returns></returns>
        private PackedItemList GetPackedItemList()
        {
            var packedItemList = new PackedItemList();

            foreach (var layer in layers)
            {
                foreach (var packedItem in layer.Items)
                {
                    packedItemList.Insert(packedItem);
                }
            }

            return(packedItemList);
        }
Ejemplo n.º 5
0
        public void TestVolumeUtilisation()
        {
            var box  = Factory.CreateBox("Box", 10, 10, 10, 0, 10, 10, 10, 10);
            var item = Factory.CreateItem("Item", 5, 10, 10, 10, true);

            var packedItem = new PackedItem(item, 0, 0, 0, 5, 10, 10);

            var packedItemList = new PackedItemList();

            packedItemList.Insert(packedItem);
            var packedBox = new PackedBox(box, packedItemList);

            var packedBoxList = new PackedBoxList();

            packedBoxList.Insert(packedBox);

            Assert.Equal(50f, packedBoxList.GetVolumeUtilisation());
        }
Ejemplo n.º 6
0
        public OrientatedItem GetBestOrientation(
            Item item,
            OrientatedItem prevItem,
            ItemList nextItems,
            bool isLastItem,
            int widthLeft,
            int lengthLeft,
            int depthLeft,
            int rowLength,
            int x,
            int y,
            int z,
            PackedItemList prevPackedItemList
            )
        {
            var possibleOrientations = GetPossibleOrientations(item, prevItem, widthLeft, lengthLeft, depthLeft, x, y, z, prevPackedItemList);
            var usableOrientations   = GetUsableOrientations(item, possibleOrientations, isLastItem);

            if (usableOrientations.Count == 0)
            {
                return(null);
            }
            //TODO: VolumePackerTest.161 chtck here
            var comparer = new OrientatedItemsComparer(this)
            {
                widthLeft          = widthLeft,
                lengthLeft         = lengthLeft,
                depthLeft          = depthLeft,
                nextItems          = nextItems,
                rowLength          = rowLength,
                x                  = x,
                y                  = y,
                z                  = z,
                prevPackedItemList = prevPackedItemList,
            };

            usableOrientations.Sort(comparer);

            var bestFit = usableOrientations.First();

            return(bestFit);
        }
Ejemplo n.º 7
0
        public void TestVolumeUtilisation()
        {
            var box   = Factory.CreateBox("Box", 10, 10, 20, 10, 10, 10, 20, 10);
            var oItem = new OrientatedItem(
                Factory.CreateItem("Item", 4, 10, 10, 10, true),
                4,
                10,
                10
                );

            var packedItemList = new PackedItemList();

            packedItemList.Insert(PackedItem.FromOrientatedItem(oItem, 0, 0, 0));

            var pBox = new PackedBox(box, packedItemList);

            Assert.Equal(400, pBox.UsedVolume);
            Assert.Equal(1600, pBox.UnusedVolume);
            Assert.Equal(20, pBox.VolumeUtilizationPercent);
        }
Ejemplo n.º 8
0
        private OrientatedItem GetOrientationForItem(Item itemToPack,
                                                     PackedItem prevItem,
                                                     ItemList nextItems,
                                                     bool isLastItem,
                                                     int maxWidth,
                                                     int maxLength,
                                                     int maxDepth,
                                                     int rowLength,
                                                     int x,
                                                     int y,
                                                     int z
                                                     )
        {
            var prevOrientatedItem = prevItem?.ToOrientatedItem();

            // TODO: ConstrainedPlacementItem check implementation
            // don't calculate it if not going to be used
            var prevPackedItemList = new PackedItemList();

            var oifDecision = orientatedItemFactory.GetBestOrientation(
                itemToPack,
                prevOrientatedItem,
                nextItems,
                isLastItem,
                maxWidth,
                maxLength,
                maxDepth,
                rowLength,
                x,
                y,
                z,
                prevPackedItemList
                );

            return(oifDecision);
        }
Ejemplo n.º 9
0
        public List <OrientatedItem> GetPossibleOrientations(Item item,
                                                             OrientatedItem prevItem,
                                                             int widthLeft,
                                                             int lengthLeft,
                                                             int depthLeft,
                                                             int x,
                                                             int y,
                                                             int z,
                                                             PackedItemList prevPackedItemsList)
        {
            var orientations = new List <OrientatedItem>();

            if (prevItem != null && IsSameDimensions(prevItem.Item, item))
            {
                // Special case items that are the same as what we just packed - keep orientation
                orientations.Add(
                    new OrientatedItem()
                {
                    Item   = item,
                    Width  = prevItem.Width,
                    Length = prevItem.Length,
                    Depth  = prevItem.Depth
                }
                    );
            }
            else
            {
                // simple 2D rotation
                orientations.Add(
                    new OrientatedItem()
                {
                    Item   = item,
                    Width  = item.Width,
                    Length = item.Length,
                    Depth  = item.Depth
                }
                    );
                orientations.Add(
                    new OrientatedItem()
                {
                    Item   = item,
                    Width  = item.Length,
                    Length = item.Width,
                    Depth  = item.Depth
                }
                    );

                //add 3D rotation if we're allowed
                if (!item.KeepFlat)
                {
                    orientations.Add(
                        new OrientatedItem()
                    {
                        Item   = item,
                        Width  = item.Width,
                        Length = item.Depth,
                        Depth  = item.Length
                    }
                        );

                    orientations.Add(
                        new OrientatedItem()
                    {
                        Item   = item,
                        Width  = item.Length,
                        Length = item.Depth,
                        Depth  = item.Width
                    }
                        );

                    orientations.Add(
                        new OrientatedItem()
                    {
                        Item   = item,
                        Width  = item.Depth,
                        Length = item.Width,
                        Depth  = item.Length
                    }
                        );

                    orientations.Add(
                        new OrientatedItem()
                    {
                        Item   = item,
                        Width  = item.Depth,
                        Length = item.Length,
                        Depth  = item.Width
                    }
                        );
                }
            }

            // remove any that simply don't fit
            orientations = orientations.
                           Distinct().
                           Where(or => or.Width <= widthLeft && or.Length <= lengthLeft && or.Depth <= depthLeft).
                           ToList();

            // TODO: implement ConstrainedPlacementItem case

            return(orientations);
        }