Display optimization variable/solution

2 ビュー (過去 30 日間)
Andra Vartolomei
Andra Vartolomei 2022 年 8 月 21 日
コメント済み: Matt J 2022 年 8 月 23 日
I am solving a finction minimizing the objective function. The optimization variable looks like this [3D array]
a=3; b=2; c=50;
costs_tasks = rand (3,2);
linoptim = optimproblem;
x = optimvar('x',a,b,c,'Type', 'integer','LowerBound',0,'UpperBound',1);
objfun = sum(sum(sum(x,3).*(costs_tasks),2),1);
linoptim.Objective = objfun;
sol = solve(linoptim)
Solving problem using intlinprog. LP: Optimal objective value is 0.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).
sol = struct with fields:
x: [3×2×50 double]
There are also some constraints I consider.
By solving the objective function, there are certain pages (3rd dimension) with the value 1 and I would like to see them.
My question ist, how can I display the optimal variable?

採用された回答

Matt J
Matt J 2022 年 8 月 21 日
pages=any(sol.x==1,[1,2]);
disp(sol.x(:,:,pages) )
  3 件のコメント
Andra Vartolomei
Andra Vartolomei 2022 年 8 月 22 日
I managed to adapt it, so that I get a Matrix with the positions where I have non-zero values:
ind = find(sol.x>0);
[i1, i2, i3] = ind2sub(size(sol.x), ind);
positions = [i1(:),i2(:),i3(:)]
Matt J
Matt J 2022 年 8 月 23 日
I'm glad, but please accept-click the answer to indicate tht your question is resolved.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Least Squares についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by