3dbinpacking
3dbinpacking copied to clipboard
Bin orientation makes difference in finding a solution
I've a very simple test case, where the algorithm can't fit all items. But when I change the orientation of the bin, it can fit all. Is this a bug or is the algorithm very limited and can't solve such a simple combination?
from py3dbp import Packer, Bin, Item
packer = Packer()
packer.add_bin(Bin('Bin-1', 6, 1, 5, 100))
packer.add_bin(Bin('Bin-2', 5, 1, 6, 100))
packer.add_item(Item('Box-1', 3, 1, 2, 1))
packer.add_item(Item('Box-2', 3, 1, 2, 1))
packer.add_item(Item('Box-3', 3, 1, 2, 1))
packer.add_item(Item('Box-4', 3, 1, 2, 1))
packer.add_item(Item('Box-5', 3, 1, 2, 1))
packer.pack()
for b in packer.bins:
print(":::::::::::", b.string())
print("FITTED ITEMS:")
for item in b.items:
print("====> ", item.string())
print("UNFITTED ITEMS:")
for item in b.unfitted_items:
print("====> ", item.string())
print("***************************************************")
print("***************************************************")
Result:
::::::::::: Bin-1(6.000x1.000x5.000, max_weight:100.000) vol(30.000)
FITTED ITEMS:
====> Box-1(3.000x1.000x2.000, weight: 1.000) pos([0, 0, 0]) rt(0) vol(6.000)
====> Box-2(3.000x1.000x2.000, weight: 1.000) pos([Decimal('3.000'), 0, 0]) rt(3) vol(6.000)
====> Box-3(3.000x1.000x2.000, weight: 1.000) pos([0, 0, Decimal('2.000')]) rt(0) vol(6.000)
====> Box-4(3.000x1.000x2.000, weight: 1.000) pos([Decimal('3.000'), 0, Decimal('3.000')]) rt(3) vol(6.000)
UNFITTED ITEMS:
====> Box-5(3.000x1.000x2.000, weight: 1.000) pos([0, 0, Decimal('4.000')]) rt(0) vol(6.000)
***************************************************
***************************************************
::::::::::: Bin-2(5.000x1.000x6.000, max_weight:100.000) vol(30.000)
FITTED ITEMS:
====> Box-1(3.000x1.000x2.000, weight: 1.000) pos([0, 0, 0]) rt(0) vol(6.000)
====> Box-2(3.000x1.000x2.000, weight: 1.000) pos([Decimal('3.000'), 0, 0]) rt(3) vol(6.000)
====> Box-3(3.000x1.000x2.000, weight: 1.000) pos([0, 0, Decimal('2.000')]) rt(0) vol(6.000)
====> Box-4(3.000x1.000x2.000, weight: 1.000) pos([Decimal('3.000'), 0, Decimal('3.000')]) rt(3) vol(6.000)
====> Box-5(3.000x1.000x2.000, weight: 1.000) pos([0, 0, Decimal('4.000')]) rt(0) vol(6.000)
UNFITTED ITEMS:
***************************************************
***************************************************
Ok, the so called "algorithm" is very basic.
But what at least is wrong, is the check if the item fits in the bin, as it doesn't takes the rotation of the item into account.
From example above, rotation of one of the items on X or Z axis will let the item stick out of the bin.