蜂群算法_原始版本

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



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值