Change constraints within optimization loop

조회 수: 4 (최근 30일)
Cedric Kotitschke
Cedric Kotitschke 2022년 4월 8일
답변: Cedric Kotitschke 2022년 4월 8일
Hey,
I have an optimization problem in which the constraints depend on whether the design variable has changed or not (Single-Loop-Approach in RBDO if anyone is interested) .
Do you have any idea how to do this with fmincon?
I found a very extensive toolbox which has this optimization problem implemented but the code is very complex. However, I saw that their method is to pass an object in the nonlinear constraint function and the output function to update some flags which are used to compute the appropriate constraints.
Here is the output function (this function gets called in each iteration, corresponds to the option 'OutputFcn'):
function stop = outfun(x,optimValues,state,current_analysis)
stop = false ;
switch state
case 'init'
% Do nothing...
% Initial value is already saved in Histroy.X &.Score
% Update the flag signaling that a new point is about
% to be computed
current_analysis.Internal.Runtime.isnewpoint = true ;
case 'iter'
% Concatenate current point and objective function
% value with history. x must be a row vector.
History.Score = ...
[History.Score; optimValues.fval];
History.X = ...
[History.X; x];
% Update the flag signaling that a new point is about
% to be computed
current_analysis.Internal.Runtime.isnewpoint = true ;
case 'done'
% Do nothing
otherwise
% Do nothing
end
end
You can clearly see how the flag 'isnewpoint' is updated. It is set to false in the nonlinear constraints function.
This makes me wonder how this works. It seems this object can be updated from anywhere like it is a global variable. However, it is not. It doesn't appear blueish like global variables do and it is not defined as global anywhere. So how does this work?
Cheers
Cedric

채택된 답변

Cedric Kotitschke
Cedric Kotitschke 2022년 4월 8일
Found the answer:
the class of current_analysis is a subclass of the dynamicprops superclass and the properties are SetObservable

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by