3

So, say you have a collection of value pairs on the form {x, y}, say {1, 2}, {1, 3} & {2, 5}. Then you have to find a subset of k pairs (in this case, say k = 2), such that the ratio of the sum of all x in the subset divided by all the y in the subset is as high as possible.

Could you point me in the direction for relevant theory or algorithms? It's kind of like maximum subset sum, but since the pairs are "bound" to each other it introduces a restriction that changes it from problems known to me.

Jontahan
  • 113
  • 8

1 Answers1

3

Initially I thought that a simple greedy approach could work here, but commentators pointed out some counter examples.

Instead I think a bisection approach should work.

Suppose we want to know whether it is possible to achieve a ratio of g.

We need to add a selection of k vectors to end up above a line of gradient g.

If we project each vector perpendicular to this line to get values p1,p2,p3, then the final vector will be above the line if and only if the sum of the p values is positive.

Now, with the projected values it does seem right that the optimal solution is to choose the largest k.

We can then use bisection to find the highest ratio that is achievable.

Mathematical justification

Suppose we want to have the ratio above g, i.e.

(x1+x2+x3)/(y1+y2+y3) >= g

=> (x1+x2+x3) >= g(y1+y2+y3)

=> (x1-g.y1) + (x2-g.y2) + (x3-g.y3) >= 0

=> p1 + p2 + p3 >= 0

where pi is defined to be xi-g.yi.

Peter de Rivaz
  • 33,126
  • 4
  • 46
  • 75
  • 1
    Let's have the pairs a = {2,4}, b = {1,2} & c = {3,3}. The first and second pair would have the same individual ratio. Yet if we were to choose two pairs we have two scenarios that look like this: a & c = (2 + 3)/(4 + 3) = 5/7. b & c = (1 + 3)/(2 + 3) = 4/5. Same individual ratio, different outcome when grouped with the same pair. – Jontahan Apr 13 '17 at 09:52
  • 1
    This won't work here, as addition of ratios doesn't give the same result when we add numerators and denominators separately and otherwise. What I mean is, `a/x + b/y != (a+b)/(x+y)` and OP here wants `(a+b)/(x+y)` – vish4071 Apr 13 '17 at 09:53
  • 1
    I think this is a counter example where you have three sets (3, 1), (2001, 1000), (2, 1), and k = 2. The greedy method suggest using sets [(3, 1), (2001, 1000)], but [(3, 1), (2, 1)] would give a better ans – Petar Petrovic Apr 13 '17 at 10:02
  • Thanks for the counterexamples - I have proposed an alternative method – Peter de Rivaz Apr 13 '17 at 11:12
  • 1
    Could you explain more what you mean, maybe with a visual? I don't quite understand​, although the ideas are inspiring. – גלעד ברקן Apr 13 '17 at 12:49
  • @גלעדברקן I've added some maths which may help – Peter de Rivaz Apr 13 '17 at 15:06