gamultiobj() is running really slow with a nested loop objective function

I am using gamultiobj() to optimize a nonlinear problem with 5 integer decision variables and one linear contraint. My objective functions are not represented by a closed-form mathematical relationship, but rather by a nested for-loop.
The objective functions evaluations go something like this:
function [obj]= fit_fun(X)
A=linspace(0,20,50);
B=linspace(0,0.05,50);
for i=1:50
for j=1:50
syms a b c
f1=f(a,b,c)==0; %Nonlinear function with trig functions of angles a and b
f2=f(a,b,c)==0; %Nonlinear function with trig functions of angles a and b
f3=f(a,b,c)==0; %Nonlinear function with trig functions of angles a and b
[a, b, c]=vpasolve([f1 f2 f3], [a b c], [0 pi/2; 0 pi/2; 0 inf]);
%Simple calculations involving X, a, b, and c
% .
% .
if statement to check previous calculations for nonlinear constraints
obj_fun_1=[obj_fun_1, A(i)];
obj_fun_2= [obj_fun_2, (simple calculation)];
else
obj_fun_1=1000 %Penalize the solution with large value
obj_fun_2=1000 %Penalize the solution with large value
break %Only to save time since I'm only intrested in maximum values reached before contraint violation
end
end
end
obj(1)=-max(obj_fun_1); %Maximize max(obj_fun_1)
obj(2)=-max(obj_fun_2); %Maximize max(obj_fun_2)
The current setup with a population of 10 and 30 maximum stall generations produces very good results, but takes really long time (14 hrs and counting). Are there any other methods or tips through which I can make my code run more efficiently?

 Accepted Answer

I was able to track down the issue to vpasolve(). When it can't find a solution within the specified range it takes upwards of 10 seconds before exiting. Using fsolve() instead with suitable initial guesses (based on previous knowledge and trial & error) solved my issue and made the code orders of magnitude faster.

More Answers (0)

Products

Release

R2022a

Asked:

on 10 Feb 2023

Answered:

on 13 Feb 2023

Community Treasure Hunt

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

Start Hunting!