An Approach to Diet Cost Optimization for Different Age Groups Using Linear Programming


Linear Programming optimization is used in this paper to find minimum cost and quantity of food items for selection of proper diet containing sufficient nutrition elements over a week for three different age groups. For this purpose, first a linear programming optimization model is selected and then three data files defining the various food items with their corresponding cost and nutrition elements appropriate to three distinct age groups are constructed. Finally, the model files and the data files are solved to obtain output cost and amount of food items to be purchased. The optimal solution demonstrates distinct cost and amount of food for different age groups. It also shows different level of complexity while obtaining objective values for different age groups.

Share and Cite:

Sultana, J., Hasan, Md.M., Tanni, S.I., Ruman, U. and Islam, S. (2022) An Approach to Diet Cost Optimization for Different Age Groups Using Linear Programming. Open Access Library Journal, 9, 1-11. doi: 10.4236/oalib.1107905.

1. Introduction

A mathematical optimization model is a decision tool to quantitatively express a problem and find the optimal solution for best interest. Linear Programming (LP) optimization is a process where desired solution is obtained from a set of linear equations or inequalities. To solve a problem using LP optimization, first, a model is constructed and then several set of variables are defined. The model consists of one objective function and a set of constraint functions to optimize the objective function. The defined variables formulate a number of linear equations following the model and finally these equations are solved to find the target solution. Many software tools are available to aide in this process to save time and labor.

Since the development and application of Linear Programming (LP) during Second World War to plan and correlate military expenditures and outcomes, it has been substantiated and implemented in more and more applications throughout the years [1] . Presently Linear programming is being extensively used in industrial and scientific research fields. It has become an effective tool to analyze cost benefit relations in industries, maximize yield in agriculture, design routes in commercial aviation, predict traffic density in telecommunication and many other areas. It has also contributed in development of sophisticated techniques like game theory which found its application from determining national policy to analyze human behaviors [2] . In this research work, Linear Programming is used to determine cost and quantity of food of a balanced diet.

Nutrients help people perform their day to day activities properly and fight any disease that might harm them. For children, nutrients contribute to their physical and mental developments. For elderly peoples, it compensates for the lack of bodily functions efficiency [3] . Absence of a balance diet with adequate nutrition hampers physiological processes and can lead to sickness [4] . Proper nutrition is a key factor in leading a healthy life. Nutrition requirement varies according to age, gender, race and many other factors. Food intake of a person also varies depending on available food resources, culture, community etc. around the globe. Besides all these, financial ability of a person determines his ability to purchase sufficient food for a balanced diet. Considering all these factors, proper diet selection for a particular person can be overwhelming. Since its inception, LP has been extensively used for solving diet problems.

Section 2 describes the general Linear Programming Optimization theory. In Section 3, LP is proposed to solve the real life diet problem. Section 4 solves the presented problem using AMPL and discusses the results. Finally, the paper ends with a conclusion in Section 5.

2. Formulation of LPs

To select the optimum plan a quantitative technique named linear programming can be used. Three basic criteria are needed to build up an optimization problem [5] .

1) Objective function which describes the behavior of the measure of effectiveness that needs to be maximized or minimized.

2) Decision variables and parameters that are directly controlled variables by decision maker are called decision variables while the uncontrolled inputs are called parameters.

3) Constraints functions that build the relation between decision variables and parameters to finally optimize the objective function.

A linear programming problem (LP) can be generalized mathematically in the following form:


Z = d 1 x 1 + d 2 x 2 + + d n x n (1)

Subject to:

p 11 x 1 + p 12 x 2 + + p 1 n x n ( , = , ) r 1

p 21 x 1 + p 22 x 2 + + p 2 n x n ( , = , ) r 2 (2)

p m 1 x 1 + p m 2 x 2 + + p m n x n ( , = , ) r m

x j 0 , where j = 1 , 2 n

where each of the linear equations or inequalities in Equation (1) determines a constraint to the solution. Here only one of the three symbols holds for each of the equations depending on the constraint.

3. Diet Optimization Using LP

