How can I maximize the sum of y values across a given number of graphs?

132 Views Asked by At

I have any number of graphs. Each graph is a plot of points, not necessarily an equation.

I need to pick a point on each graph in way that the following is true:

  1. The sum of the y values of each point is maximized
  2. The sum of the x values of each point does not exceed a limit L, which can be any positive number.

The problem seems so simple, and yet I cannot find a way to solve the problem mathematically. There are several ways to solve the problem using CS, but I would prefer to avoid those if possible.

1

There are 1 best solutions below

1
On

This has the combinatoric feel that says to me finding a perfect algorithm will be hard and the problem may even be NP hard. I would suggest the following reasonably greedy algorithm:

  1. Find the maximum $y$ value in each graph
  2. Add up the corresponding $x$ values. If the sum is less than $L$ you are done.
  3. If the sum is greater than $L$, look over the next best $y$s that are at lower $x$s than the ones you are using. Find the one that maximizes the ratio $\frac {\Delta x}{\Delta y}$ Replace the applicable point in your list.
  4. If the sum of $x$s is less than $L$ you are done. Otherwise repeat step $3$

This is not guaranteed to find an optimal solution. It could be that the third best $y$ in one graph comes with a very small $x$ and would get the sum down to $L$ in one go.