fork download
  1. % Coefficients for the cost function (cost per ton of each ore)
  2. f = [27; 25; 32; 22; 20; 24];
  3.  
  4. % Inequality for impurities (impurity limit constraint)
  5. A_ineq = [40 15 30 50 35 29];
  6.  
  7. % Maximum impurity level (example)
  8. b_ineq = 50; % Set to your impurity limit
  9.  
  10. % Total ton constraint (equality)
  11. Aeq = [1 1 1 1 1 1];
  12. beq = 1;
  13.  
  14. % Metal content requirements
  15. A = [-19 -43 -17 -20 0 -12;
  16. -15 -10 0 -12 -24 -18;
  17. -12 -25 0 0 -10 -16;
  18. -14 -7 -53 -18 -31 -25];
  19.  
  20. % Metal requirement bounds (example; adjust to specific needs)
  21. lb = zeros(6,1); % Lower bounds: non-negative values
  22. ub = ones(6,1); % Upper bounds: cannot exceed 1 ton of each ore (adjust if needed)
  23.  
  24. ctype = "SSSSS"; % 'S' indicates equality or inequality constraints (depending on your problem)
  25. vartype = "CCCCCC"; % 'C' indicates continuous variables
  26.  
  27. % Solve the LP problem using glpk
  28. [x, z, exitflag] = glpk(f, [A; A_ineq], [0; 0; 0; 0; b_ineq], lb, ub, ctype, vartype, 1);
  29.  
  30. % Display the results
  31. disp('Optimal amounts of ores:');
  32. disp(x);
  33. disp('Minimum cost:');
  34. disp(z);
  35.  
Success #stdin #stdout 0.08s 46912KB
stdin
Standard input is empty
stdout
Optimal amounts of ores:
    NA
    NA
    NA
    NA
    NA
    NA
Minimum cost:
  NA