How to improve efficiency of patternsearch function optimization with multiple outputs

1 visualización (últimos 30 días)
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

Respuestas (1)

Viktor
Viktor el 6 de Jul. de 2024
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 comentario
John
John el 6 de Jul. de 2024
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

Iniciar sesión para comentar.

Categorías

Más información sobre Direct Search en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by