1 简介

【优化求解】基于School Based Optimization (SBO)求解单目标_优化算法

【优化求解】基于School Based Optimization (SBO)求解单目标_优化算法_02

【优化求解】基于School Based Optimization (SBO)求解单目标_优化算法_03

【优化求解】基于School Based Optimization (SBO)求解单目标_优化算法_04

【优化求解】基于School Based Optimization (SBO)求解单目标_优化算法_05

2 部分代码


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

          
          
%%
  • 1.

          
          
clc
  • 1.

          
          
clear all
  • 1.

          
          
close all
  • 1.

          
          
global D
  • 1.

          
          
% Specity SBO parameters
  • 1.

          
          
Itmax=300; % Maximum number of iterations
  • 1.

          
          
NClass=5; % Number of classes in the school
  • 1.

          
          
PopSize=15; % Population size of each class
  • 1.

          
          
% Optimization problem parameters
  • 1.

          
          
D=Data10; % For truss function evaluate the functio to get the initial parameters
  • 1.

          
          
LB=D.LB; % Lowerbound
  • 1.

          
          
UB=D.UB; % Upperbound
  • 1.

          
          
FN='ST10'; % Name of analyzer function
  • 1.

          
          
%% Randomely generate initial designs between LB and UB
  • 1.

          
          
Cycle=1;
  • 1.

          
          
for I=1:PopSize
  • 1.

          
          
for NC=1:NClass
  • 1.

          
          
Designs{NC}(I,:)=LB+rand(1,size(LB,2)).*(UB-LB); % Row vector
  • 1.

          
          
end
  • 1.

          
          
end
  • 1.

          
          
% Analysis the designs
  • 1.

          
          
for NC=1:NClass
  • 1.

          
          
[PObj{NC},Obj{NC}]=Analyser(Designs{NC},FN);
  • 1.

          
          
Best{NC}=[];
  • 1.

          
          
end
  • 1.

          
          
%% SBO loop
  • 1.

          
          
for Cycle=2:Itmax
  • 1.

          
          
for NC=1:NClass
  • 1.

          
          
% Identify best designs and keep them
  • 1.

          
          
[Best{NC},Designs{NC},PObj{NC},Obj{NC},WMeanPos{NC}]=Specifier(PObj{NC},Obj{NC},Designs{NC},Best{NC});
  • 1.

          
          
TeachersPObj(NC,1)=Best{NC}.GBest.PObj;
  • 1.

          
          
TeachersDes(NC,:)=Best{NC}.GBest.Design;
  • 1.

          
          
end
  • 1.

          
          
for NC=1:NClass
  • 1.

          
          
% Select a teacher
  • 1.

          
          
SelectedTeacher=TeacherSelector(Best,NC,TeachersPObj);
  • 1.

          
          
% Apply Teaching
  • 1.

          
          
[Designs{NC},PObj{NC},Obj{NC}]=Teaching(LB,UB,Designs{NC},PObj{NC},Obj{NC},TeachersDes(SelectedTeacher,:),WMeanPos{NC},FN);
  • 1.

          
          
[Best{NC},Designs{NC},PObj{NC},Obj{NC},WMeanPos{NC}]=Specifier(PObj{NC},Obj{NC},Designs{NC},Best{NC});
  • 1.

          
          
% Apply Learning
  • 1.

          
          
[Designs{NC},PObj{NC},Obj{NC}]=Learning(LB,UB,Designs{NC},Obj{NC},PObj{NC},FN);
  • 1.

          
          
[Best{NC},Designs{NC},PObj{NC},Obj{NC},WMeanPos{NC}]=Specifier(PObj{NC},Obj{NC},Designs{NC},Best{NC});
  • 1.

          
          
end
  • 1.

          
          
% Find best so far solution and Mean
  • 1.

          
          
CumPObj=[];
  • 1.

          
          
for NC=1:NClass
  • 1.

          
          
ClassBestPObj(NC,1)=Best{NC}.GBest.PObj;
  • 1.

          
          
ClassMean(NC,1)=mean(PObj{NC});
  • 1.

          
          
CumPObj=[CumPObj;PObj{NC}];
  • 1.

          
          
end
  • 1.

          
          
[~,b]=min(ClassBestPObj);
  • 1.

          
          
OveralBestPObj=Best{b}.GBest.PObj;
  • 1.

          
          
OveralBestObj=Best{b}.GBest.Obj;
  • 1.

          
          
OveralBestDes=Best{b}.GBest.Design;
  • 1.

          
          
% Plot time history of the best solution vs. iteration and print the
  • 1.

          
          
% results
  • 1.

          
          
hold on;plot(Cycle,Best{b}.GBest.PObj,'b*');xlabel('Iteration');ylabel('Best solution value');pause(0.0001)
  • 1.

          
          
fprintf('Cycle: %6d, Best (Penalized): %6.4f, Objective: %6.4f\n',Cycle,OveralBestPObj,OveralBestObj);
  • 1.

          
          
end
  • 1.

          
          
Solution.PObj=OveralBestPObj;% Objective value for best non-penalized solution
  • 1.

          
          
Solution.Design=OveralBestDes;% Design for best non-penalized solution
  • 1.

          
          
img =gcf; %获取当前画图的句柄
  • 1.

          
          
print(img, '-dpng', '-r600', './img.png') %即可得到对应格式和期望dpi的图像
  • 1.

          
          
%% Save the results
  • 1.

          
          
save('SBO_Results.mat','Solution')
  • 1.

3 仿真结果

【优化求解】基于School Based Optimization (SBO)求解单目标_优化算法_06

4 参考文献

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

【优化求解】基于School Based Optimization (SBO)求解单目标_优化算法_07