Change constraints within optimization loop

5 vues (au cours des 30 derniers jours)
Cedric Kotitschke
Cedric Kotitschke le 8 Avr 2022
Réponse apportée : xuechen le 20 Juil 2024
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

Réponse acceptée

Cedric Kotitschke
Cedric Kotitschke le 8 Avr 2022
Found the answer:
the class of current_analysis is a subclass of the dynamicprops superclass and the properties are SetObservable

Plus de réponses (1)

xuechen
xuechen le 20 Juil 2024
Hello, have you solved this problem? I am also confused about the Single-Loop-Approach. Can I ask you a few questions? Thank you.

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by