specify the number of iterations in genetic algorithm matlab (ga)
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
mohammed hussein
am 13 Jul. 2022
Kommentiert: mohammed hussein
am 13 Jul. 2022
dear all
I have a question related to the genetic algorithm (ga) in MATLAB I would like to specify the number of iterations so the algorithm stops after this number
I have only five variables
0 Kommentare
Akzeptierte Antwort
Sam Chak
am 13 Jul. 2022
Bearbeitet: Sam Chak
am 13 Jul. 2022
Here is a simple example where you can vary MaxGene and check the accuracy of the result.
fun = @objfcn; % objective function, specified as a function handle
PopuSiz = 50; % Population Size
MaxGene = 100; % Max Generations
nvars = 5; % number of variables
A = -eye(nvars); % []; %
b = zeros(nvars, 1); % linear inequality constraints, A*x <= b
Aeq = [];
beq = [];
lb = [];
ub = [];
nonlcon = [];
options = optimoptions('ga', 'PopulationSize', PopuSiz, 'MaxGenerations', MaxGene);
[x, fval, exitflag, output] = ga(fun, nvars, A, b, Aeq, beq, lb, ub, nonlcon, options)
function y = objfcn(x)
y = (x(1) - 1).^2 + (x(2) - 2).^2 + (x(3) - 3).^2 + (x(4) - 4).^2 + (x(5) - 5).^2;
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Genetic Algorithm finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!