Genetic algorithm plot diagram display
31 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
joshua Abam
am 21 Feb. 2020
Kommentiert: joshua Abam
am 23 Feb. 2020
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 Kommentare
Walter Roberson
am 22 Feb. 2020
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?
Akzeptierte Antwort
Walter Roberson
am 23 Feb. 2020
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Genetic Algorithm finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!