<jupyter_start><jupyter_text>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 >=0The 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?<jupyter_code># 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)<jupyter_output>[[-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.])
{'fraction_non_alphanumeric': 0.14366053169734153, 'fraction_numerical': 0.09611451942740286, 'mean_word_length': 3.773170731707317, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '61094', 'license': 'MIT', 'n_tokens_mistral': 806, 'n_tokens_neox': 700, 'n_words': 260, 'path': 'Wk3/Wk3Tests.ipynb', 'repo_name': 'knightman/MSPA-PREDICT400', 'size': '1956'}