To lead a healthy life, a person must have a balanced diet. Dietary requirement of a person depends on age, gender, body weight, race and also any underlying medical condition if there is any. Though a nutritionist can determine the dietary requirements of a person it is not an easy task to select food items that should contain all the necessary nutrients in adequate amount. It might require careful selection and extensive calculation to determine appropriate diet for a person. With the help of Linear Programming and software to solve the optimization problem, this laborious and time consuming task can easily be accomplished. For this first, an appropriate software tool is selected which in this case is AMPL. Then appropriate model befitting the software tool needs to be constructed and then data correlating food and nutrition can be provided to obtain the target result.

In this research work, LP optimization is used to find cost for purchasing of food containing sufficient 20 nutrition elements over a week for three different age groups. This also determines the amount of 30 food items to be purchased. For this, first a model is developed and then three data files defining the 30 food items with their corresponding cost and 20 nutrition elements appropriate for three distinct age groups are constructed. Finally the model files and the data files are solved using AMPL in the next section to obtain output cost and amount of food items to be purchased.

3.1. Model Description

The adopted model for diet optimization [6] is as follows:

set NUTR;

set FOOD;

param cost {FOOD} > 0;

param f_min {FOOD} >=0;

param f_max {j in FOOD} >= f_min [j];

param n_min {NUTR} >=0;

param n_max {i in NUTR} >= n_min[i];

param amt {NUTR,FOOD} >= 0;

var Buy {j in FOOD} >= f_min[j],<=f_max[j];

minimize Total_Cost: sum {j in FOOD} cost[j]*Buy[j];

subject to Diet {i in NUTR}:

n_min[i] <= sum {j in FOOD} amt[i,j] * Buy[j] <=n_max[i];

Following the general LP structure, cost of the food items that contain appropriate nutrition for a particular person over a week is set as the objective function. The expression for this in the model is

Total_Cost: sum {j in FOOD} cost[j]*Buy[j];

where cost is the unit price of foods and Buy is the amount of food one should buy.

The variable Buy is limited by the constraint function

Buy {j in FOOD} >= f_min[j],<=f_max[j];

where f_min and f_max are respectively the minimum and maximum amount of particular foods that a person should consume over a week.

The amount of nutrients a person should consume over a week is given by the expression:

n_min {NUTR} >=0; and

n_max {i in NUTR} >= n_min[i];

And food selection for the objective function is determined by the expression:

n_min[i] <= sum {j in FOOD} amt[i,j] * Buy[j] <=n_max[i];

Combining all these expressions we get the model for diet selection using LP. The food and nutrients information are passed through the variables FOOD and NUTR respectively.

3.2. Data Preparation

