5.5. Linear Programming#
Linear programming is the minimization (or maximization) of a linear objective subject to linear constraints. There are several widely adopted schemes for representing linear programming problems. Here we adopt a scheme corresponding where the linear objective is written in terms of decision variables \(x_1, x_2, \ldots, x_N\) as
subject to
5.5.1. Matrix/Vector format#
The notation can be simplified by adopting a matrix/vector formulation where
subject to
where \(c\), \(A_{ub}, b_{ub}\), and \(A_{eq}, b_{eq}\), are vectors and matrices of coefficients constructed from the linear expressions given above.
5.5.2. Example 19.3: Refinery Blending Problem#
The decision variables are
Variable |
Description |
Units |
---|---|---|
\(x_1\) |
crude #1 |
bbl/day |
\(x_2\) |
crude #2 |
bbl/day |
\(x_3\) |
gasoline |
bbl/day |
\(x_4\) |
kerosine |
bbl/day |
\(x_5\) |
fuel oil |
bbl/day |
\(x_6\) |
residual |
bbl/day |
The overall objective is to maximize profit
where the financial components are given by
Combining these terms, the objective is to maximize
The material balance equations are
Production limits
from scipy.optimize import linprog
c = [49, 32, -72, -48, -42, -20]
A_ub = [[0, 0, 1, 0, 0, 0],
[0, 0, 0, 1, 0, 0],
[0, 0, 0, 0, 1, 0]]
b_ub = [24000, 2001, 6000]
A_eq = [[0.80, 0.44, -1, 0, 0, 0],
[0.05, 0.10, 0, -1, 0, 0],
[0.10, 0.36, 0, 0, -1, 0],
[0.05, 0.10, 0, 0, 0, -1]]
b_eq = [0, 0, 0, 0]
results = linprog(c, A_ub, b_ub, A_eq, b_eq)
results
p0 = 573517.24
print('additional profit', -results.fun - p0)
additional profit 175.035862069
print(results.message)
if results.success:
for k in range(len(results.x)):
print('x[{0:2d}] = {1:7.1f} bbl/day'.format(k+1, results.x[k]))
Optimization terminated successfully.
x[ 1] = 26199.3 bbl/day
x[ 2] = 6910.3 bbl/day
x[ 3] = 24000.0 bbl/day
x[ 4] = 2001.0 bbl/day
x[ 5] = 5107.7 bbl/day
x[ 6] = 2001.0 bbl/day