Is there a way to test the best fit of combination of ratios to fit inside an overarching ratio? We have a problem we are trying to solve where we have a number of different containers. Each container can hold a number of different items (call them "item $A$" through to "item $H$"). Each container can handle a different ratio of the items before it is full. So taking just three of the containers the ratios the can handle may be:
Container $1$ may be able to hold the items in the ratio like below:
A  B  C  D  E  F  G  H
1  2  3  3  3  3  2  1

Container $2$ may be able to hold the items in the ratio like below:
A  B  C  D  E  F  G  H
1  2  3  4  4  3  2  1

Container $3$ may be able to hold the items in the ratio like below:
A  B  C  D  E  F  G  H
1  1  2  2  3  3  4  4  

What we need to try and find out is how to best fit packs of items with smaller ratios with a maximum number of items (say $5$ or $6$) into the containers. We can find all the different permutations of packs using combinatorics. We have a limit that out of all of the pack ratio permutations we can only select $3$ or $4$ different ones to use, so have to discard the worst fits and keep the best $3$ or $4$.
What we are struggling with is a technique that can test for the best of the smaller packs into the larger containers that is both accurate and performant. Currently we have one or the other!
Is there a way to do this$?$
 A: I'm going to take as the first goal a statement of the mathematical problem to be solved, and then make some suggestions about a greedy algorithm to approximate the solution.
As with many combinatorial problems, we can separate out the hard part, here the selection of up to four "packs" useful in loading containers, and the easy part, assessing the "goodness" of any possible selection.  This latter part is not very clear in the Question statement, so I will propose an objective that is relatively easy to compute and arguably representative of what the real world objective is.
Suppose that the packs $P_1,P_2,P_3,P_4$ have been chosen as multisets of the available items.  We pose the following "inner" problem.
We define a cost of filling a specified number $f_i$ of each kind of container $C_i$, using combinations of packs $P_k$ and individual items $j$ ("item A to item H" in the Question statement).
Let $w_k$, $k = 1,2,3,4$, be the cost of loading pack $P_k$ into a container.  We assume this is a common cost for any container $C_i$ into which $P_k$ will fit, but the value could be made to depend on the container as well as the pack, or simply to be a constant depending on neither.  Also let $w_0$ be the cost for loading any individual item in a container.
We want to minimize the total cost $T = \sum_i f_i L_i$ of loading all containers, where $L_i$ is the cost of loading one container $C_i$.  Notice that achieving this minimum total cost $T$ amounts to minimizing the cost $L_i$ of filling each different container, given the available packs and itemized costs.
Because the minimization is done for each container type $C_i$, these are small integer linear programs.  Although there may be tens of different container types (per the Question statement), solving the least cost ways of loading each are fully decoupled computations.
Example Taking the itemized and pack loading costs $w_0 = w_1 = w_2 = w_3 = w_4$ to be equal and positive results in finding how to fill each container $C_i$ with the fewest items and packs, counting both items and packs equally.
The outer problem is selecting which packs $P_1,P_2,P_3,P_4$ will result in the minimum total cost $T$.  Consideration of all possible packs, even though only four at a time are used, seems fairly impractical.  We therefore propose a procedure that searches for good choices of packs based on a greedy heuristic.
By greedy we mean choosing the first pack $P_1$ so that $|P_1| \sum_{i\in S_1} f_i$, the largest number of items coverable by a pack, is maximized.  Here $S_1$ denotes the set of indexes $i$ for which $P_1 \subseteq_m C_i$ (where the subscript $m$ reminds us we are dealing with multisets rather than simple sets).
Remove as many copies of $P_1$ from the various $C_i$ containers as possible (at least one copy for each $i$ in $S_i$), and repeat the process with the redacted container definitions $C_i'$ to choose the second pack $P_2$.  And so on, until all four packs are defined.
At certain points in this search there may be more than one choice of $P_k$ that maximizes the corresponding coverage $\sum_{i\in S_k} f_i$.  If computational time permits, some or all of these variations should be explored.
