Change constraints within optimization loop
4 views (last 30 days)
Show older comments
Cedric Kotitschke
on 8 Apr 2022
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
0 Comments
Accepted Answer
More Answers (1)
xuechen
on 20 Jul 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.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!