How to include min() in optimization constraint
조회 수: 4 (최근 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!