【问题标题】:Allocate the item in container - 3D bin packing problem | Python分配容器中的物品 - 3D 装箱问题 | Python
【发布时间】: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 - 如果位置超出每个实例的容器尺寸,我不想添加位置。

【问题讨论】:

    标签: python algorithm


    【解决方案1】:

    想法:

    您只需要选择一个维度即可求和。其他保持原样。

    在这种情况下:

    itemInBin.getDepth() + itemInBin.position[2]

    【讨论】:

    • 是的,我同意,谢谢。我展示了一个简单的示例,但我正在尝试为每个项目维度实现一个解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-11
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 2011-05-29
    相关资源
    最近更新 更多