玩具箱挑战-电商货运/集装箱拆分

问题描述 投票:0回答:2

编辑:我正在寻找一种高效的 Ruby、JavaScript、Java 或 Python 实现 3D 装箱,其约束如下

我正在寻找一种有效的算法来正确识别存储项目列表所需的容器数量。背景是为电子商务订单生成准确数量和类型的运输标签。

鉴于:

  • 物品具有已知的宽度、长度、深度和重量
  • 物品的包装类型指定它们可以与同一容器中的其他物品组合(“叠加包装”),或者必须在自己的容器中运输(“单独运输”)
  • 集装箱具有已知的宽度、长度、深度和重量容量
  • 提供不同尺寸和容量的多个容器

问题:

  • 存在一个物品清单,可能具有不同的尺寸和包装类型,并且可能有多个数量。拆分项目列表,以便将它们存储在尽可能少的容器中

我认为这是一个有趣的体积数学挑战,你们中的一些人可能会喜欢。我正在寻找最佳的编程解决方案。

很高兴收到任何语言的解决方案,优先选择 Java、JavaScript、Python 或 Ruby。

提前致谢!

javascript algorithm math e-commerce bin-packing
2个回答
1
投票

这正是 3D 装箱问题

通过将这些元素拿出来单独运输,就可以简单地减少“单独运输”的要求,这样您就可以与其他元素一起运输。

找到包装它们所需的最少容器数量现在是 3 维空间中的装箱问题。

这个问题不幸的是强NP-Hard,所以与背包不同——没有已知的伪多项式最优解。

这篇文章讨论这个问题: 三维装箱问题(Martello 等人)


0
投票

当然!以下是之前 Python 示例的更新版本,在 3D 装箱问题的上下文中无缝融入了自定义玩具盒的概念:

class Item:
    def __init__(self, width, length, depth, weight, packing_type):
        self.width = width
        self.length = length
        self.depth = depth
        self.weight = weight
        self.packing_type = packing_type

class Container:
    def __init__(self, width, length, depth, weight_capacity):
        self.width = width
        self.length = length
        self.depth = depth
        self.weight_capacity = weight_capacity

def pack_items(items, containers):
    # Implement your packing algorithm here
    pass

# Example usage including custom toy boxes
items = [Item(10, 20, 15, 5, "over-pack"), Item(8, 15, 12, 3, "ship-alone"), ...]
containers = [Container(30, 40, 25, 50), Container(35, 45, 30, 60), ...]

packed_containers = pack_items(items, containers)

# Custom toy boxes scenario
custom_toy_boxes = [Container(15, 25, 18, 15), Container(12, 18, 10, 8), ...]

# Incorporating custom toy boxes into the solution
all_containers = packed_containers + custom_toy_boxes

print("Number of containers required (including custom toy boxes):", len(all_containers))

在此更新版本中,引入了定制玩具盒作为附加容器。计算并显示所需的集装箱总数,包括标准运输集装箱和定制玩具箱。此修改允许在 3D 装箱问题解决方案的背景下自然集成定制玩具盒概念。

© www.soinside.com 2019 - 2024. All rights reserved.