A mixed-integer programming problem

Snow
3 min readDec 4, 2020

A girl wants to lose weight, but in the meantime, she does not want to be in lack of certain nutritions. Find her a minimum calorie diet that contains at least 800 mg of calcium, 55 grams of protein, and 200 grams of carbohydrates

In order to avoid monotony, she decides to eat at most 5 units of each food type. She likes eating yogurt with apples, so any time she eats a yogurt, she eats an apple with it. She does not want to eat baked beans and roast chicken on the same day, so she decides that she will only eat from one of them.

The point is, we need to decide:

  1. What food she will eat
  2. How many items of it to eat

so that to satisfy nutrition needs and minimize total calories.

That’s why the above two points can be our variables.

VAR:

x_i: =1 if she eats i, =0 if not (i=1..5) binary

b_i = units she eats for i integer

PARAM:

c_i: calcium in i

p_i: protein in i

k_i: carb in i

z_i: calories in i

CONSTRAINTS:

she decides to eat at most 5 units of each food type

0 ≤ b_i ≤5 for all i

any time she eats a yogurt, she eats an apple

b_2 * x_2 ≤ b_1 * x_1

She does not want to eat baked beans and roast chicken on the same day, so she decides that she will only eat from one of them

x_3 + x_5 = 1

she does not want to be in lack of certain nutritions

sum_i(b_i * x_i *c_i) ≥ 800

sum_i(b_i * x_i *p_i) ≥ 55

sum_i(b_i * x_i *k_i) ≥ 200

OBJ:

minimize sum_i (b_i * x_i *z_i)

Solve in XPRESS

declarations
input param and write constraints
write output
output

So, she will eat 5 apples, 5 yogurts, 5 baked beans, and 4 boiled eggs each day to satisfy her nutrition needs and she will get minimum calories: 1687 kcal from this plan.

--

--