I have a very long "list" of numbers ( maybe thousands ) which may be grouped, by sum into "n" groups. The number of groups and values are given. For example:
- List of numbers: [1, 2, 5, 6, 7, 8.5, 10]
- Groups:[3, 15, 21.5]
I need to find a summary of which numbers in the "list" will crate given "groups".
- 3 = 1+2
- 15 = 5+10
- 21.5 = 6+7+8.5
Ideas?
You can solve the problem via integer linear programming as follows. Let binary decision variable $x_{i,g}$ indicate whether item $i$ (with value $v_i$) appears in group $g$. Let $s_g$ be the target sum for group $g$. The problem is to find a feasible solution to the linear constraints \begin{align} \sum_g x_{i,g} &= 1 &&\text{for all $i$} \\ \sum_i v_i x_{i,g} &= s_g &&\text{for all $g$} \end{align}