tags:

views:

50

answers:

2

So I'm working on a fun little program and ran across this rather interesting problem: I have several sets of values of pre-defined set sizes. These are all a unique subset of a larger pool of values. The averages of each subset of numbers should be as close to each other as reasonably possible. This does not need to be perfect, but should be close enough that all sets are "balanced" against each other.

ex: {1,2,3,6,9,10,15,23,27} global mean: 10.66 needs to be sorted into 2 sets of 2 and one set of 5

acceptable result: {1,27}{2,23}{3,6,9,10}

In practice, the values will range between 60 and 200, and the sets will range from size 6 to 20.

I've tried a couple different algorithms, with various degrees of success, but I was interested in seeing what the good people at StackOverflow think.

My best, Zach

A: 

This sounds interesting. would love to know whats the practical application of this.

Just to be sure, guess you meant non intersecting subsets and sum of subsets be roughly equal (and not the averages)

Also, in the example I couldn't understand how you decided (for sure) to make 2 sets of 2 and one of 5.

I can think of a greedy sub optimal solution.

  1. Sort the numbers decreasing order order. (smaller numbers surprise less so deal them later)
  2. Decide on the number of sets you are going to have. not too sure about this
  3. Go through the set elements one by one and put them into the subset which has the lowest sum (round robin in case of equal sums)

This will not always give you the optimal solution though.

For 1,2,3,6,9,10,15,23,27 reversed: 27, 23, 15, 10, 09, 06, 03, 02, 01

27 3 2 1 = 33

23 09 = 30

15 10 06 = 31

neal aise
I'm coding a turn-based strategy space game I and my friends have been coding in our spare time. Each player starts in a galaxy consisting of 6 planets, with a central galaxy of (numPlayers)*4 planets. Each planet has several different randomly-generated attributes, but also has a 'value' attribute which measures the planets approximate value to a player. I want to balance the game when I generate the various galaxies, so that no player starts off in a superior galaxy. Thus, attempting to make the mean of each galaxies planet values as close to all the other starting galaxies is critical.
Zach H
okay so deciding the number of subsets is solved. its the number of players since each have one galaxy.looks like this algo should work for you. but i would suggest instead of that decide on the net worth of a value to be given to each of the players (you can make this value itself randomly generated)once that is done for each of the attribute generate a random quota from the remaining of the networth of value to be allocated.so you get random attributes, random total worth of galaxies to each of the player. and of course its equal worth to each of the player.
neal aise
@techle yup. Your comment points out a better strategy. I agree.
belisarius
+2  A: 

This reminds me of RubyQuiz #65, "Splitting the Loot". The major difference is that that problem was looking for splits that were exactly equal, instead of nearly equal. Maybe some of those solutions will help you.

AShelly
"splitting The Loot" is a very good example of what I'm trying to do. Another big difference between this and the current problem is that some of the gems are not assigned to a pirate, as an example, for 4 pirates, each will get 6 of 40 gems, leaving 16 gems unclaimed.
Zach H