How to improve efficiency of patternsearch function optimization with multiple outputs

1 次查看(过去 30 天)
I have written a code that uses patternsearch to optimize a complex aircraft geometry for a desired flight condition. The code itself is extremely long, so I'm writing a simpler version below. The function of interest takes multiple geometric variables as inputs, and outputs lift (the objective) and volume (the constraint). I have followed some guides, and have my code setup in a way like this at the moment (this is an extremely simplified version for brevity):
obj = fcn2optimexpr(@lift_fun,x1,x2,x3,x4,x5);
prob = optimproblem("Objective",1/obj);
const1 = fcn2optimexpr(@volume_fun,x1,x2,x3,x4,x5);
prob.Constraints.vol = const1 >= 5;
x0 = [1 2 3 4 5];
[sol] = solve(prob,x0,"Solver","patternsearch","Options",options);
function [lift] = lift_fun(w,n,beta,epsS,p2,p3,Mdesign)
[lift,~] = master_function(x1,x2,x3,x4,x5);
end
function [volume] = volume_fun(w,n,beta,epsS,p2,p3,Mdesign)
[~,volume] = master_function(x1,x2,x3,x4,x5);
end
As I understand it, this code is calling the function 'master_function' twice for every optimization loop. This is a problem because this function takes up to a minute to run every time. Because of this I am wondering if it is possible to edit this code so that 'master_function' is only called once, providing both the objective and the constraint for the patternsearch optimization? Thank you for your help

回答(1 个)

Viktor
Viktor 2024-7-6
Try to store the last master_function inputs [x1,...,x5] and results [lift,volume] in a global variable. lift_fun() and volume_fun() can then first check, if the result for the specific inputs is already given before calculating.
  1 个评论
John
John 2024-7-6
This method definitely made a dent, reducing the total runtime by 20%. A little less than I was hoping for, but very happy with the result. Will be searching for other inefficiencies I can speed up in the patternsearch now.
Thank you

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Direct Search 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by