Optimization terminated: maximum number of generations exceeded.

46 ビュー (過去 30 日間)
Patis Thepsorn
Patis Thepsorn 2023 年 4 月 10 日
コメント済み: Torsten 2023 年 4 月 10 日
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
f2 = function_handle with value:
@(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);
Optimization terminated: maximum number of generations exceeded.
fprintf("The optimal decision is:\nx = %f\ny = %f\nThis solution has value %f\n", x(1), x(2), fval);
The optimal decision is: x = 1206.044779 y = -884.937818 This solution has value -28272094798.760334
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
f2 = function_handle with value:
@(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);
Optimization terminated: maximum number of generations exceeded.
fprintf("The optimal decision is:\nx = %f\ny = %f\nThis solution has value %f\n", x(1), x(2), fval);
The optimal decision is: x = -1128.320461 y = -849.805146 This solution has value -23761468456.310452
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 件のコメント
Torsten
Torsten 2023 年 4 月 10 日
Why do you use "ga" if you can use any other optimizer of your choice ?

サインインしてコメントする。

採用された回答

Alan Weiss
Alan Weiss 2023 年 4 月 10 日
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 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by