Python Day 6:
Linear Optimization with Paper Company
Last time we did a Pirelli Glass Linear Optimization, it considered a simple problem, because it has only 2 variables.What should we do if there are more variables and with much more complexed constrain systems?
[caption id="attachment_1573" align="alignnone" width="750"] imagediwou / Pixabay[/caption]
Problem:
Nancy Grant is the owner of Coal Bank Hollow Recycling company, there is two Recycling Process.
Recyle ProcessMaterial
- 70 tons of newspaper
- 50 tons of mixed paper
- 30 tons of white office paper
- 40 tons of cardboard
Production:
- 60 newsprint pulp
- 40 packaging paper pulp
- 50 print stock pulp
Let's use the linear optimation method to minimize the recycle uses and find the most efficient way for recycling.
Process Flow Chart
Process Flow ChartSolution
Linear Model
MInmize total Cost
General Constraints:
all
Raw Material constraints :
- newspaper :
- mixed paper
- White office paper
- cardboard
Recycling Processes Constraints:
-
Recycle Method 1:
-
Recycle Method 2:
Production Paper Constraints:
- newsprint :
- packaging paper
- stock paper
Python Code:
import numpy as np
from scipy.optimize import linprog
from numpy.linalg import solve
# Note we need to multiply "-1" in order to change the ">=" sign
A_ub= np.array([
[1,1,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,1,1,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,1,1,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,1,1,0,0,0,0,0,0],
[-0.95,0,-0.8,0,-0.95,0,-0.75,0,1,1,1,0,0,0],
[0,-0.85,0,-85,0,-0.9,0,-0.85,0,0,0,1,1,1],
[0,0,0,0,0,0,0,0,-0.95,0,0,-0.9,0,0],
[0,0,0,0,0,0,0,0,0,-0.9,0,0,-0.95,0],
[0,0,0,0,0,0,0,0,0,0,-0.9,0,0,-0.95]
])
b_ub=np.array([70,50,30,40,0,0,-60,-40,-0])
c=np.array([13, 12, 11,13, 9, 10, 13, 14, 5, 6, 8, 6, 8,7])
best = linprog(c, A_ub= A_ub, b_ub=b_ub,
bounds=(0, None))
best.fun
best.x
Output:
From the result, we can see minimal cost is 1129.94 Dollars, with 1.89 Mixed paper goes to Recycle process 2 and print 66.67 ton newsprint plus 42.1 ton Packing paper and 52.6 ton Stock Paper
1129.94
array([ 0\. , 0\. , 0\. , 1.89886481,
0\. , 0\. , 0\. , 0\. ,
0\. , 0\. , 0\. , 66.66666667,
42.10526316, 52.63157895])
Note: since this is more than 3 dimensions, so we could not visualize it.
网友评论