Home > Net >  Variation without the cost of foods using the Diet Problem(Maximization Problem)
Variation without the cost of foods using the Diet Problem(Maximization Problem)

Time:06-05

I've been looking for an algorithm that helps me to create the best possible diet based on a certain amount of nutrients. After a lot of research and attempts, it didn't succeed. But I found something that almost worked, which was the diet problem, or maximization problem, which needs a value for each food, thus not working for the purpose I was looking for. I would like to know if there is any similar algorithm or a mathematical equation that could solve my problem.

Example of what I'm looking for:

I Have a meal that needs to be filled with 300cal, 30g of carbohydrates, 15g of protein, and 7g of fat.

I also have these 2 foods:
rice with: 125cal, 3g of protein, 30 of carbohydrates, and 0 >of fat for each 100g

chicken breast with: 160cal, 32g of protein, 0 of carbohydrates, and 2.5 of fat for each 100g

What I'm looking for is an amount in grams for each food that maximizes the amount of each macronutrient in my meal!

Thanks in advance!

CodePudding user response:

Let's suppose you eat r grams of rice and c grams of chicken. Then your calorie total will be 1.25r 1.6c, and since you need at least 300 calories, you're looking to satisfy the inequality

1.25r 1.6c ≥ 300

Looking across all the requirements gives you the following:

1.25r 1.6c ≥ 300 (calories)

0.3r 0c ≥ 30 (carbohydrates)

0.03r .32c ≥ 15 (protein)

0r 0.025c ≥ 7 (fat)

Any combination of r and c that satisfies all these inequalities will give you everything you need. Of course, you could do this by making c and r huge (say, eat 10kg of rice and 10kg of chicken), and so you'll need some counterbalancing force that pushes c and r to be small. In your problem statement you mentioned you wanted to maximize the amount of each macronutrient, but, as I've pointed out here, that might not actually be what you're really aiming for. :-)

One way to do this would be to minimize the total mass of everything you eat - that is, you'd want to minimize r c. That would give you back a linear program, which you could use an off-the-shelf solver to handle:

MINIMIZE

r c

SUBJECT TO

1.25r 1.6c ≥ 300 (calories)

0.3r 0c ≥ 30 (carbohydrates)

0.03r .32c ≥ 15 (protein)

0r 0.025c ≥ 7 (fat)

The values of r and c that solve this linear program will be the lowest-mass way of eating rice and chicken to get your minimum requirements.

Or, perhaps, you want to minimize the total number of calories that you consume. That could be done by solving this linear program:

MINIMIZE

1.25r 1.6c

SUBJECT TO

1.25r 1.6c ≥ 300 (calories)

0.3r 0c ≥ 30 (carbohydrates)

0.03r .32c ≥ 15 (protein)

0r 0.025c ≥ 7 (fat)

There are a lot of variations on this theme. You could factor in the prices of rice and chicken, or minimize fat, etc. But the basic idea is to turn your possible foods and nutrient requirements into a series of inequalities, then try to solve some optimization problem on those inequalities.

Hope this helps!

  • Related