Supplying toilet papers to Walmart stores

Suppose you are the distribution manager overseeing all the Walmart gorcery stores in California. There are $m$ factories producing toilet papers in the region, which need to be supplied to $n$ Walmart stores in the state.

The geographic locations (latitudes and longitudes) of the factories and stores: $x_{i}^{\text{factory}}\in\mathbb{R}^{2}$ and $x_{j}^{\text{store}}\in\mathbb{R}^{2}$ are known, for all $i=1,...,m$, and $j=1,...,n$. At present, Walmart uses its own trucks for this delivery which incur $C_{ij}$ dollars (for fuel cost, travel time etc.) to transport per unit mass of toilet paper from the $i$th factory to the $j$th store. A reasonable model is that $C_{ij}$ equals to the squared Euclidean distance:

$$C_{ij} = \|x_{i}^{\text{factory}} - x_{j}^{\text{store}}\|_{2}^{2}, \quad\forall\;(i,j)\in\{1,...,m\}\times\{1,...,n\}.$$

This defines a cost matrix $C \equiv [C_{ij}]$ of size $m\times n$. The $i$th factory has a fixed (normalized) production capacity $\alpha_{i}>0$. The $j$th store has a fixed (normalized) storage capacity $\beta_{j}>0$. Here "normalized" means that $\sum_{i}\alpha_{i}=\sum_{j}\beta_{j}=1$. Toilet papers cannot be stored elsewhere, i.e., all the toilet papers produced must be supplied to the stores.

(a) [12 + 2 + 2 + (1 + 3) = 20 points] Primal problem

As the distribution manager, your job is to decide what is the cheapest way to transport the toilet papers from the factories to the stores. Suppose you decide that $P_{ij}$ amount of toilet paper mass (say in pound or lb) should be transported from the $i$th factory to the $j$th store. Obviously, $P_{ij} \geq 0$ for all $(i,j)\in\{1,...,m\}\times\{1,...,n\}$.

(i) Taking the matrix $P \equiv [P_{ij}]$ of size $m\times n$ as the decision variable, clearly set up the optimization problem to be solved. The input parameters for this optimization problem should be the $m\times n$ matrix $C$, the $m\times 1$ vector $\alpha$, and the $n\times 1$ vector $\beta$.

Hint: the Frobenius inner product $\langle C, P\rangle = \text{trace}(C^{\top}P)$. Also, you may find it helpful to use the column vector of ones $\mathbf{1}_{m}, \mathbf{1}_{n}$.

(ii) Argue why the optimization problem above is convex in $P$.

(iii) What is the dimensionality of this problem, that is, it is a convex optimization problem in how many variables with how many constraints?

(iv) What type of convex optimization problem is it? To support your answer, explain the geometric interpretation of the objective and the constraints.

Solution for part (a):

(i) Since the total cost is $\langle C, P\rangle = \sum_{i=1}^{m}\sum_{j=1}^{n} C_{ij} P_{ij}$ dollars, the optimization problem becomes:

\begin{align*} &\underset{P\in\mathbb{R}^{m\times n}}{\text{minimize}}\quad \sum_{i=1}^{m}\sum_{j=1}^{n} C_{ij} P_{ij}\\ &\text{subject to} \quad P_{ij} \geq 0 \quad\forall\:(i,j)\in\{1,...,m\}\times\{1,...,n\},\\ & \qquad\qquad \sum_{j=1}^{n}P_{ij} = \alpha_{i} \quad\forall\:i\in\{1,...,m\},\\ & \qquad\qquad \sum_{i=1}^{n}P_{ij} = \beta_{j} \quad\forall\:j\in\{1,...,n\}, \end{align*}

or in matrix form: \begin{align*} &\underset{P\in\mathbb{R}^{m\times n}}{\text{minimize}}\quad \langle C, P\rangle\\ &\text{subject to} \quad P \geq 0 \quad\text{(elementwise)},\\ & \qquad\qquad P\mathbf{1}_{n} = \alpha,\\ & \qquad\qquad P^{\top}\mathbf{1}_{m} = \beta. \end{align*}

(ii) The objective is linear, and hence convex in $P$. All the constraints are also linear in matrix variable $P$. The set $\mathbb{R}^{m\times n}$ is affine. Therefore, the optimization problem in part (i) is convex.

(iii) Since $P$ has $mn$ elements, this is an optimization problem in $mn$ variables with $mn$ inequality constraints, and $m+n$ equality constraints. So all in all, an optimization problem in $mn$ variables with $m+n+mn$ constraints.

