다양한 크기의 파일을 대략 동일한 블록으로 그룹화하려면 알고리즘이 필요합니다.
-
13-09-2019 - |
문제
나는 다양한 크기의 파일을 대략 같은 크기의 '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가 완료된 철저한 검색이 필요합니다.
제휴하지 않습니다 StackOverflow