I am trying to model the following problem. I have two boxes X and Y, and each of them contains a certain number of objects. For example the object 1 is $S_{x_1}$ times in the Box X and $S_{y_1}$ times in the box Y. I know that I can only pick a limited quantity of object from each box $C_x$ objects from box X and $C_y$ objects from box Y. I want to pick from any box in order to have the correct number of objects ($q_i$) at my disposition. I know at least one solution exists, but I want to find a better solution that would leave a fair ration between the two boxes.
I was able to write the following mathematical problem, but I do not really know how to solve it. I have the feeling that it is a hard problem anyway. But perhaps someone can link this to an existing well known problem?
$$\min_{x_i, y_i} \sum_i (x_i^* - y_i^*)^2$$
subject to $$\sum_i x_i \leq C_x,$$ $$\sum_i y_i \leq C_y,$$ $$\forall i$$ $$x_i^* = S_{x_i} - x_i \geq 0,$$ $$y_i^* = S_{y_i} - y_i \geq 0,$$ $$x_i + y_i = q_i,$$
with $C_X, C_y, S_{x_i}, S_{y_i}, q_i $ some constants
The objective is convex quadratic and the constraints are linear, so many mixed integer program (MIP) solvers will handle the problem. Now, if you are not wedded to squared difference, you could minimize the sum of the absolute differences. That is easily linearized, give you a mixed integer linear program (MILP), which all sorts of solvers (both free and commercial) can solve (unless your number of items is huge).