简体   繁体   中英

Weight distribution in bucket such that minimum number of buckets are used

I have n weights that weight{A1,A2,...,An} and i have to divide then into buckets such that minimum number of buckets are required and each bucket has maximum capacity of Cmax and Ai<Cmax and size of each bucket should be as close to Cmax as possible Example:- I have weight {1,2,3,4,5} and Cmax= 5 So, result should be ({1,4},{2,3},{5})

{2,3,4,5} and Cmax=10
 So, result should be {{5,3,2},{4}} . 

other possible solution is {5,4},{3,2 } but this is not acceptable as. each initial set should be as much close to Cmax as possible

Sadly, this is NP-hard problem, so exact solution is guaranteed only with brute-force approach - checking all possible variants. It is possible for rather small problem size ( n, buckets < 10..15 ) - there are N^Buckets variants.

Otherwise (usually in case of n < 100 ) you can try some discrete optimization methods like Branch and bound algorithm (stop searching when current solution becomes worse than the best already found one)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM