Iteration limit / evaluation limit problem with GlobalSearch
5 次查看(过去 30 天)
显示 更早的评论
I have the following. My problem works fine for up to n=20, then for greater n i get error for max iterations or max evaluation. How can I fix the code so I can compute for higher n? I have already tried with including the parameter 'MaxEvaluation' inside optimoptions, but I cant make it work. I atleast want to compute high n's enough so I can get an ouput less than 5. I'd appreciate any help.
n=20;
B=50;
H=30;
lb=zeros(2*n+1,1);
ub=zeros(2*n+1,1);
for i=1:n
ub(2*i-1)=B;
ub(2*i)=H;
end
ub(2*n+1)=sqrt(B^2+H^2);
X0=rand(2*n+1,1);
for i=1:n
X0(2*i-1)=B*X0(2*i-1);
X0(2*i)=H*X0(2*i);
end
X0(2*n+1)=0;
%X0(2*n+1)=sqrt(min(-minDistances(X0)));
fun=@(X)-X(end)^2;
opts=optimoptions('fmincon','Algorithm','interior-point');
%fun=@funWithGrad;
%opts=optimoptions('fmincon','Algorithm','interior-point','GradObj','on');
problem=createOptimProblem('fmincon','objective',fun,'x0',X0,...
'lb',lb,'ub',ub,'nonlcon',@minDistances,'options',opts);
X=run(GlobalSearch,problem);
disp(X(end));
figure('DefaultAxesFontSize',18);
plot(X(1:2:2*n),X(2:2:2*n),'k.','MarkerSize',20);
viscircles([X(1:2:2*n),X(2:2:2*n)],X(end)/2*ones(n,1),'LineStyle','--');
axis([0 B 0 H]);
title(['Arrangement of ',num2str(n),' tables in the blue hall']);
0 个评论
采纳的回答
Mario Malic
2020-10-21
编辑:Mario Malic
2020-10-22
I'll share my two cents until someone else with more knowledge comes.
Probably ga or patternsearch would be more suited to your problem.
You have 41 variables, MaxFunctionEvaluations is 41*100 and MaxIterations is fixed on 1000. To be honest I have never ran an optimisation with this many variables. You should verify if fmincon is suited for such problems first. You can use optimoptions below for more informations.
opts=optimoptions('fmincon','Algorithm','interior-point',...
'Display', 'iter-detailed', 'PlotFcn', 'optimplotfval', ...
'MaxFunctionEvaluations', _num_, 'MaxIterations', _num_); % I can't really judge on _num_
Maybe a suggestion for
X0(2*n+1)= sqrt(B^2+H^2)/2;
From the documentation
MaxFunctionEvaluations
Maximum number of function evaluations allowed, a positive integer. The default value for all algorithms except interior-point is 100*numberOfVariables; for the interior-point algorithm the default is 3000. See Tolerances and Stopping Criteria and Iterations and Function Counts.
MaxIterations
Maximum number of iterations allowed, a positive integer. The default value for all algorithms except interior-point is 400; for the interior-point algorithm the default is 1000. See Tolerances and Stopping Criteria and Iterations and Function Counts.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!