This sub-section provides with data to be input in the discussed model. The input data needs to be prepared in such way that the solver tool can interpret and use the data in the model to perform calculations. Here, dietary requirement of only three age groups―Children (age below 14), Adults (age between 14 to 50) and Elderly (age above 50) is considered. Some data are collected from bangla booklet “Nutrition in Bangladeshi Foods” by BIRTAN [7] and others from Internet ( The required quantities of nutrients for each level are collected on the basis of per week. The prices of the foods have been collected from the local market and then converted from Bangladeshi Take to U.S. Dollar. The provided data should not be relied upon for meeting nutritional requirements rather only be considered as mere numbers to demonstrate the model. Nutrients limits are different for different age groups. The amounts of nutrients per unit of food are given in Table 1. Table 2 contains Cost and minimum & maximum consumption of particular food. Table 3 represents maximum and minimum amount of nutrients for different age groups.

Table 1. Chart containing nutrients per unit of food.

Table 2. Cost and minimum & maximum consumption of particular food.

Table 3. Maximum and minimum amount of nutrients for different age groups.

As AMPL is used to construct and solve the linear equations to obtain the solution, some sample of constructed linear programs in AMPL interface are given in the followings:

ampl: expand;

minimize Total_Cost:

0.625*Buy['RICE'] + Buy['MILK'] + Buy['COFFEE'] + 0.25*Buy['CALFLOWER']

+ 2*Buy['ORANGE'] + 3*Buy['ICE.CREAM'] + 0.5*Buy['BREAD'] +

0.7*Buy['OIL'] + Buy['EGG'] + 2.1*Buy['MUSHROOMS'] + 2*Buy['CHICKEN']

+ Buy['BEEF'] + Buy['WATERMELON'] + 0.5*Buy['CHILI'] + Buy['PUMPKIN']

+ 2*Buy['FISH'] + 3*Buy['LITCHIS'] + 2.5*Buy['TURKEY'] +

0.5*Buy['TOMATOES'] + Buy['CREACKERS'] + 0.5*Buy['LIMEJUICE'] +

0.5*Buy['PEPPER'] + Buy['GRAVELEAVES'] + Buy['GINGER'] +

0.5*Buy['PEANUTS'] + Buy['LETTUCE'] + Buy['CHEESE'] + Buy['LIMES'] +

1.5*Buy['NODDLES'] + Buy['GUAVA'];

subject to Diet['ENERGY']:

20000 <= 97*Buy['RICE'] + 61*Buy['MILK'] + 9*Buy['COFFEE'] +

23*Buy['CALFLOWER'] + 43*Buy['ORANGE'] + 201*Buy['ICE.CREAM'] +

293*Buy['BREAD'] + 884*Buy['OIL'] + 199*Buy['EGG'] +

296*Buy['MUSHROOMS'] + 157*Buy['CHICKEN'] + 410*Buy['BEEF'] +

557*Buy['WATERMELON'] + 314*Buy['CHILI'] + 541*Buy['PUMPKIN'] +

87*Buy['FISH'] + 66*Buy['LITCHIS'] + 170*Buy['TURKEY'] +

258*Buy['TOMATOES'] + 434*Buy['CREACKERS'] + 27*Buy['LIMEJUICE'] +

281*Buy['PEPPER'] + 93*Buy['GRAVELEAVES'] + 347*Buy['GINGER'] +

585*Buy['PEANUTS'] + 13*Buy['LETTUCE'] + 300*Buy['CHEESE'] +

30*Buy['LIMES'] + 527*Buy['NODDLES'] + 51*Buy['GUAVA'] <= 40000;

subject to Diet['FIBER']:

210 <= Buy['RICE'] + 2.7*Buy['CALFLOWER'] + 0.1*Buy['ORANGE'] +

0.7*Buy['ICE.CREAM'] + 2.5*Buy['BREAD'] + 12*Buy['MUSHROOMS'] +

1.8*Buy['BEEF'] + 34*Buy['CHILI'] + 3.9*Buy['PUMPKIN'] +

1.3*Buy['LITCHIS'] + 12*Buy['TOMATOES'] + 3*Buy['CREACKERS'] +

0.4*Buy['LIMEJUICE'] + 22*Buy['PEPPER'] + 11*Buy['GRAVELEAVES'] +

13*Buy['GINGER'] + 8*Buy['PEANUTS'] + Buy['LETTUCE'] + 2.8*Buy['LIMES']

+ 3.9*Buy['NODDLES'] + 25*Buy['GUAVA'] <= 1500;

subject to Diet['ZN']:

100 <= 0.4*Buy['RICE'] + 0.4*Buy['MILK'] + 0.1*Buy['COFFEE'] +

0.2*Buy['CALFLOWER'] + 0.1*Buy['ORANGE'] + 0.7*Buy['ICE.CREAM'] +

0.7*Buy['BREAD'] + 1.2*Buy['EGG'] + 7.7*Buy['MUSHROOMS'] +

4.3*Buy['CHICKEN'] + 8.1*Buy['BEEF'] + 10.2*Buy['WATERMELON'] +

2.7*Buy['CHILI'] + 7.46*Buy['PUMPKIN'] + 1.48*Buy['FISH'] +

0.07*Buy['LITCHIS'] + 3.1*Buy['TURKEY'] + 1.99*Buy['TOMATOES'] +

0.77*Buy['CREACKERS'] + 0.1*Buy['LIMEJUICE'] + 2.8*Buy['PEPPER'] +

0.7*Buy['GRAVELEAVES'] + 4.7*Buy['GINGER'] + 3.3*Buy['PEANUTS'] +

0.2*Buy['LETTUCE'] + 24*Buy['CHEESE'] + 0.1*Buy['LIMES'] +

14*Buy['NODDLES'] + 0.2*Buy['GUAVA'] <= 7000;

3.3. Optimal Solution Using AMPL

AMPL, acronym for “A Mathematical Programming Language”, developed by Robert Fourier, David Gay and Brian Kemighan in Bell Laboratories [8] is an algebraic modeling language for solving and analyzing high-complexity problems for large-scale mathematical computation (i.e. large-scale optimization and scheduling-type problems). It is also a very powerful algebraic modeling language for linear and nonlinear optimization problems, in both discrete and continuous variables. It is ideal for rapid prototyping and development of models, while its speed and generality provide the resources required by repeated production runs [9] .

First the model and data are prepared in text files. Then these are incorporated in the AMPL interface using proper commands. Finally the linear program is solved and displayed in the interface. Such process for solving the objective function for children age group is as follows:

sw: ampl

ampl: model diet_mod.txt;

ampl: data children_dat.txt;

ampl: solve;

MINOS 5.51: optimal solution found.

17 iterations, objective 108.825

ampl: display Buy;

Buy [*] :=










Using AMPL, the optimal solution of the objective function for different age groups can be demonstrated. Quantities of food items to be purchased for children age group are shown in Table 4. Table 5 and Table 6 show the quantities of food items to be purchased for adult and elderly age groups respectively.

Table 4. Quantities of food items to be purchased for children age group.

Table 5. Quantities of food items to be purchased for adult age group.

Table 6. Quantities of food items to be purchased for elderly age group.

The optimal solution of the objective function for children age group is found 108.825 after 17 iterations (Table 4).

The optimal solution of the objective function for adult age group is found 110.1682683 after 37 iterations (Table 5).

The optimal solution of the objective function for elderly age group is found 109.9573062 after 31 iterations (Table 6).

4. Discussion

From the obtained result in previous section, it is evident that cost of proper diet is different for different age group. Different nutritional requirements in age groups caused differences in quantity of several food items. For example, children and adults require 3 units of cheese while the elderly people need 3.383 units. Again children need 4 units of peanuts while the adults and elderly peoples require 4.369 and 4.023 units of peanuts respectively. These differences also resulted in different levels of computational complexities which are reflected in the number of iterations.

5. Conclusion

Linear Programming is used to optimize a general yet important issue. In this paper, a structured approach to accommodate balanced diet containing sufficient nutrients in low cost is made using LP optimization tool. It suggests that the required minimum cost varies for different nutritional requirement. It also demonstrates that, varying nutrient requirement leads to change in food intake. The change in complexity of calculations is evident from the varying number of iterations with different constraints. Finally, it can be implemented in a larger scope by adapting distinct physiological nutritional requirements in broader spectrum and including all the necessary nutrients as well as large variety of food choice.

Conflicts of Interest

The authors declare no conflicts of interest.


[1] Kantorovich, L.V. (1940) On One Effective Method of Solving Some Classes of Extreme Problems. Academy of Sciences, 28, 211-214.
[2] Dantzig, G.B. (1947) Maximization of a Linear Function of Variables Subject to Linear Inequalities. In: Koopmans, T.C., Ed., Activity Analysis of Production and Allocation, Wiley & Chapman-Hall, New York, London, 339-347.
[3] Dewey, K.G. and Brown, K.H. (2003) Update on Technical Issues Concerning Complementary Feeding of Young Children in Developing Countries and Implications for Intervention Programs. Food and Nutrition Bulletin, 24, 5-28.
[4] Saunders, J. and Smith, T. (2010) Malnutrition: Causes and Consequences. Clinical Medicine Journal, 10, 624-627.
[5] Winston, W.L. and Goldberg, J.B. (2004) Operations Research: Applications and Algorithms. 4th Edition, Thomson Brooks/Cole.
[6] Fourer, R., Gay, D.M. and Kernighan, B.W. (2003) AMPL: A Modeling Language for Mathematical Programming. 2nd Edition, Thomson/Brooks/Cole.
[8] Gay, D.M. (2015) The AMPL Modeling Language: An Aid to Formulating and Solving Optimization Problems. Numerical Analysis and Optimization, Springer, Cham, 95-116.

Copyright © 2022 by authors and Scientific Research Publishing Inc.

Creative Commons License

This work and the related PDF file are licensed under a Creative Commons Attribution 4.0 International License.