0

I want to solve a problem in python with integer programming (cvxpy librairy), but I am a little confuse about the definition of my constraints.

Here is my problem. I have two databases. 1 contains food products (name of the product/quantity (g/L/piece)/ quantity (how many units)). The other contains recipes (name of the recipe/name of the product/quantity needed (g/L/piece)). I want to know how many of each recipe I have to make in order to minimize my food products left quantity. So my "selection" variable would be :

selection = cvxpy.Variable(number_of_recipes, integer = True)

I have 2 constraints. The first is that I can't chose more products than the quantity I have. So I have something like :

supply_constraint = cvxpy.sum_entries(selection, axis=0) <= max_quantity

I see a first problem here. "selection" has the len of the number of recipes, and "max_quantity" the len of the number of ingredients. That does not match. Do I have to define 2 variables to solve, one for the recipes and one for the products ? For my tests I have few recipes and products, but my databases are supposed to have thousands of each.

My second constraint is that a product is allocated to a recipe only if all the ingredients of the recipe are allocated to it too. I don't even know how to express this constraint with cvxpy.

Thank you for those who will help me !

  • For the first problem: You need one constraint for each ingredient. And instead of just summing the selection variables, you must sum the selection variables multiplied by the amount you need of the respective ingredient for the recipes. – Daniel Junglas Aug 13 '20 at 09:10
  • It seems to me that the second constraint is always implicitly satisfied (provided you got the first constraint right): whenever a `selection` variable is non-zero, then there is enough of all ingredients for the respective recipe since otherwise the first constraint would be violated. – Daniel Junglas Aug 13 '20 at 09:12
  • Thank you for your answers. I see what you mean, I will try this ! – Philippine Prevost Aug 13 '20 at 11:58

0 Answers0