# Iteration limit / evaluation limit problem with GlobalSearch

7 views (last 30 days)
Erik Börgesson on 21 Oct 2020
Edited: Mario Malic on 22 Oct 2020
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');
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']);

Mario Malic on 21 Oct 2020
Edited: Mario Malic on 22 Oct 2020
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.