In: Advanced Math
A company makes four types of gourmet chocolate bars.
Chocolate Bar I contains 5 grams of nuts, 5 grams of biscuit, 10
grams of caramel, and 100 grams of chocolate, and sells for $5.40.
Chocolate Bar II contains 10 grams of nuts, 10 grams of biscuit, 10
grams of caramel, and 90 grams of chocolate and sells for $6.25.
Chocolate Bar III contains no nuts, 10 grams of biscuit, 10 grams
of caramel, and 100 grams of chocolate and sells for $5.25.
Chocolate Bar IV contains 20 grams of nuts, no biscuit, 10 grams of
caramel, and 90 grams of chocolate and sells for $7.00. The
ingredient costs are $0.15 per gram of nuts, $0.025 per gram of
biscuit, $0.02 per gram of caramel, and $0.015 per gram of
chocolate. The company has supplier agreements that force them to
order at least 50,000 grams of each ingredient per week (nuts,
biscuit, caramel, and chocolate). However, due to the space in
their warehouse and the expense of holding too much inventory, the
company cannot hold more than 100,000 grams of nuts; 75,000 grams
of biscuits; 85,000 grams of caramel; and 500,000 grams of
chocolate per week. How many chocolate bars of each type should the
company produce each week in order to maximize its weekly
profit?
Let be the number of chocolate bars of type I, II, III, and IV respectively.
Amount of nuts needed
Amount of biscuits needed
Amount of caramel needed
Amount of chocolate needed
Therefore, cost price of nuts
Cost price of biscuits
Cost price of caramel
Cost price of chocolate
Total cost
Total sale
Therefore, profit
We want to maximize the objective function
subject to
You will get maximum at and the maximum profit
Write a Python code as follows:
import numpy as np
from scipy.optimize import minimize
def objective(x):
return x[0]*x[3]*(x[0]+x[1]+x[2])+x[2]
def constraint1(x):
return x[1]
def constraint2(x):
return x[2]
def constraint3(x):
return x[3]
def constraint4(x):
return x[4]
def constraint5(x):
return x[1]+2*x[2]+4*x[4]-10000
def constraint6(x):
return 20000-(x[1]+2*x[2]+4*x[4])
def constraint7(x):
return x[1]+2*x[2]+2*x[3]-10000
def constraint8(x):
return 15000-(x[1]+2*x[2]+2*x[3])
def constraint9(x):
return x[1]+x[2]+x[3]+x[4]-5000
def constraint10(x):
return 8500-(x[1]+x[2]+x[3]+x[4])
def constraint11(x):
return 10*x[1]+9*x[2]+10*x[3]+9*x[4]-5000
def constraint12(x):
return 50000-(10*x[1]+9*x[2]+10*x[3]+9*x[4])
# initial guesses
n = 4
x0 = np.zeros(n)
x0[0] = 0.0
x0[1] = 0.0
x0[2] = 0.0
x0[3] = 0.0
# show initial objective
print('Initial SSE Objective: ' + str(objective(x0)))
# optimize
b = (0.0,8500.0)
bnds = (b, b, b, b)
con1 = {'type': 'ineq', 'fun': constraint1}
con2 = {'type': 'ineq', 'fun': constraint2}
con3 = {'type': 'ineq', 'fun': constraint3}
con4 = {'type': 'ineq', 'fun': constraint4}
con5 = {'type': 'ineq', 'fun': constraint5}
con6 = {'type': 'ineq', 'fun': constraint6}
con7 = {'type': 'ineq', 'fun': constraint7}
con8 = {'type': 'ineq', 'fun': constraint8}
con9 = {'type': 'ineq', 'fun': constraint9}
con10 = {'type': 'ineq', 'fun': constraint10}
con11 = {'type': 'ineq', 'fun': constraint11}
con12 = {'type': 'ineq', 'fun': constraint12}
cons =
([con1,con2,con3,con4,con5,con6,con7,con8,con9,con10,con11,con12])
solution = minimize(objective,x0,method='SLSQP',\
bounds=bnds,constraints=cons)
x = solution.x
# show final objective
print('Final SSE Objective: ' + str(objective(x)))
# print solution
print('Solution')
print('x1 = ' + str(x[0]))
print('x2 = ' + str(x[1]))
print('x3 = ' + str(x[2]))
print('x4 = ' + str(x[3]))