(iv) The problem derived in part (i) is an LP.

This is because the objective is linear in $P$, and the constraint set is an intersection of $mn$ halfspaces with $m+n$ hyperplanes, i.e., a polyhedron.

(b) [20 points] Numerical solution

Fix $m=20, n=167$. Write a code in MATLAB/Python/Julia to load the input data from CANVAS Files section: HW problems and solutions: alpha.txt, beta.txt, x_stores.txt, x_factories.txt, and use cvx/cvxpy/Convex.jl in the same code to solve the optimization problem in part (a). Report the numerically computed optimal value (minimized cost) and submit your code.

Remark: It is recommended (but not required) that in your code, you also check if your optimal solution obtained from using cvx/cvxpy/Convex.jl matches with linprog in MATLAB, or with scipy.optimize.linprog in Python.

Solution for part (b):

For numerical computation, we need the recast our optimization problem derived in part (a) in standard vector LP form. To do so, let $c:=\operatorname{vec}(C)$, $p:=\operatorname{vec}(P)$, and $$A := \begin{pmatrix} \mathbf{1}_{n}^{\top}\otimes I_{m}\\ I_{n} \otimes \mathbf{1}_{m}^{\top} \end{pmatrix}\in\mathbb{R}^{(m+n)\times mn}, \qquad b:= \begin{pmatrix} \alpha\\ \beta \end{pmatrix}\in\mathbb{R}^{m+n}, $$ where $\operatorname{vec}(\cdot)$ denotes the column vectorization, and $\otimes$ denotes the Kronecker product. Then we can rewrite the LP in part (a) as

\begin{align*} &\underset{p\in\mathbb{R}^{mn}}{\text{minimize}}\quad \langle c, p\rangle\\ &\text{subject to} \quad p \geq 0 \quad\text{(elementwise)},\\ & \qquad\qquad Ap = b, \end{align*}

where $\langle c, p\rangle = c^{\top}p$ (the vector inner product).

The numerically computed minimum cost is $$p^{*}_{\text{cvx}} = 0.057986948821812.$$ The same via MATLAB linprog is $$p^{*}_{\text{MATLAB}} = 0.057986941579042.$$

These numerical values were obtained by running the code $\texttt{AM229F20HW6.m}$ in MATLAB, posted in CANVAS File section, inside the folder "HW problems and solutions".

(c) [(10 + 10 + 10) + ( 8 + 2 ) = 40 points] Duality

(i) Starting from the convex optimization problem in matrix variable $P$ deduced in part (a), derive the Lagrangian $L$, the Lagrange dual function $g$, and the dual optimization problem.

Hint: To handle the inequality constraint $P \geq 0$ (elementwise), introduce a matricial Lagrange multiplier $\Lambda$ of size $m\times n$.

(ii) Numerically solve the dual problem using cvx/cvxpy/Convex.jl in the same code in part (b). So your submitted code should solve both the primal and dual problems separately. Report the numerically computed optimal value of the dual problem, and explain what you observe.

Solution for part (c):

(i) Following the hint provided, the Lagrangian is $$L(P,\Lambda,\nu_{1},\nu_{2}) = \langle C, P\rangle + \langle\Lambda, -P\rangle + \langle \nu_{1}, P\mathbf{1}_{n}-\alpha\rangle + \langle \nu_{2},P^{\top}\mathbf{1}_{m}-\beta\rangle.$$

The Lagrange dual function, by definition, is

$$g(\Lambda,\nu_{1},\nu_{2}) = \underset{P\in\mathbb{R}^{m\times n}}{\sup}L(P,\Lambda,\nu_{1},\nu_{2}).$$

Using that trace is invariant under cyclic permutation, we write $\nu_{1}^{\top}P\mathbf{1}_{n} = \operatorname{trace}(\mathbf{1}_{n}\nu_{1}^{\top}P)$, and that $\nu_{2}^{\top}P^{\top}\mathbf{1}_{m} = \operatorname{trace}(\nu_{2}^{\top}P^{\top}\mathbf{1}_{m}) = \operatorname{trace}(\mathbf{1}_{m}^{\top}P\nu_{2}) = \operatorname{trace}(\nu_{2}\mathbf{1}_{m}^{\top}P)$, where the last but one equality used that trace is also invariant under matrix transpose.

