【优化求解】基于School Based Optimization (SBO)求解单目标问题matlab源码

1 简介

2 部分代码

%% This function implements the basic School Based Optimization (SBO) algorithm for 10-bar truss optimization

%%
clc
clear all
close all
global D
% Specity SBO parameters
Itmax=300;                                                                 % Maximum number of iterations
NClass=5;                                                                  % Number of classes in the school
PopSize=15;                                                                % Population size of each class
% Optimization problem parameters
D=Data10;                                                                  % For truss function evaluate the functio to get the initial parameters
LB=D.LB;                                                                   % Lowerbound
UB=D.UB;                                                                   % Upperbound
FN='ST10';                                                                 % Name of analyzer function

%% Randomely generate initial designs between LB and UB
Cycle=1;
for I=1:PopSize
   for NC=1:NClass
       Designs{NC}(I,:)=LB+rand(1,size(LB,2)).*(UB-LB);                   % Row vector
   end
end

% Analysis the designs
for NC=1:NClass
  [PObj{NC},Obj{NC}]=Analyser(Designs{NC},FN);
   Best{NC}=[];
end

%% SBO loop
for Cycle=2:Itmax
   for NC=1:NClass
       % Identify best designs and keep them
      [Best{NC},Designs{NC},PObj{NC},Obj{NC},WMeanPos{NC}]=Specifier(PObj{NC},Obj{NC},Designs{NC},Best{NC});
       TeachersPObj(NC,1)=Best{NC}.GBest.PObj;
       TeachersDes(NC,:)=Best{NC}.GBest.Design;
   end
   for NC=1:NClass
       % Select a teacher
       SelectedTeacher=TeacherSelector(Best,NC,TeachersPObj);
       % Apply Teaching
      [Designs{NC},PObj{NC},Obj{NC}]=Teaching(LB,UB,Designs{NC},PObj{NC},Obj{NC},TeachersDes(SelectedTeacher,:),WMeanPos{NC},FN);
      [Best{NC},Designs{NC},PObj{NC},Obj{NC},WMeanPos{NC}]=Specifier(PObj{NC},Obj{NC},Designs{NC},Best{NC});
       % Apply Learning
      [Designs{NC},PObj{NC},Obj{NC}]=Learning(LB,UB,Designs{NC},Obj{NC},PObj{NC},FN);
      [Best{NC},Designs{NC},PObj{NC},Obj{NC},WMeanPos{NC}]=Specifier(PObj{NC},Obj{NC},Designs{NC},Best{NC});
   end
   % Find best so far solution and Mean
   CumPObj=[];
   for NC=1:NClass
       ClassBestPObj(NC,1)=Best{NC}.GBest.PObj;
       ClassMean(NC,1)=mean(PObj{NC});
       CumPObj=[CumPObj;PObj{NC}];
   end
  [~,b]=min(ClassBestPObj);
   OveralBestPObj=Best{b}.GBest.PObj;
   OveralBestObj=Best{b}.GBest.Obj;
   OveralBestDes=Best{b}.GBest.Design;
   % Plot time history of the best solution vs. iteration and print the
   % results
   hold on;plot(Cycle,Best{b}.GBest.PObj,'b*');xlabel('Iteration');ylabel('Best solution value');pause(0.0001)
   fprintf('Cycle: %6d, Best (Penalized): %6.4f, Objective: %6.4f\n',Cycle,OveralBestPObj,OveralBestObj);    
end

Solution.PObj=OveralBestPObj;% Objective value for best non-penalized solution
Solution.Design=OveralBestDes;% Design for best non-penalized solution
img =gcf;  %获取当前画图的句柄
print(img, '-dpng', '-r600', './img.png')         %即可得到对应格式和期望dpi的图像
%% Save the results
save('SBO_Results.mat','Solution')

3 仿真结果

4 参考文献

[1] Farshchin, M. , et al. "School based optimization algorithm for design of steel frames." Engineering Structures 171(2018):326-335.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Matlab科研辅导帮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值