Intlinrprog (maximize) vs excel Solver (Maximize)

조회 수: 14 (최근 30일)
Angga Fernando
Angga Fernando 2021년 8월 23일
댓글: Angga Fernando 2021년 8월 24일
Dear All,
I tried to solve a problem that the objective is to find maximize value from X1, X2, and X3 and should be in integer. So, I use the intlinprog in Matlab to find the maximize value. Since I looking for maximize, I change "f" to "-f" and the result is negative number with the result 0 X1, 4 X2, and 2 X3. Attached below :
In confused why the result is negative. Then, I tried to solve the problem using Excel Solver (maximize) and I got a reasonable result below :
The confused things is, when I set the Excel Solver to minimize and also I remove "-" in Matlab (from "-f" to "f", the result will be same between the Excel Solver and Intlinprog Matlab.
Anyone here can help me, how to solve this problem ? How to use maximize function in intlinprog properly?
Thank you for your kindly help.

채택된 답변

Alan Weiss
Alan Weiss 2021년 8월 23일
Your problem is that you set
intcon = 3;
This means that the only variable restricted to be an integer is x(3). Instead you should write the following:
f = [10 25 45];
intcon = 1:3; % All three variables are integer
A = [1 6 3;2 2 3];
b = [30 15];
Aeq = [0 5 2];
beq = 20;
lb = [0 0 0];
x = intlinprog(-f,intcon,A,b,Aeq,beq,lb,[])
LP: Optimal objective value is -130.000000. Optimal solution found. Intlinprog stopped at the root node because the objective value is within a gap tolerance of the optimal value, options.AbsoluteGapTolerance = 0 (the default value). The intcon variables are integer within tolerance, options.IntegerTolerance = 1e-05 (the default value).
x = 3×1
3 4 0
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 1
Angga Fernando
Angga Fernando 2021년 8월 24일
It works. Thank you so much for your kindly help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by