Change constraints within optimization loop
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
更多回答(1 个)
xuechen
2024-7-20
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!