【发布时间】:2020-03-17 16:53:09
【问题描述】:
我正在寻找有关在 3D Bin 包装问题中将物品放置在容器中的建议或想法。我正在使用 [x, y, z] 位置检查项目是否适合容器。我的目标是尽可能放置物品。如果不可能,我会将项目放在 unpacked 列表中。下面是我的一段代码:
for item in self.items:
for itemInBin in binn.items:
positionToPlace= [itemInBin.position[0] + itemInBin.getWidth(), itemInBin.getHeight() + itemInBin.position[1], itemInBin.getDepth() + itemInBin.position[2]]
if positionToPlace[0] <= binn.getWidth() or positionToPlace[1] <= binn.getHeight() or positionToPlace[2] <= binn.getDepth(): # do not exceed the dimensions of the container
binn.putItem(item, positionToPlace)
else:
unpacked.append(item)
对于测试数据:
- 容器 = [20, 20, 8]
- 项目 1 = [20, 20, 2]
- 项目 2 = [20, 20, 2]
- 项目 3 = [20, 20, 2]
- 项目 4 = [20, 20, 2]
- 项目 5 = [20, 20, 2]
前四个项目应该被打包到 Container 中,一个项目进入 unpacked 数组。使用位置应该看起来像 [20, 20, 8],但对于我来说是 [80, 80, 8]。我试图分配项目的当前位置,如果它超出容器尺寸,则不指定其宽度、高度或深度,但这是错误的想法。
如果可能的话,我正在考虑精确分配项目的“if 语句”或函数。这意味着它将在 X、Y 或 Z 轴上可用。我知道此时我的解决方案非常糟糕,但我想向您展示一些东西。 在其他功能中,我正在旋转项目以最佳放置它,它似乎工作正常。
请帮助我处理 positionToPlace - 如果位置超出每个实例的容器尺寸,我不想添加位置。
【问题讨论】: