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!