If you were to stroll into the Application Engineering office at Maplesoft, you might be led to believe that we subsist on nothing but donuts, pizza, chocolate and coffee.  It’s even worse at this time of year when we have many more opportunities to over-consume. I try to have a balanced diet, but there are too many temptations scattered around the office (including candy at the office entrance – our receptionist, Walli, expects me at 3pm each day without fail). It doesn’t help that a virtually limitless supply of donuts are only a three minute drive away.

One of my (usually quickly discarded) New Year’s resolutions is to at least have a half-hearted attempt at balancing my diet. Being a natural-born geek, my second nature is to formalize the problem like so:

Given a basket of different foods, what is the best combination and quantities of food to maintain my nutritional requirements while minimizing the total cost? 

 

Stigler studied this problem heuristically in the 1940s, but only the development of the simplex algorithm a few years later gave relatively quick accurate solutions.  This application belongs to a broad field called Linear Programming, a discipline that explores how we can best allocate resources under real-world constraints.

Given that the new year is rapidly approaching, I decided to plan my diet with Maple.  I first needed to choose what foods were in my basket. I picked donuts, bagels, yogurt, chilli, broccoli, apples, oats, oranges, boiled lentils (with no salt), raw carrots, cooked Brussel sprouts and spinach (with no salt), skinless roast chicken, blueberries, and milk.

The nutritional data could be easily found on the web .  I chose only to consider the calories, total fat (including saturated and trans fats), cholesterol, sodium, carbohydrates, fibre, sugar, protein, vitamin A and C, iron and calcium content of the food (I could have easily included constraints involving other vitamins and minerals, like B12, selenium and potassium). 

Within Maple, after forming the cost function and the constraints, I used Optimization[LPSolve] to minimize the cost while finding the number of portions that maintained the nutritional values between specific bounds.

results:=LPSolve(totalCost,{

totalCalories>=1900,totalCalories<=2200,            #Calories (kCal)

totalFat<=75,totalFat>=30,                          #g

totalSatFat<=25,                                    #g

totalTransFat<=2,                                   #g

totalCholesterol<=300,                              #mg

totalSodium<=2300, totalSodium>=1500,               #mg

totalCarbs>=150, totalCarbs <=300,                  #g

totalFibre>=20, totalFibre<=60,                     #g

totalSugar<=50,                                     #g

totalProtein>=50, totalProtein<=160,                #g

totalVitA>=3000,totalVitA<=7000,                    #IU

totalVitC>=300,                                     #mg

totalCalcium>=1000,                                 #mg

totalIron>=18,totalIron<=40},                       #mg

assume={integer,nonnegative},depthlimit=40):

I placed integer constraints on the number of portions of each food (but I could have easily just placed this restriction on a subset).

So what was the optimum diet? Naturally, with sensible and healthy constraints Maple kept nagging me to eat more fruit, vegetables, lentils, small amounts of meat and far fewer donuts (all at a cost that hovered around $10 or less).

Researchers have used linear programming techniques similar to those in the attached worksheet to investigate diet regimes with specific restrictions on certain factors (e.g. Atkins).  For example, Raffensperger (2008) found that the cheapest low-carbohydrate diet is far more expensive than diets with no carbohydrate restrictions.

As I’m writing this, muffins have appeared in the office, and I might just have one.  I just now need to skew the constraints in the Maple worksheet so I feel justified in doing so.

 

Sample output from the worksheet

Please Wait...