Problem with ga optimization of 2 variables with IntCon

I am attempting to optimize airfoils in certain conditions, where my input variables are the digits of NACA airfoils. I am using a genetic algorithm (I am aware that this type of optimization is not great for my purpose, however it is the only optimization that allows the variables to be strictly integers which is required for my optimization).
This works perfectly using 1 variable, and I have tested using 2+ variables with simple fitness functions (x(1) + x(2)), however using 2 variables with my final problem will not run the optimization. I will copy the fitness function and main script file.
%fitness function
function [LiftC] = gaCL(x)
CL = mpxfoil(strcat(num2str(x(1)),'4',num2str(x(2))), 91202,
0.0195498580029, 3);
LiftC = -CL;
end
~
%main script
lb = [1,11];
ub = [7,20];
opts = optimoptions('ga','PlotFcn',@gaplotbestf);
IntCon = 1;
[x,fval] = ga(@gaCL,2,[],[],[],[],...
lb,ub,[],IntCon,opts);
The fitness function as well as the other function this is based off of (mpxfoil) I have tested and both work. It seems that this fails when I add in more than one variable. The plot never shows up and MATLAB is continually busy until canceled. Is it possible that with 2 variables this optimization takes 20+ minutes for even the plot to show up when only 1 variable takes under 2 minutes to completely finish?
Here is the error message I get after manually stopping the optimization (the runperl and mpxfoil error just mean that the inputs that mpxfoil was given caused it to fail).
%errors
Operation terminated by user during runperl (line 41)
In mpxfoil (line 127)
runperl('xfw.pl', airfoil, isnaca, Re, Ma, alfa_start, alfa_end, alfa_step, maxit, input_file, timeout);
In gaCL (line 27)
[alfa, CL, CD, CDp, CM, Top_Xtr, Bot_Xtr] = mpxfoil(strcat(num2str(x(1)),'4',num2str(x(2))), 91202, 0.0195498580029, 3);
In createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
In fcnvectorizer (line 13)
y(i,:) = feval(fun,(pop(i,:)));
In gaminlppenaltyfcn
In gapenalty
In makeState (line 64)
Score = FitnessFcn(state.Population(initScoreProvided+1:end,:));
In galincon (line 17)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
In gapenalty
In gaminlp
In ga (line 366)
[x,fval,exitFlag,output,population,scores] = gaminlp(FitnessFcn,nvars, ...
In main (line 38)
[x,fval] = ga(@gaCL,2,[],[],[],[],...
In run (line 86)
evalin('caller', [script ';']);

 Réponse acceptée

Alan Weiss
Alan Weiss le 18 Août 2017

0 votes

I do not understand, and am therefore somewhat suspicious of, your mpxfoil call. Did you try to call gaCL(x) for a variety of 2-D or 3-D x? It seems to me that the strcat call will have mpxfoil receive first arguments such as '1411.00001' through '7419.99999'. Is that really what you want? Also, you have only the first component of x is integer-valued, and you have bounds on the first two components, but you have three variables. Are all those settings sensible? I doubt it, because your fitness function does not seem to use x(3).
Anyway, that's all I can see right now. If you want more help, please double-check that you copied and pasted exactly from your functions (I mean, you said that you have a 2-D x, but you clearly wrote 3 in your gatest call), and give the full and complete copy-pasted error messages.
Alan Weiss
MATLAB mathematical toolbox documentation

1 commentaire

Dylan Mack
Dylan Mack le 18 Août 2017
Modifié(e) : Dylan Mack le 18 Août 2017
I seem to have made a few mistakes copy code, I apologize. I will edit the first comment's code and also include the entire error message.
Also, mpxfoil is a function which takes 5 inputs (1 string and 4 numerical). This string is always a 4 digit number, and 3 of those digits are meant to be my variables, and I am attempting to optimize a specific output of mpxfoil.
Addressing what you said about what mpxfoil receives, the string needs to be strictly an integer. That string should be receiving "1411" for example. If for some reason you think it will receive '1411.999999', then that will DEFINITELY be causing this error and would make complete sense, however I assumed the IntCon would keep that to strictly integers.
Lastly, I have spent a lot of time debugging mpxfoil and my fitness function with different variables and variable numbers. It seems that this problem arises when I attempt to optimize with 2 variables, within the string. (when optimize with the 4 other inputs that mpxfoil takes, it works. When I optimize 1 variable within the string, it works.) Possibly my error is within the use of commands like strcat?
Thank you so much for responding, I appreciate your help! Please get back to me ASAP.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by