% Coefficients for the cost function (cost per ton of each ore)
f = [27; 25; 32; 22; 20; 24];
% Metal content inequalities (if there are specific minimum content requirements)
Aeq = [1 1 1 1 1 1]; % Equality constraint: sum of ore = 1 ton
beq = 1; % Total of ores should sum to 1 ton
% Impurities constraint (less than or equal to 50%)
A_ineq = [40 15 30 50 35 29]; % Impurities
b_ineq = 50; % Impurity threshold
% Metal content constraints (optional: set minimum required metal content if needed)
A = [-19 -43 -17 -20 0 -12;
-15 -10 0 -12 -24 -18;
-12 -25 0 0 -10 -16;
-14 -7 -53 -18 -31 -25];
% Lower bounds and upper bounds for decision variables
lb = zeros(6,1); % No negative ore amounts
ub = ones(6,1); % Each ore amount is between 0 and 1 ton
% Solve the LP problem using glpk
ctype = "S"; % Equality constraint for total tonnage
vartype = "C"; % Continuous variables
% Now run the solver
[x, z, exitflag] = glpk(f, [A_ineq; Aeq], [b_ineq; beq], lb, ub, ctype, vartype, 1);
% Check if a valid solution is found
if exitflag == 180
disp('Optimal amounts of ores:');
disp(x);
disp('Minimum cost per ton of alloy:');
disp(z);
else
disp('No feasible solution found');
end
JSBDb2VmZmljaWVudHMgZm9yIHRoZSBjb3N0IGZ1bmN0aW9uIChjb3N0IHBlciB0b24gb2YgZWFjaCBvcmUpCmYgPSBbMjc7IDI1OyAzMjsgMjI7IDIwOyAyNF07CgolIE1ldGFsIGNvbnRlbnQgaW5lcXVhbGl0aWVzIChpZiB0aGVyZSBhcmUgc3BlY2lmaWMgbWluaW11bSBjb250ZW50IHJlcXVpcmVtZW50cykKQWVxID0gWzEgMSAxIDEgMSAxXTsgICAlIEVxdWFsaXR5IGNvbnN0cmFpbnQ6IHN1bSBvZiBvcmUgPSAxIHRvbgpiZXEgPSAxOyAgICAgICAgICAgICAgICUgVG90YWwgb2Ygb3JlcyBzaG91bGQgc3VtIHRvIDEgdG9uCgolIEltcHVyaXRpZXMgY29uc3RyYWludCAobGVzcyB0aGFuIG9yIGVxdWFsIHRvIDUwJSkKQV9pbmVxID0gWzQw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