Genetic algorithm plot diagram display
조회 수: 17 (최근 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!