Optimization: share additional output of cost function with constraint function
古いコメントを表示
I have a well defined optimization problem in which I have a separate cost function and a separate constraint function:
Cost = @(C)costcenterroad(C,lp,xref,yref,T,rw);
Nonlinconstr=@(C)nonlcon(C,lp,rw,xref,yref,sol);
[C,fval] = fmincon(Cost,C1,[],[],[],[],[],[],Nonlinconstr);
Inside the cost function (which is called first by fmincon), I evaluate nonlinear functions of the decision variables (C in this case). The outputs of the nonlinear function determine the cost.
However, in the constraint function I need to evaluate the same function, with the same decesion variables (thats the way fmincon works; first the cost, then the contraints). Hence, I would rather use the values already calculated in the cost functions.
I tried to do this by using a structure SOL as an output of the cost function, and provide it as an input to the constraint function hence (also see code above);
function [J,sol]=costcenterroad(C,lp,xref,yref,T,rw)
function [c,ceq]=nonlcon(C,lp,rw,xref,yref,sol)
However, Matlab will tell that "sol" is unknown. I'am guessing that "sol" is not an output when the function `costcenterroad` is called. I also used 'sol' as a global variable, but this is not very elegant and fast.
Does anyone have any suggestions how to do this? Your help will be greatly appreciated!
採用された回答
その他の回答 (1 件)
Martijn
2012 年 3 月 7 日
1 件のコメント
Conrad McGreal
2020 年 12 月 21 日
Thank you for taking the time to write this up. It was exactly what I needed today!
カテゴリ
ヘルプ センター および File Exchange で Surrogate Optimization についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!