function main_peaks
clc; close all; clear all;
%% Setting the Parameter for the Algorithm
n= 30; % number of scout bees (e.g. 40-100)
itr=15; % number of iterations (e.g. 1000-5000)
m=20; % number of best selected patches (e.g. 10-50)
e=10; % number of elite selected patches (e.g. 10-50)
n1=15; % number of recruited bees around best selected patches (e.g. 10-50)
n2=30; % number of recruited bees around elite selected patches (e.g. 10-50)
ngh=0.0234; % Patch radius for neighbourhood search
x_max=3;
y_max=3;
x_min=-3;
y_min=-3;
Grid_step=0.05;
%% Plotting the Matlab Peaks Testfunction
[X1, X2]=meshgrid(x_min:Grid_step:x_max,y_min:Grid_step:y_max);
fig(1)= figure('PaperSize',[20.98 29.68],'WindowStyle','docked');
ax(1)=surf(X1,X2,peaks(X1,X2),'FaceColor',[0.6824 0.4667 0], 'EdgeColor','none','FaceLighting','phong');
view([-47 20]); camlight left; hold on;
title({'Basic Bees Algorithm used with Peaks Function';'\copyright 2007 MEC Steffen Scholz, Ahmed Haj Darwish'});
%% Scoutbees: random search (only once)
U=X_random(n,x_max, y_max, x_min, y_min);
ax(1)=plot3(U(:,1),U(:,2),peaks(U(:,1),U(:,2)),'k.');
Par_Q=sortrows([U(:,1), U(:,2), peaks(U(:,1),U(:,2))],-3);
clear U; l=0;
%% Iterations of the algorithm
for k=1:itr % iterations
disp(sprintf('Interation Number: %02.0f',k));
% ______________________________________________________________________
for j=1:e % number of elite selected patches
for i=1:n2 % number of bees around elite patches
U=bee_dance(ngh, Par_Q(j,1), Par_Q(j,2));
if peaks(U(1),U(2))> Par_Q(j,3)
Par_Q(j,:)=[U(1), U(2), peaks(U(1),U(2))];
ax(1)=plot3(U(1), U(2), peaks(U(1), U(2)),'r.');
end
l=l+1;
end
end
% _______________________________________________________________________
for j=e+1:m % number of best selected patches
for i=1 : n1 % number of bees around best patches
U=bee_dance(ngh,Par_Q(j,1),Par_Q(j,2));
if peaks(U(1),U(2))> Par_Q(j,3)
Par_Q(j,:)=[U(1), U(2), peaks(U(1), U(2))];
ax(1)=plot3 (U(1), U(2), peaks(U(1), U(2)), 'b.');
end
l=l+1;
end
end
% _______________________________________________________________________
for i=m+1:n
U=X_random(2,x_max, y_max, x_min, y_min);
Par_Q(i,:)=[U(1), U(2), peaks(U(1),U(2))];
ax(1)=plot3(U(1), U(2), peaks(U(1), U(2)), 'k.');
l=l+1;
end
% _______________________________________________________________________
Par_Q=sortrows(Par_Q,-3);
Best(k,:)=Par_Q(1:15,3)';
% Interation Number: 01~15
end % iterations
kkk=1
蜂群算法_原始版本
最新推荐文章于 2024-02-25 14:30:35 发布