Implement parameter constraint for surrogateopt

Hello,
I want to run an optimisation using surrogateopt and I have the constraint, that certain parameters can't be smaller than others. So, I guess for other methods my constraint function would look like this (?):
params = [param1, param2, param3, param4]
function [c, ceq] = simple_constraint(params)
c = [params(2)-params(1);
params(4)-params(3)];
ceq = [];
end
As far as I understood in surrogateopt the constraints are set in the objective function.
What is the best way to implement these parameter constraints which are independent of the objective function value?
Just setting and arbitrary high value as value of the objective function? So, something like this:
function f = objFun_surrogateopt(param)
if params(2)> params(1) || params(4) > params(3)
f.Fval = 1000;
else
f.Fval = objFun(param);
end
f.Ineq = [params(2)-params(1);
params(4)-params(3)];
end
Or is there a smarter and more efficient way?
I'm looking forward to any hint on how to improve this!

 採用された回答

Alan Weiss
Alan Weiss 2021 年 10 月 29 日

0 投票

The answer depends on your MATLAB version. As the Release Notes show, linear constraints were introduced in R2021a, nonlinear constraints were initroduced in R2020a.
  • With R2021a or later, param(2) >= param(1) is equivalent to the linear constraint
A = [1 -1 0 0 0];
b = 0; % This means x(1) - x(2) <= 0, or x(1) <= x(2)
  • With R2020a or R2020b, represent the constraint as a nonlinear inequality constraint:
function F = objcon(x)
F.Ineq = x(1) - x(2);
F.Fval = % your objective function here
end
Alan Weiss
MATLAB mathematical toolbox documentation

3 件のコメント

Elsa Bunz
Elsa Bunz 2021 年 10 月 29 日
@Alan Weiss Thanks! Does that mean, that for the R2020a/R2020b version the objective function will still be evaluated even if the constraints are not satisfied? So, in order to avoid an unnecessary evaluation (in my case a quite lengthy simulation) I'd need to something as I suggested in my original question (if case, giving an arbitrary high value for the objective function instead of evaluating, if the constraints aren't satisfied)?
Would this issue be solved with the way linear constraints are handled in R2021a?
Alan Weiss
Alan Weiss 2021 年 10 月 29 日
Indeed, for R2021a the linear constraints are always satisfied. For R2020a, the constraints can be violated.
Alan Weiss
MATLAB mathematical toolbox documentation
Elsa Bunz
Elsa Bunz 2021 年 10 月 29 日
Okay, thanks a lot for the clarification!

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

その他の回答 (0 件)

カテゴリ

製品

リリース

R2020b

質問済み:

2021 年 10 月 27 日

コメント済み:

2021 年 10 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by