我试图找出一种算法,这将有助于我组大小不等到发言权的文件的分类,“N”近似相等大小的组。

这是如何实现这一目标的任何想法?

有帮助吗?

解决方案

Find the target group size. This is the sum of all sizes divided by n.
Create a list of sizes.
Sort the files decreasing in size. 
for each group
    while the remaining space in your group is bigger than the first element of the list
        take the first element of the list and move it to the group
    for each element
        find the elemnet for which the difference between group size and target group size is minimal
    move this elemnt to the group

这不会产生最佳结果,但很容易实现,并让你很好的效果。为最优解需要穷举搜索是NP完全。

其他提示

K均值可以帮助你。这是研究关于更先进的聚类算法一个很好的起点,但考虑到你的问题是一维的,K-手段应该是绰绰有余。

您隐含的优化目标是最有可能减少N,组数。然后,你必须完全装箱问题,有时也被称为的下料问题

入Netlib具有此 FORTRAN代码以解决更一般的多个背包问题(项目具有利润以及成本/重量值)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top