Optimization terminated: maximum number of generations exceeded.
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Patis Thepsorn
am 10 Apr. 2023
Kommentiert: Torsten
am 10 Apr. 2023
Why I got the maximum number exceeding? The solution is fluctuated as it shows in first run and second run.
% GA without constraints
% Objective function
f1 = @(x) 11*x(1)+22*x(1).^2.*x(2)+x(2).^2+31.*x(1).^2;
f2 = @(x,y) 11*x+22*x.^2.*y + y.^2 +31*x.^2
% LHS of linear inequalities
A = [];
% RHS of linear inequalities
B = [];
% No linear equalities
Aeq = [];
Beq = [];
% Nonlinear constraints
nonlcon = [];
lb = [];
% Alternatively:
% lb = []
ub = [];
options = optimoptions('ga','ConstraintTolerance',1e-8,'PlotFcn', @gaplotbestf);
% Solve the problem
[x, fval] = ga(f1,2, A, B, Aeq, Beq, lb, ub, nonlcon, options);
fprintf("The optimal decision is:\nx = %f\ny = %f\nThis solution has value %f\n", x(1), x(2), fval);
figure
hold on
fcont = fcontour(f2, [-1500 1500 -1000 1000]);
optpoint = scatter(x(1), x(2), 200, [0 0 0], '*');
legend([optpoint,fcont], {'Solution','Objective'}, 'Location', 'Southwest');
hold off
% GA without constraints
% Objective function
f1 = @(x) 11*x(1)+22*x(1).^2.*x(2)+x(2).^2+31.*x(1).^2;
f2 = @(x,y) 11*x+22*x.^2.*y + y.^2 +31*x.^2
% LHS of linear inequalities
A = [];
% RHS of linear inequalities
B = [];
% No linear equalities
Aeq = [];
Beq = [];
% Nonlinear constraints
nonlcon = [];
lb = [];
% Alternatively:
% lb = []
ub = [];
options = optimoptions('ga','ConstraintTolerance',1e-8,'PlotFcn', @gaplotbestf);
% Solve the problem
[x, fval] = ga(f1,2, A, B, Aeq, Beq, lb, ub, nonlcon, options);
fprintf("The optimal decision is:\nx = %f\ny = %f\nThis solution has value %f\n", x(1), x(2), fval);
figure
hold on
fcont = fcontour(f2, [-1500 1500 -1000 1000]);
optpoint = scatter(x(1), x(2), 200, [0 0 0], '*');
legend([optpoint,fcont], {'Solution','Objective'}, 'Location', 'Southwest');
hold off
1 Kommentar
Akzeptierte Antwort
Alan Weiss
am 10 Apr. 2023
ga exceeded 200 generations. If you want more, increase the MaxGenerations option.
options = optimoptions('ga','ConstraintTolerance',1e-8,'PlotFcn', @gaplotbestf,...
'MaxGenerations',1e3);
Alan Weiss
MATLAB mathematical toolbox documentation
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Direct Search 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!