LP 3: Larger-Scale LP Models

Packages Used: No new packages are used in this notebook.

It is convenient when creating larger-scale LP models to use arrays for specifying individual scalar decision variables and coefficients instead of individual scalar values. Set notation can be used to indicate iteration over a set of array indices as long as the order in which the iteration occurs does not matter; when order is important, sequences should be used.

Ex 1: Coffee and Peppers Arbitrage Opportunity (cont. from Ex 1 in LP 2)

Everything is the same except that n-element arrays will be used instead of individual scalars for the sale price, purchase price, and purchase quantity, where n is the number of items purchased and $ N = \{ 1, \dots, n \}$$ = \{ 1, 2 \} $ is the set of array indices:

$ \begin{eqnarray*} \quad \mbox{Maximize} \quad \sum_{i \in N} \left( p_i - c_i \right) x_i \\ \quad \mbox{subject to} \quad \sum_{i \in N} c_i x_i &\le& 120 &\quad\mbox{:Budget constraint}\\ \sum_{i \in N} x_i &\le& 30 &\quad\mbox{:Weight constraint}\\ x_i &\ge& 0 \mbox{,} \end{eqnarray*} $

which can be then be formulated in JuMP as follows:

If both items have different maximum order quantity restrictions, modeled as UBs of 40 and 10:

Ex 2: Multi-Item Arbitrage Opportunity (cont. from Ex 1)

Continuing with Ex 1, if there were three other items avaiable in addition to coffee and peppers:

Ex 3: Production Mix

Three different chemical products are produced using four different raw materials as input. Up to 100, 40, and 80 liters of each product can be sold for \$10, 20, and 30 per L, respectively. Producing 10 liters of the first product requires 2, 3, and 5 L of inputs 1-3, respectively; 10 liters of the second requires 7 and 3 L of inputs three and four; 5 liters of the third product requires 2 L of inputs one and two and 1 L of input four. Up to 40, 20, 30, and 80 L of inputs 1-4, respectively, are available at the cost of \\$4, 3, 5, and 1 per L. Determine how many liters of each product should be produced.

Solution: First step is to make the fixed proportions commensurate by determining the quantity of each input needed to produce 1 L of each product:

Next, the following LP is formulated:

$ \begin{eqnarray*} \quad \mbox{Maximize} \quad \sum_{i \in N} p_i x_i &-& \sum_{j \in M} c_j \sum_{i \in N} a_{ij} x_i \\ \quad \mbox{subject to} \quad \sum_{i \in N} a_{ij} x_i &\le& b_j \mbox{,} \quad j \in M \\ 0 \le x_i &\le& u_i \mbox{,} \end{eqnarray*} $

where the decision variables $x_i, p_i, u_i, i \in N$, represent the production (L), sale price (\$/L), and upper bound (L) of each product in the set $N$ of products; $c_j, bj, j \in M$, represent the cost (\\$/L) and upper bound (L) of each input in the set $M$ of inputs; and $a{ij}$ represents the liters of input j required to produce one liter of product i.

