<jupyter_start><jupyter_text>```Business_Statistics = 0.0Calculus = 0.0Computer_Simulation = 1.0Data_Structures = 1.0Forecasting = 0.0Introduction_to_Computer_Programming = 1.0Operations_Research = 1.0Total Cost of the Process =  4.0```<jupyter_code>from pulp import LpVariable, LpMinimize, LpStatus, LpProblem

prob = LpProblem("Minimize_Total_Cost_Of_Weekly_Demands_Selection",LpMinimize)

#Decision Variables
p1w = LpVariable("Production Line 1 Worker", lowBound=0, cat="Integer")
p2w = LpVariable("Production Line 2 Worker", lowBound=0, cat="Integer")
p1s = LpVariable("Production Line 1 Set up", lowBound=0, upBound=1, cat="Integer")
p2s = LpVariable("Production Line 2 Set up", lowBound=0, upBound=1, cat="Integer")

#Objective Function for Minimize Z
prob += 1000*p1s + 2000*p2s + 500*p1w + 900*p2w

#Constraints of Problem
prob += 20*p1w + 50*p2w >= 120, "Glue 1 Unit"
prob += 30*p1w + 35*p2w >= 150, "Glue 2 Unit"
prob += 40*p1w + 45*p2w >= 200, "Glue 3 Unit"

prob += p1w <= 7*p1s, "Line 1 Utilization"
prob += p2w <= 7*p2s, "Line 2 Utilization"

prob.solve()


print("Status:", LpStatus[prob.status])

for v in prob.variables():
    print(v.name, "=", v.varValue)
print("Total Cost of the Process = ", prob.objective.value())<jupyter_output>Status: Optimal
Production_Line_1_Set_up = 1.0
Production_Line_1_Worker = 6.0
Production_Line_2_Set_up = 0.0
Production_Line_2_Worker = 0.0
Total Cost of the Process =  4000.0<jupyter_text>```Production_Line_1_Set_up = 1.0Production_Line_1_Worker = 6.0Production_Line_2_Set_up = 0.0Production_Line_2_Worker = 0.0Total Cost of the Process =  4000.0```<jupyter_code>def const_1 (_list):
  return _list[2] - _list[0] - _list[1]

def const_2 (_list):
  return 17.5 - _list[2]

import numpy as np
from scipy.optimize import minimize

def obj_funx (_list, sign=-1.0):
  p1=_list[0]
  p2=_list[1]
  c=_list[2]

  p1_price=30-p1
  p2_price=50-2*p2

  p1_cost=-3
  p2_cost=-5
  c_cost=-10

  obj_func = p1*(p1_price) + p2*p2_price + p1*p1_cost + p2*p2_cost + c*c_cost
  return sign*obj_func

def const_1 (_list):
  p1=_list[0]
  p2=_list[1]
  c=_list[2]
  return c - p1 - p2

def const_2 (_list):
  c=_list[2]
  return 17.5 - c

variable_list = np.ones(3)

"""
Constraints for COBYLA, SLSQP are defined as a list of dictionaries. Each dictionary with fields:

type:str
Constraint type: ‘eq’ for equality, ‘ineq’ for inequality.

fun:callable
The function defining the constraint.

jac:callable, optional
The Jacobian of fun (only for SLSQP).

args:sequence, optional
Extra arguments to be passed to the function and Jacobian.

Equality constraint means that the constraint function result is to be zero whereas inequality means that it is to be non-negative. Note that COBYLA only supports inequality constraints.
"""
all_const = ([{'type':'ineq', 'fun':const_1}, {'type':'ineq', 'fun':const_2}])

minimize(obj_funx, variable_list, constraints=all_const, method='SLSQP')
#minimize(obj_funx, variable_list, constraints=all_const, method='trust-constr')
#minimize(obj_funx, variable_list, constraints=all_const, method='COBYLA')<jupyter_output><empty_output><jupyter_text>```     fun: -225.3749999995488     jac: array([-10.00002289, -10.00004578,  10.        ]) message: 'Optimization terminated successfully.'    nfev: 26     nit: 5    njev: 5  status: 0 success: True       x: array([ 8.4999866 ,  8.74998869, 17.24997529])```<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.127709431751611, 'fraction_numerical': 0.07176332747510251, 'mean_word_length': 5.2775735294117645, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 15, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '615558', 'license': 'Apache-2.0', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1294, 'n_words': 320, 'path': 'Business Analytics for Managers/hw2/hw2.ipynb', 'repo_name': 'hcipek/Big-Data-Homeworks', 'size': '3414'}