Why I get the minus result for linear optimization?
古いコメントを表示
I am trying to solve a linear optimization problem, and I have followed the steps of the guide in MATLAB website. And I get the minus result. I am pretty sure the max is 36000.
linearOptim = optimproblem('ObjectiveSense','maximize');
product_1 = optimvar('product_1', 'Type', 'integer', 'LowerBound', 0);
product_2 = optimvar('product_2', 'Type', 'integer', 'LowerBound', 0);
linearOptim.Objective = 3000 * product_1 + 5000 * product_2;
linearOptim.Constraints.econs1 = product_1 <= 4;
linearOptim.Constraints.econs2 = 2 * product_2 <= 12;
linearOptim.Constraints.econs3 = 3 * product_1 + 2 * product_2 <= 18;
showproblem(linearOptim);
solveLinearOptim = solve(linearOptim);
4 件のコメント
Walter Roberson
2018 年 9 月 14 日
It is common to handle maximizations by minimizing the negative of the function. When maximizations are done this way, you have to take the negative of the output value.
Your code produces a value of -36000 which is exactly the negative of what you are expecting.
Edward Xu
2018 年 9 月 14 日
Torsten
2018 年 9 月 14 日
But how to tell the software that you wanted to maximize instead of minimize ?
Walter Roberson
2018 年 9 月 14 日
Torsten, the new problem based optimization permits that. Notice Edward included
linearOptim = optimproblem('ObjectiveSense','maximize');
I think it would be quite reasonable for the optimizer to get the sign right in such a case, but it does not appear to do so.
回答 (1 件)
Alan Weiss
2018 年 9 月 14 日
編集済み: Alan Weiss
2018 年 9 月 14 日
You are seeing the underlying solver's intermediate calculations. But if you look at the returned function value, you get the correct answer. For example,
evaluate(linearOptim.Objective,solveLinearOptim)
ans =
36000
Or even more simply, in the function call itself:
[solveLinearOptim,fval] = solve(linearOptim)
LP: Optimal objective value is -36000.000000. % This is the confusing bit
**snip**
solveLinearOptim =
struct with fields:
product_1: 2.0000
product_2: 6
fval =
36000 % This is the correct answer
Alan Weiss
MATLAB mathematical toolbox documentation
カテゴリ
ヘルプ センター および File Exchange で Solver Outputs and Iterative Display についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!