Let's say that I have a database of foods, each with an amount of Fat, Carbs and Protein. For example, let's say that I had this database:
Item Fat Carbs Protein ================================================ Milk 12 36 8 Chicken 1 12 18 Juice 0 50 2 Bacon 9 1 4
What would be an efficient algorithm to see what combinations of these foods would fit a certain range of desired Fat, Carbs and Protein, and each item can be used multiple times?
Like if I wanted a combination that was in the range of Fat: 20-30, Carbs: 170-190, Protein: 100-110, then 2 Milks, 5 Chickens, 1 Juice, and 0 Bacon would be one possible solution, as would 0 Milks, 5 Chickens, 2 Juices and 2 Bacons.
It would also be fine if the algorithm stopped once it hit just a possible solution, but I would like it to not be a deterministic algorithm so the next time it is run there is the possibility that a different solution would be found.
This problem sounds like an NP-hard problem like the subset sum problem or the knapsack problem, and I have looked into algorithms for those but I don't understand the algorithms for the multiple-constraint problems. Also knapsack problems are optimizing while here there is no optimizing.
I suppose this problem would be much more difficult if there were more items in the database, and much more easier (to find a single solution that fits the constraints) if the solution was not limited to integers (like 0.2 Milks).
I plan to incorporate something like this in Python so Python solutions would be appreciated, thanks.