Hi I am trying to solve the following problem:
I have multiple category sets of food A,B,..., each with nutritional information encoded in a vector x_a1,x_a2,...,x_b1,x_b2,.... I also have a vector, y, which encodes the target nutrition values. I want to select a combination of foods from the food sets such that the difference between the target nutrition y and the sum of the selected food nutrition vectors is minimized:
min_x ||x−y||_2
where x is the element-wise sum of all selected foods
x = ∑_i(x_{ij})
for i∈{A,B,C,...} and j∈{1,2,3,...}.
To solve this with linear programming I formulated it in the following way - Let Z be a m by n matrix for n foods and m nutrients and w_j is a vector of binary values. I am trying to minimize the L1 norm:
sum_i | sum_j(Z_{ij}w_j) - y |
linearly by introducing slack and nonnegative surplus variables t_i and s_i, respectively:
min sum_i(s_i + t_i)
s.t. sum_j(Z_{ij}w_j) - s_i + t_i = y for all i
sum_j(w_j) >= 1 for j∈{A,B,C,...}
Can someone point me in the direction for how I would formulate this in scipy?