Definitions
Assume we have a Shopping List $L$ which is a list of pairs of Items and Quantities: $L = [(i_1, Q_1), (i_2, Q_2), (i_3, Q_3) ...$
We also have a Stock List $S$ which is a list of pairs of Containers and Prices: $S = [(C_1, p_1),(C_2, p_2), (C_3,p_3)...]$
Each container is a list of 3-tuples of Items, Quantities, and Probabilities: $C_n = \left[\left(t_1,q_1,\frac{a_1}{b_1}\right), \left(t_2,q_2,\frac{a_2}{b_2}\right), \left(t_3,q_3,\frac{a_3}{b_3}\right)...\right]$
Purchasing a container for a given price gives you a chance of getting each item within it. The chance is equal to each item's probability. The probabilities are independent of each other (two items with a probability of 1/2 are treated as two coin flips, it isn't "one or the other"), and their quantities are absolute. If we had $C_1 = \left[\right(x, 2, \frac{1}{2}\left)\right]$, then there is a one-in-two chance of getting two $x$s, and no chance of getting only a single $x$.
The Goal
I'm trying to come up with some algorithm which has the ultimate goal of satisfying a given shopping list from some stock list. Due to the random nature of the problem, it is impossible to construct a definite chain of purchases to make. Thus, I was thinking that foo(L, S)
should return the best next purchase -- the container to buy which satisfies the most items in the shopping list for the lowest price. Purchasing this container can affect the shopping list in a variety of ways, so upon purchasing, the list will be run through the algorithm again and again until it is empty.
My Attempts
If I could construct a function which outputs some "instantaneous value" of each container, I could then calculate and sort each container by this value and purchase the one highest-valued one.
This value of a container would be its benefit minus its cost. Calculating the cost of containers which contain only one needed item is simple enough, but I'm stumped on containers with multiple items. Consider this example:
$L = [(x, 1), (y, 1)]$
$S = \left[\\ \left(\left[\left(x, 1, \frac{1}{2}\right)\right], 10\right),\\ \left(\left[\left(y, 1, \frac{1}{2}\right)\right], 10\right),\\ \left(\left[\left(x, 1, \frac{1}{3}\right),\left(y, 1, \frac{1}{3}\right)\right], 20\right)\\ \right]$
(The first container costs \$10 and has a 1/2 chance of giving an $x$. The second container costs \$10 and has a 1/2 chance of giving a $y$. The third container costs \$20 and has a 1/3 chance of giving an $x$, and a 1/3 chance of giving a $y$.)
The cost of getting an $x$ from the first container is \$20. This would satisfy one out of two of our list's requested items. If our strategy for satisfying the list was to brute-force the first container, then the second, the total cost of the list would be \$40.
What gives me trouble is that third choice. There is a 1/9 chance of spending only \$20 and getting both of our $x$ and $y$ in one move. There is a 4/9 chance of spending \$20 and getting either our $x$ or $y$ -- we could then get the remaining one for \$20 and be done for \$40. Finally, there is another 4/9 chance of getting nothing.
I suspect that the best path in this case is to buy the third container until at least either an $x$ or $y$ is obtained, then buy the remaining one from the first or second container. (Edit: A simulation shows that solely buying containers 1 and 2 leads to an average cost of \$40 to satisfy the list, as expected, but buying the third container then one or two leads to an average cost of \$52 to satisfy the list. Besides simulating, I'm unsure of how to derive that 52)
Any ideas on how to approach this?