Therefore, we obtain \begin{align*} g(\Lambda,\nu{1},\nu{2}) &= \underset{P\in\mathbb{R}^{m\times n}}{\sup} \operatorname{trace}\left((C^{\top}-\Lambda^{\top} + \mathbf{1}{n}\nu{1}^{\top} + \nu{2}\mathbf{1}{m}^{\top})P\right) - \nu{1}^{\top}\alpha - \nu{2}^{\top}\beta\ &= \begin{cases}

  • \nu{1}^{\top}\alpha - \nu{2}^{\top}\beta \quad \text{if} \quad C-\Lambda + \nu{1}\mathbf{1}{n}^{\top} + \mathbf{1}{m}\nu{2}^{\top} = \mathbf{0}_{m\times n},\ +\infty \quad \text{otherwise}.\end{cases} \end{align*}

Consequently, the dual problem is \begin{align*} &\underset{\Lambda\in\mathbb{R}^{m\times n},\nu_1\in\mathbb{R}^{m},\nu_2\in\mathbb{R}^{n}}{\max} -\nu_{1}^{\top}\alpha - \nu_{2}^{\top}\beta\\ &\quad\text{such that}\quad C-\Lambda + \nu_{1}\mathbf{1}_{n}^{\top} + \mathbf{1}_{m}\nu_{2}^{\top} = \mathbf{0}_{m\times n},\\ & \qquad\qquad\qquad \Lambda \geq 0 \quad\text{(elementwise)}. \end{align*} We notice that the dual problem is also LP, as expected.

(ii) The same code posted in CANVAS (as in part(b)) also solves the dual LP via cvx. The computed solution was

$$d^{*}_{\text{cvx}} = 0.057986941767268.$$

We see that $d^{*}$ matches with $p^{*}$ upto 8 significant digits. This is expected since theoretically LPs have zero duality gap, i.e., $d^{*}=p^{*}$.

(d) [20 points] To contract or not

A Silicon Valley startup Brand New Truck Company (BNTC) has approached you, the Walmart distribution manager in California, claiming that they can lower the cost of transport for you if you give them the contract to transport the toilet papers from the $m$ factories to the $n$ Walmart stores. Their business model is that they actually do not charge for the transportation process, but only charge variable per unit mass loading cost $\eta_{1}\in\mathbb{R}^{m}$, and variable per unit mass unloading cost $\eta_{2}\in\mathbb{R}^{n}$. They also guarantee you that

$$\left(\eta_{1}\right)_{i} + \left(\eta_{2}\right)_{j} \leq C_{ij} \quad\forall\;(i,j)\in\{1,...,m\}\times\{1,...,n\},$$

and hence, BNTC argues that Walmart cannot loose money by awarding them the contract for toilet paper transport.

To maximize revenue, BNTC determines $(\eta_{1},\eta_{2})$ by solving

\begin{align*} \underset{(\eta_{1},\eta_{2})}{\text{maximize}}\quad &\eta_{1}^{\top}\alpha + \eta_{2}^{\top}\beta\\ \qquad\qquad\text{s.t.}\quad &\eta_{1}\mathbf{1}_{n}^{\top} + \mathbf{1}_{m}\eta_{2}^{\top} \leq C \quad\text{(elementwise).} \end{align*}

Is contracting the transport to BNTC profitable for Walmart? Use the duality results in part (c) to mathematically explain your answer.

Solution for part (c):

No, by awarding the contract to BNTC, Walmart cannot do any better than what they are doing now.

In fact, by awarding the contract, Walmart will incur the exact same cost as they are incurring now. To see why, let us start from the dual LP in part (b), and let $\eta_1 := -\nu_1$, $\eta_2 := -\nu_2$. Then the dual objective reduces to the BNTC revenue maximization objective. We can also combine the two constraints in the dual LP as the single constraint:

$$C - \eta_{1}\mathbf{1}_{n}^{\top} - \mathbf{1}_{m}\eta_{2}^{\top} = \Lambda \geq 0 \:\text{(elementwise)}\:\Rightarrow \: C \geq \eta_{1}\mathbf{1}_{n}^{\top} + \mathbf{1}_{m}\eta_{2}^{\top},$$

where we used $\eta_1 := -\nu_1$, $\eta_2 := -\nu_2$. But this combined inequality is exactly the fesability constraint in the revenue maximization problem of BNTC.

Therefore, the revenue maximization problem of BNTC is exactly the dual LP in part (b), and by strong duality for LPs, its optimal value must be equal to the primal minimum: the transportation cost Walmart is currently incurring using its own trucks.