Inside AI

Optimising Diet Plan In Tight Budget-Modelling In Python

A balanced recommended diet with the constraint of the tight budget in this pandemic is a challenge. It can be addressed to some extent with linear optimisation model

Kaushik Choudhury
4 min readOct 14, 2020


Photo by Brooke Lark on Unsplash

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.

Sample Nutrition Data Used In the Scenario Discussed ( Photo By Author)

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.

prob=LpProblem("Diet", LpMinimize)

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")
potato=LpVariable("Potato", lowBound=0…



Kaushik Choudhury

Kaushik Choudhury is an experienced Supply Chain Strategy and Digital Transformation manager in one of the Big 4 Consulting firm in the UK.