specify the number of iterations in genetic algorithm matlab (ga)

18 ビュー (過去 30 日間)
mohammed hussein
mohammed hussein 2022 年 7 月 13 日
コメント済み: mohammed hussein 2022 年 7 月 13 日
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

採用された回答

Sam Chak
Sam Chak 2022 年 7 月 13 日
編集済み: Sam Chak 2022 年 7 月 13 日
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)
Optimization terminated: maximum number of generations exceeded.
x = 1×5
1.0006 2.0004 3.0003 4.0006 5.0011
fval = 2.1865e-06
exitflag = 0
output = struct with fields:
problemtype: 'linearconstraints' rngstate: [1×1 struct] generations: 100 funccount: 4753 message: 'Optimization terminated: maximum number of generations exceeded.' maxconstraint: 0 hybridflag: []
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by