是否有适用于此的 Bin 打包算法的变体?

Is there a variant of the Bin packing algorithm which is applicable here?

假设您正在用物品堆放一个板条箱,板条箱中的每件物品的尺寸都相同,物品不能倾倒,所以所有物品都是直立的,物品都在一层。

现在我的目标是拥有一个板条箱 select 或者用户在采购订单中输入项目和项目数量并在 return 中收到一份报告,告诉用户要使用哪个板条箱select 打包物品。

例如

Input: 
    24 x Item 199111
Output:
    Option 1: 2 x crate #1 with 12 item 199111 per crate
    Option 2: 1 x Crate #3 with 24 item 199111 per crate 

我目前已经用这些表创建了一个 Microsoft Access 数据库

我还有一个表单,用户可以在创建新项目时添加它们。 我们只有 30 种箱子尺寸和 200 种物品可供选择。

我的问题是我可以使用哪些访问工具或我可以阅读的任何书籍来实现此目的。我的主要困难是检查每个板条箱中可以装多少件物品。

我将使用基于 public 函数的计算字段查询。访问查询设计者可以使用 public 可用的功能。因此,我们可以创建函数来处理围绕我们需要多少个创建以及每个组合项目数量、包装安排和板条箱类型的这些板条箱的总成本的数学。

计算的变量详细信息以及调用 public 函数的位置

CratesNeeded: CratesNeededforOrder([tblItemInfo]![ItemLength],[tblItemInfo]![ItemWidth],[tblCrateInfo]![CrateLength],[tblCrateInfo]![CrateWidth],[tblOrderInfo]![ItemQuantity])

Cost: Cost([ItemLength],[ItemWidth],[CrateLength],[CrateWidth],[ItemQuantity],[CrateCost])

注意计算字段 CratesNeeded 在一行中可以访问该行的 ItemLength 值。

要添加 public 数据库功能,请转到功能区的设计选项卡并添加代码模块,通常在最右侧。然后在代码模块中添加public函数:

'assume all items have an approximating rectangle and all items packed with the same orientation so crate length is divided by either item length or item width giving us only two packing arrangements
Public Function AtLeast1ItemFitsintoCrate(itemlength As Double, itemwidth As Double, cratelength As Double, cratewidth As Double) As Boolean
Dim temp As Double 'make sure length is equal or larger than width
If itemwidth > itemlength Then
temp = itemlength
itemlength = itemwidth
itemwidth = temp
End If
If cratewidth > cratelength Then
temp = cratelength
cratelength = cratewidth
cratewidth = temp
End If
If (itemlength <= cratelength) And (itemwidth <= cratewidth) Then
AtLeast1ItemFitsintoCrate = True
Else
AtLeast1ItemFitsintoCrate = False
End If
End Function
Public Function HowManyitemsWillFitinCrate(itemlength As Double, itemwidth As Double, cratelength As Double, cratewidth As Double) As Integer
Dim itemsinpackingarrangement1 As Integer
Dim itemsinpackingarrangement2 As Integer
itemsinpackingarrangement1 = CInt(cratelength / itemlength) * CInt(cratewidth / itemwidth)
itemsinpackingarrangement2 = CInt(cratelength / itemwidth) * CInt(cratewidth / itemlength)
If itemsinpackingarrangement1 > itemsinpackingarrangement2 Then
HowManyitemsWillFitinCrate = itemsinpackingarrangement1
Else
HowManyitemsWillFitinCrate = itemsinpackingarrangement2
End If
End Function
Public Function CratesNeededforOrder(itemlength As Double, itemwidth As Double, cratelength As Double, cratewidth As Double, itemquantity As Integer) As Integer
Dim itemspercrate As Integer
itemspercrate = HowManyitemsWillFitinCrate(itemlength, itemwidth, cratelength, cratewidth)
CratesNeededforOrder = Ceiling(itemquantity / itemspercrate)
End Function
Public Function Cost(itemlength As Double, itemwidth As Double, cratelength As Double, cratewidth As Double, itemquantity As Integer, cratecost As Currency) As Currency
'found technical annoyance that functions used in queries must avoid passing calculated fields as parameters, cratequantity must be calculated here when used for queries
Dim cratequantity As Integer
cratequantity = CratesNeededforOrder(itemlength, itemwidth, cratelength, cratewidth, itemquantity)
Cost = cratequantity * cratecost
End Function
Public Function Ceiling(number As Double) As Integer
Ceiling = -Int(-number)
End Function

我忘记按 AtLeast1ItemFitsintoCrate 过滤查询,所以我把它留作练习。当您获得更好的包装模型时,您可以修改支持成本函数的函数。通过枚举所有可能的情况并按成本排序来处理最小化。