miC*_*inG 3 algorithm size grouping file np-complete
我正在试图找出一种算法,它可以帮助我将各种不同大小的文件分组成大小相等的'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
Run Code Online (Sandbox Code Playgroud)
这不会产生最佳结果,但易于实现并获得良好的结果.要获得最佳解决方案,您需要进行详尽的搜索,即NP完成.