【优化求解】基于头脑风暴优化算法BSO求解最优目标matlab源码

203 阅读2分钟

1 简介

受人类创造性解决问题过程--头脑风暴会议的启发, 2011年史玉回老师 在第二次群体智能国际会议(The Second International Conference on Swarm Intelligence(ICSI11))中提出一种新的群智能优化算法--头脑风暴优化算法,算法采用聚 类思想搜索局部最优,通过局部最优的比较得到全局最优;采用变异思想增加了算法的多 样性,避免算法陷入局部最优,在这聚与散相辅相承的过程中搜索最优解,思想新颖,适合于解决多峰高维函数问题。

2 部分代码

clc
clear
%bso test
tic
funStr = 'sphere10D5C';   %output worksheet name
funName = @sphere;        % fitness function name
rang_l = -100;            % left of dynamic range sphere
rang_r = 100;             % right of dynamic range
%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 iterations
warning off all
n_p = 100;                 % population size
n_d = 300;                  % dimension
% n_c = 2;                   % number of clusters
% funStr = 'sphere10D5C';   %output worksheet name
% funName = @sphere;       % fitness function name
% rang_l = -100;           % left of dynamic range sphere
% rang_r = 100;             % right of dynamic range
% funStr = 'Minima10D5C'; %output worksheet name
% funName = @Minima;     % fitness function name
% rang_l = -5;           % left of dynamic range rastrigin
% rang_r = 5;             % right of dynamic range
% funStr = 'Griewangk10D5C'; %output worksheet name
% funName = @Griewangk;     % fitness function name
% rang_l = -50;           % left of dynamic range rastrigin
% rang_r = 50;             % right of dynamic range
% funName = @ackley_path;     % fitness function name
% rang_l = -5;           % left of dynamic range rastrigin
% rang_r = 5;             % right of dynamic range
% minpts = 10;
max_iteration = 2000;     % maximal number of iterations
XX=1
%P = 0;
n_c = 2;
% P = 0.6;
% for P = 0:0.1:1 
for idx = 1:30            % 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('bso.xls',fit,funStr, [str,'1'])
                          % output best fitness over generation to EXCEL worksheet for each BSO run
  ['run', num2str(idx)]
   opt(idx,:)=fit;  %可以把列换成行   fit为一列数据
%     plot(x,opt(1,:)
end
opt;
format short g
best_value = min(opt(:,max_iteration))
worst_value = max(opt(:,max_iteration))
[ln col]=size(opt);
out_put(XX,:)=sum(opt)/ln;    %每一列的均值
format short g
m_value = min(out_put(XX,:))
z = 0;
for idx = 1:30
   z = z+(opt(idx,max_iteration)-m_value)^2;
end
SD = z/29
XX=XX+1
% end
% save UUB out_put(n_c,:);
% plot(out_put);
% end
% save UUB out_put(n_c,:);
% plot(opt);
figure(1)
save UUB out_put;
x=1:max_iteration;
% plot(x,out_put(1,:),'b',x,out_put(2,:),'g',x,out_put(3,:),'r',x,out_put(4,:),'c',x,out_put(5,:),'m',x,out_put(6,:),'y',x,out_put(7,:),'k',x,out_put(8,:),'b--',x,out_put(9,:),'g-.',);
% legend('k=2:蓝色','k=3:绿色','k=4:红色','k=5:青色','k=6:品红色','k=7:黄色','k=8:黑色','k=9','k=10');
plot(x,out_put(1,:))%,'b',x,out_put(2,:),'g',x,out_put(3,:),'r',x,out_put(4,:),'c',x,out_put(5,:),'m',x,out_put(6,:),'y',x,out_put(7,:),'k',x,out_put(8,:),'b--',x,out_put(9,:),'g-.',x,out_put(10,:),'r:',x,out_put(11,:),'c-.');
% legend('P=0','P=0.1','P=0.2','P=0.3','P=0.4','P=0.5','P=0.6','P=0.7','P=0.8','P=0.9','P=1');
toc
img =gcf;  %获取当前画图的句柄
print(img, '-dpng', '-r600', './运行结果.png')         %即可得到对应格式和期望dpi的图像

3 仿真结果

4 参考文献

[1]范虹, 史肖敏, and 姚若侠. "头脑风暴算法优化的乳腺MR图像软子空间聚类算法." 计算机科学与探索 8(2020):1348-1357.

5 MATLAB代码与数据下载地址

见博客主页