How to include min() in optimization constraint
5 次查看(过去 30 天)
显示 更早的评论
Hi,
I have an optimization problem for which I want to find a solution using the GlobalSearch solver. I have several constraints of the form "X(20) <= 100 - max([max(X(1:3)) max(X(5:7)) max(X(10:17))])" which I implemented in the "c" argument: "X(20) - (100 - max([max(X(1:3)) max(X(5:7)) max(X(10:17))]);" (<= 0)
However, these constraints seem to be ignored by Matlab during optimization. This leads me to suspect that it is not possible to use min() and max() when writing constraints. Is this true? If so, is there a convenient way to implement this without having to write out every single constraint, i.e. "X(20) - (100-X(1)); X(20) - (100-X(2)); etc."?
Thank you!
0 个评论
回答(2 个)
Matt J
2015-4-19
编辑:Matt J
2015-4-21
If so, is there a convenient way to implement this without having to write out every single constraint, i.e. "X(20) - (100-X(1)); X(20) - (100-X(2));
These are linear constraints. You should be using matrix/vector inputs to express them and you should construct the matrix/vector input data using vectorized methods. The code below generates A,b that express your constraints in the appropriate matrix/vector form A*X<=b,
J=[1:3,5:7, 10:17];
numcon=length(J);
A=sparse(1:numcon,J,1,numcon,length(X));
A(:,20)=1;
b(1:numcon,1)=100;
0 个评论
Derya
2015-4-21
编辑:Derya
2015-4-21
Hello Greg,
In regards to your question whether one can use min() or max() in writing their nonlinear constraints, the answer is yes.
A possible reason for why your constraint is ignored would be that the solver doesn't know about it.
I assume that you have implemented your nonlinear constraint function (say function [c, ceq] = myconst(x)) and your problem structure has a field called 'nonlcon' and its value is 'myconst'. As an example, using createOptimProblem
problem = createOptimProblem('fmincon','x0',randn(2,1), 'objective',myobjfun,'nonlcon',myconst,'lb',[-2;-2],'ub',[2;2],'options',opts);
you had your problem, that was fed into GlobalSearch as:
gs = GlobalSearch;
[x,f] = run(gs,problem)
Could you confirm that you have (more or less) done this?
Regards,
Derya
P.S.: I think you can use "X(20) <= 100 - max([X(1:3) X(5:7) X(10:17)])" instead of "X(20) <= 100 - max([max(X(1:3)) max(X(5:7)) max(X(10:17))])".
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!