Example 4.7 — Diet planning for several classes
Lecture notes (PDF) · Chapter slides (PDF) · App: Diet for several classes
Model: symbolic · Techniques: 4.3 Blending · All the worked models
The problem
Diet planning for several classes
A school canteen needs to determine \(n \in \mathbb{Z}_{\ge 1}\) monthly diets for its classes of students. It is considering \(s \in \mathbb{Z}_{\ge 1}\) possible types of food (e.g., milk, rice, bread, etc.), each containing \(r \in \mathbb{Z}_{\ge 1}\) nutrients (e.g., iron, sodium, etc.). For each food \(i \in \{1, 2, \dots, s\}\), the value \(w_i \in \mathbb{Q}_{> 0}\) represents the cost in euros per kilogram of that food. For each food \(i \in \{1, 2, \dots, s\}\) and each nutrient \(j \in \{1, 2, \dots, r\}\), the value \(g_{ij} \in \mathbb{Q}_{\ge 0}\) denotes the grams of nutrient \(j\) provided by one kilogram of food \(i\). For each diet \(k \in \{1,2,\dots,n\}\) and each nutrient \(j \in \{1, 2, \dots, r\}\), the diet must contain at least \(a_{kj} \in \mathbb{Q}_{\ge 0}\) grams and at most \(b_{kj} \in \mathbb{Q}_{>0}\) grams of that nutrient per month. Additionally, for each food \(i \in \{1, 2, \dots, s\}\), the diets must include at least \(c_i \in \mathbb{Q}_{\ge 0}\) kilograms and at most \(d_i \in \mathbb{Q}_{> 0}\) kilograms of that food per month. The school canteen aims to determine a minimum-cost monthly diets for all classes of students subject to the constraints described above.
Questions
-
Write a Linear Programming (LP) model for the problem. Identify the decisions that must be taken and the corresponding decision variables. Identify and comment the objective function of the model and the constraints. What algorithm can be used to find an optimal solution of the model?
-
Consider now an instance of the problem with \(n=2\) diets, \(s=3\) types of food and \(r=2\) nutrients. These are the other input data:
\(a_{kj}\) \(j=1\) \(j=2\) \(k=1\) \(20\) \(10\) \(k=2\) \(10\) \(20\) \(b_{kj}\) \(j=1\) \(j=2\) \(k=1\) \(40\) \(20\) \(k=2\) \(20\) \(40\) \(i=1\) \(i=2\) \(i=3\) \(w_i\) 5 8 6 \(c_i\) 1 1 0 \(d_i\) 5 4 10 \(g_{ij}\) \(j=1\) \(j=2\) \(i=1\) \(6\) \(2\) \(i=2\) \(2\) \(1\) \(i=3\) \(2\) \(6\) Write the LP model for this instance.
-
Find a feasible solution of the LP model of the instance and accordingly an upper bound on the optimal solution value of the LP model for the instance.
-
Write the dual model of the LP model and the dual model for the instance. Find a feasible solution of the dual model of the instance and accordingly a lower bound on the optimal solution value of the LP model for the instance.
Worked solution
-
We introduce the following \(s \; n\) non-negative variables:
\[ \begin{gathered} x_{ik} = \text{kilograms of food } i \text{ in the diet } k \text{ per month}, \\[0.5ex] \forall i \in \{1,2,\dots,s\}, ~ \forall k \in \{1,2,\dots,n\}. \end{gathered} \]Using these variables, an LP model for the problem reads as follows:
\[\begin{align*} \min ~~ \sum_{i=1}^s \sum_{k=1}^n w_i \, x_{ik} & & \label{sm4-obj} \tag{1a}\\[1ex] \text{subject to} \quad \sum_{i=1}^s g_{ij} \; x_{ik}& \ge a_{kj}, & \forall k \in \{1,2,\dots,n\},~\forall j \in \{1,2,\dots,r\}, \label{sm4-cons1} \tag{1b}\\[1ex] \sum_{i=1}^s g_{ij} \; x_{ik}& \le b_{kj}, & \forall k \in \{1,2,\dots,n\},~\forall j \in \{1,2,\dots,r\}, \label{sm4-cons2} \tag{1c}\\[1ex] \sum_{k=1}^n x_{ik}& \ge c_i, & \forall i \in \{1,2,\dots,s\}, \label{sm4-cons3} \tag{1d}\\[1ex] \sum_{k=1}^n x_{ik}& \le d_i, & \forall i \in \{1,2,\dots,s\}, \label{sm4-cons4} \tag{1e}\\[1ex] x_{ik} &\ge 0, & \forall i \in \{1,2,\dots,s\},~\forall k \in \{1,2,\dots,n\}. \label{sm4-cons5} \tag{1f} \end{align*}\]Description of the objective function and constraints of the LP model:
-
the linear objective function \(\eqref{sm4-obj}\) minimizes the total cost of the diets for all classes of students.
-
the linear constraints \(\eqref{sm4-cons1}\) ensure that, for every diet and every nutrient, the total amount of the nutrient provided by the foods included in that diet satisfies the minimum requirement (\(n \; r\) linear constraints);
-
the linear constraints \(\eqref{sm4-cons2}\) ensure that, for every diet and every nutrient, the total amount of the nutrient provided by the foods included in that diet does not exceed the maximum requirement (\(n \; r\) linear constraints);
-
the linear constraints \(\eqref{sm4-cons3}\) ensure that, for each food, the total quantity distributed across all diets satisfies the minimum requirement (\(s\) linear constraints);
-
the linear constraints \(\eqref{sm4-cons4}\) ensure that, for each food, the total quantity distributed across all diets does not exceed the maximum requirement (\(s\) linear constraints);
-
the linear constraints \(\eqref{sm4-cons5}\) define the variables of the LP model.
The LP model can be solved to optimality, for example, by the simplex algorithm.
-
-
The LP model (1) for the specific instance reads as follows:
\[ \begin{array}{rrcrcrcrcrcrcr} {\min} & {5\,x_{11}} & {+} & {5\,x_{12}} & {+} & {8\,x_{21}} & {+} & {8\,x_{22}} & {+} & {6\,x_{31}} & {+} & {6\,x_{32}} \\[1ex] \text{subject to} & {6\,x_{11}} & & & {+} & {2\,x_{21}} & & & {+} & {2\,x_{31}} & & & {\ge} & {20} \\[1ex] & {2\,x_{11}} & & & {+} & {x_{21}} & & & {+} & {6\,x_{31}} & & & {\ge} & {10} \\[1ex] & & & {6\,x_{12}} & & & {+} & {2\,x_{22}} & & & {+} & {2\,x_{32}} & {\ge} & {10} \\[1ex] & & & {2\,x_{12}} & & & {+} & {x_{22}} & & & {+} & {6\,x_{32}} & {\ge} & {20} \\[1ex] & {6\,x_{11}} & & & {+} & {2\,x_{21}} & & & {+} & {2\,x_{31}} & & & {\le} & {40} \\[1ex] & {2\,x_{11}} & & & {+} & {x_{21}} & & & {+} & {6\,x_{31}} & & & {\le} & {20} \\[1ex] & & & {6\,x_{12}} & & & {+} & {2\,x_{22}} & & & {+} & {2\,x_{32}} & {\le} & {20} \\[1ex] & & & {2\,x_{12}} & & & {+} & {x_{22}} & & & {+} & {6\,x_{32}} & {\le} & {40} \\[1ex] & {x_{11}} & {+} & {x_{12}} & & & & & & & & & {\ge} & {1} \\[1ex] & & & & & {x_{21}} & {+} & {x_{22}} & & & & & {\ge} & {1} \\[1ex] & & & & & & & & & {x_{31}} & {+} & {x_{32}} & {\ge} & {0} \\[1ex] & {x_{11}} & {+} & {x_{12}} & & & & & & & & & {\le} & {5} \\[1ex] & & & & & {x_{21}} & {+} & {x_{22}} & & & & & {\le} & {4} \\[1ex] & & & & & & & & & {x_{31}} & {+} & {x_{32}} & {\le} & {10} \\[1ex] & {x_{11},} & & {x_{12},} & & {x_{21},} & & {x_{22},} & & {x_{31},} & & {x_{32}} & {\ge} & {0} \end{array} \] -
For example, by setting:
\[ \bar{x}_{11}=4,~~\bar{x}_{12}=1,~~\bar{x}_{21}=2,~~\bar{x}_{22}=1,~~\bar{x}_{31}=0,~~\bar{x}_{32}=3 \]we have a feasible solution. The objective function value of this feasible solution is:
\[ \sum_{i=1}^s w_i \sum_{k=1}^n \, \bar x_{ik} = 5 \cdot 4 + 5 \cdot 1 + 8 \cdot 2 + 8 \cdot 1 + 6 \cdot 0 + 6 \cdot 3 = 67 \]accordingly 67 is an upper bound on the optimal solution value of the LP model (1). So, for this instance, we have:
\[ z(~ LP~) ~\le~ 67 \] -
By using
-
a non-negative variable \(\alpha_{kj}\) for each constraint \(\eqref{sm4-cons1}\) (\(k \in \{1,2,\dots,n\},j \in \{1,2,\dots,r\}\))
-
a non-positive variable \(\beta_{kj}\) for each constraint \(\eqref{sm4-cons2}\) (\(k \in \{1,2,\dots,n\},j \in \{1,2,\dots,r\}\))
-
a non-negative variable \(\gamma_i\) for each constraint \(\eqref{sm4-cons3}\) (\(i \in \{1,2,\dots,s\}\))
-
a non-positive variable \(\delta_i\) for each constraint \(\eqref{sm4-cons4}\) (\(i \in \{1,2,\dots,s\}\))
the dual of the LP model (1) reads as follows:
-
- The dual model (2) for the instance reads as follows:
-
For example, by setting:
\[ \bar\alpha_{11}=\bar\alpha_{12}=\bar\alpha_{21}=\bar\alpha_{22}= \bar\beta_{11}=\bar\beta_{12}=\bar\beta_{21}=\bar\beta_{22}=\bar\delta_{1}=\bar\delta_{2}=\bar\delta_{3}=0 \]and by setting:
\[ \bar \gamma_1=\min\{5,5\}=5,~~\bar \gamma_2=\min\{8,8\}=8,~~\bar \gamma_3=\min\{6,6\}=6 \]we have a feasible dual solution.
The objective function value of this feasible dual solution is:
\[ \sum_{k=1}^n \sum_{j=1}^r a_{kj} \; \bar \alpha_{kj} + \sum_{k=1}^n \sum_{j=1}^r b_{kj} \;\bar \beta_{kj} +\sum_{i=1}^s c_i \: \bar \gamma_i +\sum_{i=1}^s d_ i\: \bar \delta_i = \]\[ = 20 \cdot 0 + 10 \cdot 0 + 10 \cdot 0 + 20 \cdot 0 + 40 \cdot 0 + 20 \cdot 0 + 20 \cdot 0 + 40 \cdot 0 + 1 \cdot 5 + 1 \cdot 8 + 0 \cdot 6 + 5 \cdot 0 + 4 \cdot 0 + 10 \cdot 0= 13 \]Accordingly \(13\) is a lower bound on the optimal solution value of the model. So, for this instance, we have:
\[ 13 ~\le~ z(~ LP~) ~\le~ 67 \]
Shadow prices of the instance
The shadow price of a constraint is the change of the optimal value for one more unit of its right-hand side, as long as the optimal basis does not change. For the instance of this page (optimal value \(\frac{757}{16}\)) they are, computed with Gurobi:
| Constraint | Shadow price |
|---|---|
| diet 1, nutrient 1, minimum (\(a_{11}\)) | \(\frac{9}{16}\) €/g |
| diet 1, nutrient 2, minimum (\(a_{12}\)) | \(\frac{13}{16}\) €/g |
| diet 2, nutrient 1, minimum (\(a_{21}\)) | \(\frac{9}{16}\) €/g |
| diet 2, nutrient 2, minimum (\(a_{22}\)) | \(\frac{13}{16}\) €/g |
| food 2, minimum (\(c_2\)) | \(\frac{97}{16}\) €/kg |
The other 9 constraints have a zero shadow price.
Interactive lab
The app solves this model in the browser, with the data of the example: the sliders change the data and the simplex method recomputes the optimal solution. It also opens full page in the interactive lab: Diet for several classes.