% bso test
clc
clear all
close all
%funStr = 'rastrigin'; %output worksheet name
%funName = @rastrigin; % fitness function name
%n_p = 500; % population size
%n_d = 2; % dimension
%n_c = 5; % number of clusters
%rang_l = -100; % left of dynamic range
%rang_r = 100; % right of dynamic range
%max_iteration = 50; % maximal number of iterationswarning off all
n_p = 100; % population size
n_d = 30; % dimension
n_c = 5; % number of clustersfunStr = 'sphere30D5C'; %output worksheet name
funName = @sphere; % fitness function name
rang_l = -100; % left of dynamic range sphere
rang_r = 100; % right of dynamic range%funStr = 'rastrigin10D5C'; %output worksheet name
%funName = @rastrigin; % fitness function name
%rang_l = -5.12; % left of dynamic range rastrigin
%rang_r = 5.12; % right of dynamic rangemax_iteration = 200; % maximal number of iterations
for idx = 1:50 % run times
idx
fit = bso2(funName,n_p,n_d,n_c,rang_l,rang_r,max_iteration); %run BSO one time
% if idx <27
% str = native2unicode(idx + 64);
% else % assume idx <53
% str =['A',native2unicode(idx + 38)];
% end
% xlswrite('bso2.xls',fit,funStr, [str,'1']); % output best fitness over generation to EXCEL worksheet for each BSO run
% ['run', num2str(idx)]
fit1=fit';
fits(idx,1:max_iteration)=fit1(1,1:max_iteration);

end
fits=sum(fits)/idx;
plot(fits,'-.');


 

头脑风暴优化算法_头脑风暴