% bso test_OS
%smaple for writing a test for a benchmark function
%funStr = 'rastrigin'; %output worksheet name
%funName = @rastrigin; % fitness function name
%n_p = 500; % population size
%n_d = 2; % dimension
%n_c = 0.1; % elitist percentage
%rang_l = -100; % left of dynamic range
%rang_r = 100; % right of dynamic range
%max_iteration = 50; % maximal number of iterations
% run all ten benchmark functions
warning off all
m_r = 30; % maximum run times
max_iteration = 2000; % maximal number of iterations
n_p = 100; % population size
n_c = 0.1; % elitist percentage
% Sphere
funName = @sphere; % fitness function name
rang_l = -100; % left of dynamic range sphere
rang_r = 100; % right of dynamic range
n_d = 10; % dimension
funStr = 'sphereD10'; %output worksheet name
for idx = 1:m_r % run times
[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('bsok25.xls',fit,funStr, [str,'1']); % output best fitness over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25dc.xls',dc,funStr, [str,'1']); % output average inter-cluster distance over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25de.xls',de,funStr, [str,'1']); % output entropy on number of individuals in cluster over generation to EXCEL worksheet for each BSO run
['sphere D10 run', num2str(idx)]
end
n_d = 20; % dimension
funStr = 'sphereD20'; %output worksheet name
for idx = 1:m_r % run times
[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('bsok25.xls',fit,funStr, [str,'1']); % output best fitness over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25dc.xls',dc,funStr, [str,'1']); % output average inter-cluster distance over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25de.xls',de,funStr, [str,'1']); % output entropy on number of individuals in cluster over generation to EXCEL worksheet for each BSO run
['sphere D20 run', num2str(idx)]
end
n_d = 30; % dimension
funStr = 'sphereD30'; %output worksheet name
for idx = 1:m_r % run times
[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('bsok25.xls',fit,funStr, [str,'1']); % output best fitness over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25dc.xls',dc,funStr, [str,'1']); % output average inter-cluster distance over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25de.xls',de,funStr, [str,'1']); % output entropy on number of individuals in cluster over generation to EXCEL worksheet for each BSO run
['sphere D30 run', num2str(idx)]
end
% Schwefel 221
funName = @schwefel221; % fitness function name
rang_l = -100; % left of dynamic range sphere
rang_r = 100; % right of dynamic range
n_d = 10; % dimension
funStr = 'schwefel221D10'; %output worksheet name
for idx = 1:m_r % run times
[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('bsok25.xls',fit,funStr, [str,'1']); % output best fitness over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25dc.xls',dc,funStr, [str,'1']); % output average inter-cluster distance over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25de.xls',de,funStr, [str,'1']); % output entropy on number of individuals in cluster over generation to EXCEL worksheet for each BSO run
['schwefel221 D10 run', num2str(idx)]
end
n_d = 20; % dimension
funStr = 'schwefel221D20'; %output worksheet name
for idx = 1:m_r % run times
[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('bsok25.xls',fit,funStr, [str,'1']); % output best fitness over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25dc.xls',dc,funStr, [str,'1']); % output average inter-cluster distance over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25de.xls',de,funStr, [str,'1']); % output entropy on number of individuals in cluster over generation to EXCEL worksheet for each BSO run
['schwefel221 D20 run', num2str(idx)]
end
n_d = 30; % dimension
funStr = 'schwefel221D30'; %output worksheet name
for idx = 1:m_r % run times
[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('bsok25.xls',fit,funStr, [str,'1']); % output best fitness over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25dc.xls',dc,funStr, [str,'1']); % output average inter-cluster distance over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25de.xls',de,funStr, [str,'1']); % output entropy on number of individuals in cluster over generation to EXCEL worksheet for each BSO run
['schwefel221 D30 run', num2str(idx)]
end
% Step
funName = @step; %fitness function name
rang_l = -100; % left of dynamic range sphere
rang_r = 100; % right of dynamic range
n_d = 10; % dimension
funStr = 'stepD10'; %output worksheet name
for idx = 1:m_r % run times
[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('bsok25.xls',fit,funStr, [str,'1']); % output best fitness over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25dc.xls',dc,funStr, [str,'1']); % output average inter-cluster distance over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25de.xls',de,funStr, [str,'1']); % output entropy on number of individuals in cluster over generation to EXCEL worksheet for each BSO run
['Step D10 run', num2str(idx)]
end
n_d = 20; % dimension
funStr = 'stepD20'; %output worksheet name
for idx = 1:m_r % run times
[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('bsok25.xls',fit,funStr, [str,'1']); % output best fitness over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25dc.xls',dc,funStr, [str,'1']); % output average inter-cluster distance over generation to EXCEL worksheet for each BSO run
%xlswrite('bsok25de.xls',de,funStr, [str,'1']); % output entropy on number of individuals in cluster over generation to EXCEL worksheet for each BSO run
['Step D20 run', num2str(idx)]
end
n_d = 30; % dimension
funStr = 'stepD30'; %output worksheet name
for idx = 1:m_r % run times
[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('bsok25.xls',fit,funStr, [str,'1']); % output best fitness over generation to EXCEL worksheet for each B