Note: In the above model, @constraint(model, con[j = M], is used to label each constraint as con1 to con4 so that they can be referenced; for example (see below), each constraint is referenced to determine its "shadow price."

Sensitivity Analysis

In order to provide more information for sensitivity analysis of the solution, the following additional data can be reported:

or, equivalently:

Since the upper bound of 20 for input 2 is binding, increasing the bound should increase profits; for example, increasing the bound to 21 increases profit by \$67.50, from \\$1998 to \$2065.50. This is also reflected in the shadow price of each constraint:

Reading Matrix Data from a File

The following can be used to read the matrix A from the CSV file LP-3-Data.csv:

0.2,0.3,0.5,0
0,0,0.7,0.3
0.4,0.4,0,0.2

Ex 4: Employee Staffing

Question: Wally World adventure park is deciding how many full-time employees to hire for the upcoming season. Each full-time employee should work for five consecutive days each week, followed by two days off. They have estimated that their staffing requirements for Sunday through Saturday each week are 150, 160, 110, 175, 130, 150, and 190 full-time employees, respectively. Additional part-time staff will be hired for peak periods during the season. Determine the minimum number of full-time employees needed.

Solution approach: The decision variable $x_i$ represents the number of employees that start their five consecutive days of work on day $i$, for $i = 1$ corresponding to Sunday. Since consecutive days will be defined, sequences of indices $i$ for $x_i$ will be used instead of set notation. The most difficult part of formulation a model is getting the sequences of $x_i$'s to wrap around day 7 (Saturday) to continue at day 1 (Sunday). The basic model will be

$ \begin{eqnarray} \quad \mbox{Minimize} \quad \sum_{i = 1}^{7} x_i \\ \quad \mbox{subject to} \quad \sum_{\mbox{j-start ?}}^{\mbox{j-end ?}} x_{\mbox{[x-index ?]}} &\ge& b_i \mbox{,} &\quad i = 1, \dots, 7 \\ x_i &\ge& 0 \mbox{.} \end{eqnarray} $

Since employees should work five consectitive days, the only employees not able to work day $i$ would be those that start on days $i + 1$ and $i + 2$, the summation starting limit ("j-start") should be $i + 3$, or 3 days in the future, and the ending limit ("j-end") $i + 3 + (5 - 1)$ = $i + 7$ days in the future. Since $i > 5 \implies $$j > 7$, the index for $x$ ("x-index") should be $j - 7 \left\lfloor\frac{j - 1}{7} \right\rfloor$ so that, for example, $j = 8 \implies $$ 8 - 7 \left\lfloor\frac{7}{7} \right\rfloor = $$1$. It is a good idea to test the indices, where k is the x-index:

The complete model formulation is then:

$ \begin{eqnarray} \quad \mbox{Minimize} \quad \sum_{i = 1}^{7} x_i \\ \quad \mbox{subject to} \quad \sum_{j = i+3}^{i+7} x_{j\,-\,7 \left\lfloor\frac{j - 1}{7} \right\rfloor} &\ge& b_i \mbox{,} &\quad i = 1, \dots, 7 \\ x_i &\ge& 0 \mbox{,} \end{eqnarray} $

which can be then be formulated in JuMP as follows:

In general, the solution will not be integer-valued. As a rule of thumb, rounding the (continuous) decision variables in an LP solution when their values are greater than 20 will not result in too much error, but for values less than 20, the error can be significant, and a MILP model should be used with decision variables restricted to being an integer. In this example, taking the ceiling of any fractional values will ensure that the solution remains feasible, but at the cost of increasing the number of employees required; instead, the MILP model will make the correct internal decisions with respect to rounding that will result in the least possible increase in the number of employees.

Ex 5: LP to Minimize the Sum of Absolute Deviations

This is the same problem we solved using univariate nonlinear optimization in NL Opt 1.

Instead of as a MP, this unconstrained nonlinear optimization problem is represented mathematically as follows:

$ \quad\begin{eqnarray} x^* &=& \mathrm{arg}\underset{x}{\operatorname{min}} \left\{ \sum_{i=1}^{n} \lvert p_i - x \rvert : L\!B \leq x \leq U\!B \right\} \\ T\!D^* &=& \sum_{i=1}^{n} \lvert p_i - x^* \rvert \end{eqnarray}$

It cannot be directly formulated as an LP because of the absolute values used to determine the distances. This can be formulated as an LP using a change of variables.

Absolute Value: Use a change of variables to represent absolute values in an MP.

The variables $r_i \ge 0$ and $s_i \ge 0$ are introduced to represent the cases where the unrestricted $x$ is to the right or left of $p_i$, respectively:

$ \quad\left.\begin{matrix} x \ge p_i: r_i = x - p_i \mbox{ and } s_i = 0 \\ x < p_i: s_i = p_i - x \mbox{ and } r_i = 0 \end{matrix} \right\} \implies r_i + s_i = \lvert x - p_i \rvert,\, x - r_i + s_i = p_i, \mbox{ and } r_i, s_i \ge 0 $,

where each $r_i + s_i$ is a term in the objective function, each $x - r_i + s_i = p_i$ a constraint, and $r_i, s_i \ge 0$ are lower-bounds on the new variables.