In [ ]:

Goal: Cost minimization of the objective function: C = 18y1 + 20y2 + 25y3

This function represents the total cost for three different products manufactured and sold by our company.

The constraints for this linear program example:

120y1 + 160y2 + 200y3 >= 90000

y1 + y2 + y3 >= 600

y1 + 2y2 >= 350

y1, y2, y3 >=0

The first constraint function gives the total revenue target (at least $90,000 USD). The second limiting function gives the minimum total number of units we want to produce with this batch (at least 600). Also given demand for the first two models is high, we must make at least 350 between y1 and y2 units. Based on past sales, we expect we'll need about twice as many y2 as y1 models. Obviously, y1, y2, y3 all must be >= 0.

How many of each units should we produce to limit minimize our costs?


In [3]:
# Cost objective function is:
# C = 18y1 + 20y2 + 25y3
# Rewrite Constraints:
# Revenue: 120x1 + 160x2 + 200x3 >=90000
# Numbers: x1 + x2 + x3 >= 600
# Condition: x1 + 3x2 >= 350
# x1,x2,x3 >= 0

# coefficients of the objective function
z = [2,21]
#z = [22,44,33]

# left-hand coefficients - tableau matrix
#A = [[1,1,1],[18,20,25]]
A = [[-2,-1],[-1,-2]]

#A = [[-1,-2,-1],[-1,0,-1],[-3,-2,-2]]
print(A)

# right-hand coefficients - 
#b = [500,12000]
b = [-11,-11]
#b = [-3,-3,-8]
print(b)

from scipy.optimize import linprog as lp

x1_bounds = (0,None)
x2_bounds = (0,None)
x3_bounds = (0,None)

res = lp(z, A_ub=A, b_ub=b, bounds=(x1_bounds, x2_bounds), method='simplex', options={"disp": True})
print(res)

#print('\nScipy Optimize Optimal value:', res.fun, '\n x1, x2, x3:', res.x)


[[-2, -1], [-1, -2]]
[-11, -11]
Optimization terminated successfully.
         Current function value: 22.000000   
         Iterations: 3
     fun: 22.0
 message: 'Optimization terminated successfully.'
     nit: 3
   slack: array([ 11.,   0.])
  status: 0
 success: True
       x: array([ 11.,   0.])