1
$\begingroup$

I am facing the following combination problem :

I do have $B$ colored boxes, each one containing $N_b$ balls of the given color. The total number of balls is thus $\sum_{b=1}^{B} N_b = N$.

I want to distribute the balls to P players with the two following aims:

  • The number of balls received by each player must be the same (ie $N/P$)
  • The sum of the number of different colors hold by each player must be minimal : if each player get $c_p$ different colors, I want $\sum_{p=1}^{P} c_p$ as small as possible.

Is there any formulae or algorithm to respect both constraints ?

Edit

What is this problem useful ?

This problem arises eg in scientific computing : you have a available number of processus ($P$) and you want to perform arithmetics on several ($B$) arrays of different sizes ($N_b$). Obviously you want the arrays to be uniformly distributed (otherwise one process will have much more work and will slow the whole procedure), but you also want to minimize the splits in the original arrays since each one implies a communication between processus, which are also time consuming.

What to start with :

I guess we can easily fall back to the case of a distribution $\tilde D=\{\tilde N_1, \tilde N_2, ... \tilde N_{B}\}$ to distribute on P' players, with $P' \le P$ and $\tilde N_b < N/P$ : indeed, any boxe in the original distribution having more than $N/P$ ball will fill up 100% capacity of one (or more) player. We can then try to do pairs (or triplets, etc.) with the remaining boxes to reach N/P, but we may not have a perfect match without cuts in the general case.

$\endgroup$
4
  • $\begingroup$ You mean each player gets $N/P$ balls, don't you? $\endgroup$
    – saulspatz
    Commented Mar 20, 2020 at 14:04
  • $\begingroup$ You are right, but I think that as a new contributor I can't edit my post $\endgroup$
    – Juklaa
    Commented Mar 20, 2020 at 14:06
  • $\begingroup$ I edited it, but I think there's a row of buttons under your post that say, "share cite edit ...". $\endgroup$
    – saulspatz
    Commented Mar 20, 2020 at 14:08
  • $\begingroup$ Welcome to MSE. This is an interesting question, but you'll find you get a better response if you add some contest. Where does the problem arise, what have you tried so far, what are your thoughts? Please edit the question body to address these points. $\endgroup$
    – saulspatz
    Commented Mar 20, 2020 at 14:23

2 Answers 2

1
$\begingroup$

Well, it is easy to divide the balls such that $\displaystyle\sum_{p=1}^{P} c_p=B+P-1$. You first give out as many balls as you can from box $1$ to player $1$. Then if the box becomes empty, you give away from the next box. If some player receives $\frac{N}{P}$ balls, you move on to the next player.

In general cases, that's the best you can do. In the next section, I tweak this strategy slightly to get the optimal distribution.

The following is a recursive algorithm to find the distribution for given $D=\{N_1,N_2,...,N_B\}$:

  1. Find the minimum $k$ such that there exists subset $S$ of $D$ with sum $k\cdot\frac{N}{P}$.
  2. Give away the balls corresponding to $S$ to $k$ players.
  3. Repeat with $D$ replaced by $D-S$.

If this algorithm runs $t$ times, it is easy to see that $\displaystyle\sum_{p=1}^{P} c_p=B+P-t$. This is indeed the best possible.

$\endgroup$
4
  • $\begingroup$ Your original strategy is a reasonable one. Ideally no color that has less than $\frac NP$ balls would be divided between players. There may be a different ordering of the bins that will reduce the number of colors that get divided. The second version only looks at when you can come out even, not when you can reduce the number of colors that are split. I think the general problem is NP-hard as it is similar to knapsack, bin packing, stock cutting, etc. $\endgroup$ Commented Mar 20, 2020 at 19:44
  • $\begingroup$ @Ross Millikan, how can one reduce the number of "splits" without coming out even? Also, our goal is to reduce the number of "splits" and not the number of colors that are split. (Please forgive me if I am missing something obvious.) $\endgroup$
    – Anubhab
    Commented Mar 20, 2020 at 20:01
  • $\begingroup$ For example, imagine $\frac NP=5$ and you have a bunch of bins with $3$ and $4$. You can't find them that add up to $5$ as in your second approach, but splitting a $4$ into $2+2$ can give two bins with two colors each. If you started with one extra ball and the next bin had $3$ you would get a bin with $3$ colors. $\endgroup$ Commented Mar 20, 2020 at 20:08
  • $\begingroup$ @Ross Millikan, notice that $\displaystyle\sum_{p=1}^{P} c_p=B+s$ where $s$ is the number of "split"s in the colors. So, we aim to minimize the splits, and that won't happen, unless something evens out somewhere. So, even if I my strategy ends up giving $3$ colors to someone, in total, the number of splits would still be the same. $\endgroup$
    – Anubhab
    Commented Mar 20, 2020 at 20:26
0
$\begingroup$

You can solve the problem via integer linear programming as follows. Let nonnegative integer decision variable $x_{b,p}$ be the number of balls of color $b$ distributed to player $p$. Let binary decision variable $y_{b,p}$ indicate whether $x_{b,p}>0$. The problem is to minimize $\sum_{b,p} y_{b,p}$ subject to: \begin{align} \sum_p x_{b,p} &=N_b &&\text{for all $b$}\\ \sum_b x_{b,p} &=N/P &&\text{for all $p$}\\ x_{b,p} &\le M_{b,p} y_{b,p} &&\text{for all $b$ and $p$} \end{align} Here $M_{b,p}$ is a "big-M" constant upper bound on $x_{b,p}$. A good choice is $M_{b,p}=\min(N_b,N/P)$.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .