Genetic algorithm plot diagram display
26 次查看(过去 30 天)
显示 更早的评论
Dear all,
I am having a few challenges with regards to GA displaying the plots from the plot function and saving the output results from the output function, while using the m file, however when put in optimization toolbox, the plot are displayed and the output functions are saved respectively. That draws me to the questions, what do I have to do to make the plots displays and save the out put functions using an m file as displayed below.
Thanks
Kind regards
Joshua Abam
function [x,fval,existflag,output,population,scores] = scr_gafunction(x)
options = optimoptions('ga'); %Define Optimization the solver
options = optimoptions('ga','PopulationSize',50,'Generations',50,'OutputFcn',@gascroutputdata); %Define the Population Size
%Define the generation Size %Define Ouput Function
options.SelectionFcn = ('selectionstochunif'); %Define the selection pattern
options.MutationFcn = ('mutationgaussian'); %Define the mutation methods
options.CrossoverFcn = ('crossoverheuristic'); %Define the crossover methods
options = optimoptions('ga', 'Display','diagnose','MaxStallGenerations',60); %Define Display function
%Define at what Generation is GA stall
%Define the Plot Function
scr_gafunction.options.PlotFcns = optimoptions('ga','PlotFcn',{@gaplotbestf,@gaplotrange,@gaplotscores,...
@gaplotselection,@gaplotdistance,@gaplotexpectation,@gaplotstopping})
options = optimoptions('ga','UseParallel', true, 'UseVectorized', false);
ObjectiveFunction = @weight; %fitness function
nvars = 3; % Number of variables
A = [0 0 -1]; %Linear Inequality Constraint matrix
b = [-0.0254]; %Linear inequality constraint vector (t_1+t_corr+t_fab)
Aeq = [1 -0.03 0]; %Linear equality Constraint matrix
beq = [77]; %Linear equality constraint vector
lb = [167, 3000, 0.0127]; %Vector of Lower bounds
ub = [173, 3200, 0.0286]; %Vector of Upper bounds
% Initial design point could be determined in 2 ways: One is to leave it to
% GA automatically generate; or it can be specified by the users.
%x0 = []; %Initial Feasible Point
nonlcon = @nonlinearconst; %Nonlinear constraints
Intcon = []; %Vector indicating variables that take integer values
%Excuate GA with output
[x,fval,exitflag,output,population,scores] = ga(ObjectiveFunction,nvars,A,b,Aeq,beq,lb,ub,nonlcon,Intcon,options)
Final_time = toc(startTime);
fprintf('GA optimization takes %g seconds.\n',Final_time)
end
4 个评论
Walter Roberson
2020-2-22
The code you posted does not attempt to save() anything, so it is not clear why you would expect that anything would end up in a .mat file?
采纳的回答
Walter Roberson
2020-2-23
The variable that you create that has the same name as your function, is not used after it is assigned to, so the options you assign there are never used. The options you use are the ones you create about using parallel.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!