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); }
public void TestZeroDepth() { var orientedItem = new OrientatedItem( Factory.CreateItem("Item", 1, 1, 0, 0, false), 1, 1, 0 ); var tippingPoint = orientedItem.GetTippingPoint(); }
public OrientatedItem ToOrientatedItem() { var result = new OrientatedItem() { Item = this.Item, Width = this.Width, Length = this.Length, Depth = this.Depth, }; return(result); }
public static PackedItem FromOrientatedItem(OrientatedItem oi, int x, int y, int z) { return(new PackedItem() { Item = oi.Item, Width = oi.Width, Length = oi.Length, Depth = oi.Depth, X = x, Y = y, Z = z, }); }
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); }
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); }
protected int CalculateAdditionalItemsPackedWithThisOrientation(OrientatedItem prevItem, ItemList nextItems, int originalWidthLeft, int originalLengthLeft, int depthLeft, int currentRowLengthBeforePacking) { var currentRowLength = Math.Max(prevItem.Length, currentRowLengthBeforePacking); // cap lookahead as this gets recursive and slow var itemsToPack = nextItems.TopN(8); var tempBox = new WorkingVolume(originalWidthLeft - prevItem.Width, currentRowLength, depthLeft, int.MaxValue); var tempPacker = new VolumePacker(tempBox, itemsToPack.Clone()); tempPacker.LookAheadMode = true; var remainigRowPacked = tempPacker.Pack(); foreach (var packedItem in remainigRowPacked.PackedItems) { itemsToPack.Remove(packedItem.Item); } var tempBox2 = new WorkingVolume(originalWidthLeft, originalLengthLeft - currentRowLength, depthLeft, int.MaxValue); var tempPacker2 = new VolumePacker(tempBox2, itemsToPack.Clone()); tempPacker2.LookAheadMode = true; var nextRowPacked = tempPacker2.Pack(); foreach (var packedItem in nextRowPacked.PackedItems) { itemsToPack.Remove(packedItem.Item); } return(nextItems.Count() - itemsToPack.Count()); }
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); }