How to improve efficiency of patternsearch function optimization with multiple outputs

조회 수: 4 (최근 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에서 Surrogate Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by