42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from py3dbp import Packer, Bin, Item
|
|
|
|
class PalletPacker:
|
|
def __init__(self, pallet: dict, box: dict):
|
|
self.pallet_width = pallet.get('x', 1.2)
|
|
self.pallet_height = pallet.get('y', 0.8)
|
|
self.pallet_depth = pallet.get('z', 0.144)
|
|
|
|
self.box_width = box.get('x', 0.2)
|
|
self.box_height = box.get('y', 0.2)
|
|
self.box_depth = box.get('z', 0.2)
|
|
|
|
def pack(self):
|
|
# Создаем контейнер (паллета)
|
|
pallet = Bin('pallet', self.pallet_width, self.pallet_height, self.box_depth, self.pallet_width)
|
|
|
|
# Создаем пакер
|
|
packer = Packer()
|
|
|
|
# Вычисляем, сколько коробок поместится на паллете в один слой
|
|
num_boxes_x = self.pallet_width // self.box_width
|
|
num_boxes_y = self.pallet_height // self.box_height
|
|
num_boxes = int(num_boxes_x * num_boxes_y)
|
|
|
|
# Добавляем коробки в пакер
|
|
for i in range(num_boxes):
|
|
packer.add_item(Item(f'box{i}', self.box_width, self.box_height, self.box_depth, 1))
|
|
|
|
# Добавляем контейнер в пакер
|
|
packer.add_bin(pallet)
|
|
|
|
# Упаковываем коробки
|
|
packer.pack()
|
|
|
|
# Получаем результат
|
|
coordinates = []
|
|
for b in packer.bins:
|
|
for item in b.items:
|
|
coordinates.append((item.position, item.width, item.height, item.depth))
|
|
|
|
return coordinates
|