tags:

views:

74

answers:

1

I want to distribute x(i) objects (x E {1...n}), where each object has weight w(i), into n portions. The distribution should be done in such a way, that for all the portions the sum of weights is as equal as possible.

Cheers! Pratik

+6  A: 

Calculate the total sum of the weights, divide by n the number of portions to get the required portion weight. Then use a bin packing algorithm (http://en.wikipedia.org/wiki/Bin%5Fpacking%5Fproblem) to try and fill n bins of this maximum size.

Note that all weights need to be less than the portion weight for this to work properly. Otherwise you won't be able to place the large weighted items anywhere.

pjp
a bit of preprocessing will take care of the corner case - find the required portion weight, remove any weights that are greater than the portion and put them into bins of their own, then run the bin packing algorithm for the remaining n-k weights and n-k bins.
Martin DeMello