Optimization terminated: maximum number of generations exceeded.
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Patis Thepsorn
el 10 de Abr. de 2023
Comentada: Torsten
el 10 de Abr. de 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 comentario
Torsten
el 10 de Abr. de 2023
Why do you use "ga" if you can use any other optimizer of your choice ?
Respuesta aceptada
Alan Weiss
el 10 de Abr. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Direct Search en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!