Find optimal of function with 3D input
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I am currently working on an optimization problem, but I am not sure on how to proceed. I have computed a 3D array with scores (say 10x10x10). Now I want to find the optimal x (10x10x10) which consists of only 1's and 0's such that the sum of the individual elements of
scores .* x
is maximal.
The only constraint is that there can only be one 1 in every dimension of x. That is, the following must be satisfied:
all(sum(x, 1) <= 1)
all(sum(x, 2) <= 1)
all(sum(x, 3) <= 1)
I have been looking at applying fmincon, but I get the idea that it only works for x as a scalar, vector or matrix. I could flatten x to a vector, but then I am not certain if the constraining would still work.
Does anybody has some pointers for me? Any help is welcome.
Thank you.
Robert
댓글 수: 0
답변 (1개)
Matt J
2018년 1월 25일
편집: Matt J
2018년 1월 25일
None of the solvers care what the dimensions of your unknown variable array x is. The problem with fmincon is that doesn't support binary constraints. You could use intlinprog, but the new problem-based optimization framework might make setting up the problem easier here.
x=optimvar('x',[10,10,10],'LowerBound',0,'UpperBound',1,'Type','integer');
prob=optimproblem('ObjectiveSense','max','Objective', scores(:).'*x(:));
prob.Constraints.con1=sum(x,1)<=1;
prob.Constraints.con2=sum(x,2)<=1;
prob.Constraints.con3=sum(x,3)<=1;
[sol,fval] = solve(prob);
댓글 수: 2
Matt J
2018년 1월 26일
I've used prob2struct() to convert the optimproblem object to a struct compatible with intlinprog (see attached .mat file).
You can just do
intlinprog(s)
but first make the replacement s.f=scores.
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!