by Fedor Iskhakov, ANU
Description: Linear programming and optimal transport problems.
Optimal transport problem
Minimum cost of transporting a set of goods from $ m $ origins to $ n $ destinations, where cost of transporting from origin $ i $ to destination $ j $ is given by $ c_{ij} $
Linear programming = optimizing linear function on convex polyhedron
$$ \max(c \cdot x) \text{ subject to } Ax \le b $$Note that $ Ax \le b $ includes as special cases
Let $ x $ and $ y $ denote production of goods A and B by some firm. The production technology is restricted to have
$$ \begin{cases} y - x &\le& 4, \\ 2x - y &\le&8, \end{cases} $$And the resource constraint is given by $ x + 2y \le 14 $
Let profits be given by $ \pi(x,y) = y + 2x $
Adding the natural non-negativity constraints, in matrix notation we have
$$ \max(c^{T}x) \text{ subject to } Ax \le b $$$$ c= \begin{pmatrix} 2 & 1 \end{pmatrix},\;\; A= \begin{pmatrix} -1 & 1 \\ 2 & -1 \\ 1 & 2 \\ -1 & 0 \\ 0 & -1 \\ \end{pmatrix},\;\; b= \begin{pmatrix} 4\\ 8\\ 14\\ 0\\ 0 \end{pmatrix} $$import numpy as np
from scipy.optimize import linprog
c = np.array([-2,-1])
A = np.array([[-1,1],[2,-1],[1,2],[-1,0],[0,-1]])
b = np.array([4,8,14,0,0])
def outf(arg):
print('iteration %d, current solution %s'%(arg.nit,arg.x))
linprog(c=c,A_ub=A,b_ub=b,method='simplex',callback=outf)
iteration 0, current solution [0. 0.] iteration 1, current solution [4. 0.] iteration 2, current solution [6. 4.] iteration 3, current solution [6. 4.] iteration 3, current solution [6. 4.]
con: array([], dtype=float64) fun: -16.0 message: 'Optimization terminated successfully.' nit: 3 slack: array([6., 0., 0., 6., 4.]) status: 0 success: True x: array([6., 4.])