Name: Albert Sund Aillet
Project: Diet Optimization
Links:
I am here to present my Obscure side-project:
- “Food as fuel”
- Usually when I am buying food I think about what is actually the best for my body and what minimizes my impact on the planet,
- Depends on the goals and preferences
- But what if these could be defined
The side project I built:
- An app that uses:
- Price data of food products
- Nutrition data of food products
- Set of requirements and preferences from the user
- In order to proposal an optimal diet, minimizing certain aspect and maximizing other.
It uses the following parts:
- The open food facts database for up to date product information
- The open prices database for price information
- The ciqual and ciqual-calnut for approximate micro and macro nutrient for values that are not present on the food packaging.
- I get exchange rates from the European Central Bank to be able to compare all prices.
- I get estimated climate impact from AGRIBALYSE.
I had to look a lot into the data and do a few SQL joins.
What is the optimization problem: Linear programming, scipy formulation.
(Sorry for latex messing up, I will fix it later)
$$ \begin{align*} \min_{x} \quad & c^T x \\ \text{such that} \quad & A_{ub} x \leq b_{ub}, \\ %& A_{eq} x = b_{eq}, \\ & l \leq x \leq u, \end{align*} $$
Where in our case:
- x is a vector with the quantity of each product
- c is the costs (can be price or ecological footprint).
- Aub is a matrix that contains all the contsraints (nutritional requirements).
- l = 0 and u = ∞ since we don’t want negative amount of products
This can be solved quickly and efficiently with many out of the box
solvers. In my benchmarking, since the problem is not sparse, the
revised simplex method was the fastest.
The optimal solution is global.
The following features are available:
- sliders to change preferences and in real time get an updated list of optimal products to consume.
- a map where you can choose which products to include in the optimization.
- an editor to change the objective function to minimize.
Technology used (very simple):
- Python Flask backend
- DuckDB database since I am doing only reads
- Scipy
linprogfor the optimization - Vanilla JS and d3.js for the graphs.
How I deploy:
- I have a
Makefilewith all the deployment commands - I have a VPS with Hetzner where I the app.
Obscure side project that I thought about during my studies and then thought it would be easy and straightforward to finish in a few evenings.