Aim: find a diet combination that satisfy the nutritional and environmental constraints, while similar to the current diet.
Notation
We make the following notation:
are the target food intake (in grams, or other units) for food groups.
are the current food intake (in grams, or other units).
For the constraints,
: energy associated with each of the food groups
is the total energy for all foods, with range between
For example, with the data we have, this range is (9000, 10000).
: protein
: fat
: carbs
: sugar
: alcohol
: ghge
Optimization
Find a set of such that the values would
minimise the squared sum of differences between current diet and target diet:
and satisfy the following constraints:
(realistic diet intake can not be negative)
, total energy above the lower limit
, total energy below the upper limit
, total protein below the upper limit
, total protein below the upper limit
And so on.
Solve the optimization problem
This setting is a quadratic program (QP). It is an optimization problem with quadratic objective, and inequality constraints. We do not have equality constraints in this setting.
With R, there are various software to find a solution:
nloptr in nloptr package (non-linear optimization),
constrOptim in stats package, which relies on optim function,