Status: PROTOTYPE LIVE ON GITHUB

What if you could hit all your nutrition targets while eating foods that you enjoy? This project leverages linear optimization to maximize tastiness subject to customized nutritional requirements

*disclaimer: this is NOT official dietary or nutritional advice. This is only a tool for personal use.

As a vegetarian who regularly strength trains, it can be difficult to get enough protein in my diet. Online sources will often cite “0.7-1.4 grams of protein per pound bodyweight”, which can be especially difficult, because for many Americans (myself included), that can be 200g+ of protein each day. For context, a singular egg (which is cited as a high-protein vegetarian source) only has about 6 grams of protein and 70 calories. A chicken breast on the other hand has over 24 grams of protein in an 130-150 calorie serving! So how are vegetarians supposed to get enough protein without eating 30+ eggs per day? More generally, how do you get that much protein while eating real food that actually tastes good?

I decided to take an unconventional approach to the problem and leveraged an old friend: linear optimization. I took classes in college that dabbled in various types of linear optimization. The types of problems involving it often involve maximizing an objective function (e.g. profit, output, etc.) subject to various resource constraints. This could range anywhere from a store deciding how much of each item to stock up on to an airline determining optimal pricing for seats on various routes (and everything in between!). To my knowledge, however, this has not been applied to nutrition and meal planning. So with the help of Python’s SciPy methods for linear optimization, I applied these techniques to my own meals.

The key question I settled on: how do I maximize the tastiness of my meals while staying within my dietary restrictions?

The first step was to make sure I had a way of conveying how tasty I found various meals and items to be, which is represented in a CSV file. In the file, each row of data has a name of a food, how tasty it is, the nutritional info, and any notes. I scrounged around for some typical meals I eat from very tasty and probably not very nutritious (a tikka masala) to not that tasty but more nutritious (like a whey protein powder in water).

Using this meal data, I set up a linear optimization problem. The objective function was to maximize tastiness, which I quantified for each meal. The constraints were the dietary targets: a calorie limit, and minimum and maximum values for protein, carbohydrates, and fats. The program takes into account any meals you've already eaten on a given day and calculates the remaining meals needed to meet your nutritional goals. You input the meals you've had and their quantities, and the program adjusts the constraints accordingly.

The code then outputs this list of meals, along with the total calories, protein, carbohydrates, and fats consumed, both from the meals already eaten and those recommended by the program. Specifically, the planner outputs a list of meals and their quantities that should be consumed to maximize tastiness while meeting the nutritional constraints. This helps users easily see how well their dietary intake aligns with their goals.

Next Steps / Future Work

  • Expanded Meal Library: the key downside of the way the code is set up right now is that users have to manually upload the tastiness of various meals as well as meals in general. Right now, the meal library is just a list of my own personal meals with how tasty I think they are. It’s not broadly applicable to people at large. Some ideas I’m toying with are allowing users to upload their own CSV and integrating to MyFitnessPal’s meal library.

  • User Interface: the interface is very basic at the moment. There’s a basic HTML screen with some CSS features and a back button on the other side, but nothing eye-catching. This gets the job done for now so I’m not in a rush to change it, but prettifying this page would be nice in the future

  • Limits on Meal Repetition: rather unsurprisingly, if your goal is to get a lot of protein (for example), the code will tell you to have as much whey protein and egg whites as possible. While this is technically accurate and fits all constraints, it’s not realistic. Imposing limits (e.g. no more than 2 whey protein shakes a day) would help make plans easier to stick with. I could also see this being brought to a broader scale such that on a given day you don’t have the same meal twice and in a week you don’t have it more than four times (or something like that). Because this is for personal use right now, if I see repeated meals, I just add other meals to my CSV, but a more sustainable method will be good in the future.

  • Suggestions on Homemade Recipes: there are some recipes in which a minor tweak makes a major difference in terms of feasibility for a meal plan. For example, I have a mushroom udon carbonara listed in my CSV. If you use one brand of udon noodles, it’s about 300 calories of just pure carbs of noodle, but others are no more than 150-200 calories of noodles, yet the flavor is the same. After using a lower-carb recipe alternative, it fit within my plan well, but beforehand it was a big no-no. A tool that can proactively provide suggestions to make recipes healthier would be great for such use cases (e.g. use 1 tbsp instead of 2 tbsp of butter, reduce ounces of noodles, try less oil, etc.).

Next
Next

The Battery Basics