fork download
  1. % Coefficients for the cost function (cost per ton of each ore)
  2. f = [27; 25; 32; 22; 20; 24];
  3.  
  4. % Metal content inequalities (if there are specific minimum content requirements)
  5. Aeq = [1 1 1 1 1 1]; % Equality constraint: sum of ore = 1 ton
  6. beq = 1; % Total of ores should sum to 1 ton
  7.  
  8. % Impurities constraint (less than or equal to 50%)
  9. A_ineq = [40 15 30 50 35 29]; % Impurities
  10. b_ineq = 50; % Impurity threshold
  11.  
  12. % Metal content constraints (optional: set minimum required metal content if needed)
  13. A = [-19 -43 -17 -20 0 -12;
  14. -15 -10 0 -12 -24 -18;
  15. -12 -25 0 0 -10 -16;
  16. -14 -7 -53 -18 -31 -25];
  17.  
  18. % Lower bounds and upper bounds for decision variables
  19. lb = zeros(6,1); % No negative ore amounts
  20. ub = ones(6,1); % Each ore amount is between 0 and 1 ton
  21.  
  22. % Solve the LP problem using glpk
  23. ctype = "S"; % Equality constraint for total tonnage
  24. vartype = "C"; % Continuous variables
  25.  
  26. % Now run the solver
  27. [x, z, exitflag] = glpk(f, [A_ineq; Aeq], [b_ineq; beq], lb, ub, ctype, vartype, 1);
  28.  
  29. % Check if a valid solution is found
  30. if exitflag == 180
  31. disp('Optimal amounts of ores:');
  32. disp(x);
  33. disp('Minimum cost per ton of alloy:');
  34. disp(z);
  35. else
  36. disp('No feasible solution found');
  37. end
  38.  
Success #stdin #stdout #stderr 0.09s 48148KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
error: glpk: CTYPE must be a char valued vector of length 2
error: called from
    glpk at line 549 column 7
    /home/2H4Nwg/prog.octave at line 27 column 15