1

I have a problem, which appears to be similar to number partitioning: a set of numbers partitioned (two-way), such that the sum of the numbers in each subset are as close as possible to a targeted ratio (instead of having the minimum difference, as in the number partitioning problem). Can I use the same algorithms? How would I modify them? Is another approach more suitable?

Context:

I am implementing a load-balancing algorithm, for a work conserving Group Weighted Round Robin (GWRR) scheduler. In some corner-case (some groups have less tasks than CPUs in the system), I want to partition the weighted groups and assign them to the subsets of a partitioning of the set of CPUs, so that the ratio of the sums of (predicted) CPU idle times, in the subsets of the CPU partition, is as close as possible to the ratio of the weight sums, in the subsets of the group partition. The group partition splits the groups, using a normal number partitioning algorithm (CKK), so that group weight sums, in each subset, have the minimum possible difference (but they are unlikely to match, in the general case).

Any ideas?

kavadias
  • 113
  • 5
  • It appears, there is a variant of the problem I am trying to solve, which has been studied, but it is not what I want. The Factor–r Sum Subsets or Subset-Sums Ratio problem, tries to derive two subsets with a target sum ratio, but does not require that all numbers in the original multi-set are included in the subsets ==> https://pdfs.semanticscholar.org/4dcb/83bfcfe2aacf506f58b3274c07bb17db7489.pdf – kavadias Feb 07 '17 at 17:11

1 Answers1

1

Yes. Suppose the numbers are $x_1,\dots,x_n$ and the target ratio is $r$. Define

$$y=\left\lfloor {1-r \over 1+r} \times (x_1 + \dots + x_n) \right\rceil,$$

and then look for the partition of $x_1,\dots,x_n,y$ that has minimum difference. I suspect this might be either the solution to your original problem, or very close to it.

Why? A partition of $x_1,\dots,x_n$ with exactly the ratio $r$ will have one group whose total is $c (x_1+ \dots + x_n)$ and another whose total is $cr(x_1+\dots+x_n)$. These two must sum to $x_1+\dots+x_n$, so we find that $c+cr=1$, i.e., $c=1/(1+r)$, so their difference is

$$c(x_1+\dots+x_n) - cr(x_1+\dots+x_n) = {1-r \over 1+r} (x_1+\dots+x_n).$$

We have defined $y$ to be this difference, rounded to the nearest integer. So, if you add $y$ to the smaller group, you get a perfect partition of $x_1,\dots,x_n,y$ with difference zero. And the converse is true as well.

D.W.
  • 159,275
  • 20
  • 227
  • 470
  • Interesting. Though, this requires that I arrange for the target ratio r to be r > 1, because number partitioning is defined for positive integers... – kavadias Feb 08 '17 at 11:59
  • Also, y usually will not be an integer. There will be a significant loss of accuracy, in most cases, if I take the integer part. Assume I multiply all numbers by the targeted accuracy (or as much as would makey an integer). The larger the accuracy you need, the more difficult the problem becomes: "If m is the number of bits needed to express any number in the set and n is the size of the set then m / n < 1 tends to have many solutions and m / n > 1 tends to have few or no solutions." ==> https://en.wikipedia.org/wiki/Partition_problem#Hard_instances – kavadias Feb 08 '17 at 12:22
  • In my case, I already multiply by 2^10 the CPU idle time ratios, so, I would need to raise their accuracy, say, another 10 bits. Or(!), I could avoid raising xi accuracy, by setting R = r<<10, S = x1+...+xn and calculating y = ((R - 2^10) x S) / (2^10 + R). This would make y of the targeted accuracy, same as xi. This is OK, I suppose (although it corresponds to "taking the integer part of y") :-) – kavadias Feb 08 '17 at 13:33
  • 1
    @kavadias, thanks. See edited answer, which now works correctly for $0 \le r \le 1$ and which avoids the issue associated with fractions (by rounding to the nearest integer). – D.W. Feb 08 '17 at 16:10