We all have different sets of goal in our life, and most of the time, there are different approaches to achieve these goals. One of such important goal is to have a balanced diet, and it has additional constraint of the tight budget in this pandemic.
In this article, I will discuss the way we can model our diet requirement with different constraints like budget, energy and fat requirements etc. and get the most optimised diet plan recommendation.
Let us assume that I like to have meat, eggs, broccoli, milk, apple, rice and potatoes. Below table shows the calorie and nutrient content of these food items.
Objective: I would like to have the most economical lunch to get a minimum of 1100 calories energy, less than 30 gm fat, less than 80 gm of carbohydrate, less than 5 gm of sugar.
We will PuLP to solve our diet optimisation goal. PuLP is an LP modeller written in Python.
from pulp import *
We aim to have a balanced diet lunch most economically, hence it is LpMinimize optimisation problem.
To model problem, we will define each food items I like as a variable. As we cannot have negative apples or eggs etc. hence lowBound is mentioned as zero. Also, the restaurant doesn’t allow to order half egg or three-quarter apple etc. hence we have put a constraint that the solution should be an integer.
meat=LpVariable("Meat", lowBound=0, cat="Integer")
broccoli=LpVariable("Broccoli", lowBound=0, cat="Integer")
milk=LpVariable("Milk", lowBound=0, cat="Integer")
apple=LpVariable("Apple", lowBound=0, cat="Integer")
rice=LpVariable("Rice", lowBound=0, cat="Integer")