standard and probabilistic bee algorithm explanation

%% Problem Definition
CostFunction=@(x) Sphere(x); % Cost Function
nVar=5; % Number of Decision Variables
VarSize=[1 nVar]; % Decision Variables Matrix Size
VarMin=-10; % Decision Variables Lower Bound
VarMax= 10; % Decision Variables Upper Bound
%% Bees Algorithm Parameters
MaxIt=1000; % Maximum Number of Iterations
nScoutBee=30; % Number of Scout Bees
nSelectedSite=round(0.5*nScoutBee); % Number of Selected Sites
nEliteSite=round(0.4*nSelectedSite); % Number of Selected Elite Sites
nSelectedSiteBee=round(0.5*nScoutBee); % Number of Recruited Bees for Selected Sites
nEliteSiteBee=2*nSelectedSiteBee; % Number of Recruited Bees for Elite Sites
r=0.1*(VarMax-VarMin); % Neighborhood Radius
rdamp=0.95; % Neighborhood Radius Damp Rate
%% Initialization
% Empty Bee Structure
empty_bee.Position=[];
empty_bee.Cost=[];
% Initialize Bees Array
bee=repmat(empty_bee,nScoutBee,1);
% Create New Solutions
for i=1:nScoutBee
bee(i).Position=unifrnd(VarMin,VarMax,VarSize);
bee(i).Cost=CostFunction(bee(i).Position);
end
% Sort
[~, SortOrder]=sort([bee.Cost]);
bee=bee(SortOrder);
% Update Best Solution Ever Found
BestSol=bee(1);
% Array to Hold Best Cost Values
BestCost=zeros(MaxIt,1);
%% Bees Algorithm Main Loop
for it=1:MaxIt
% Elite Sites
for i=1:nEliteSite
bestnewbee.Cost=inf;
for j=1:nEliteSiteBee
newbee.Position=PerformBeeDance(bee(i).Position,r);
newbee.Cost=CostFunction(newbee.Position);
if newbee.Cost<bestnewbee.Cost
bestnewbee=newbee;
end
end
if bestnewbee.Cost<bee(i).Cost
bee(i)=bestnewbee;
end
end
% Selected Non-Elite Sites
for i=nEliteSite+1:nSelectedSite
bestnewbee.Cost=inf;
for j=1:nSelectedSiteBee
newbee.Position=PerformBeeDance(bee(i).Position,r);
newbee.Cost=CostFunction(newbee.Position);
if newbee.Cost<bestnewbee.Cost
bestnewbee=newbee;
end
end
if bestnewbee.Cost<bee(i).Cost
bee(i)=bestnewbee;
end
end
% Non-Selected Sites
for i=nSelectedSite+1:nScoutBee
bee(i).Position=unifrnd(VarMin,VarMax,VarSize);
bee(i).Cost=CostFunction(bee(i).Position);
end
% Sort
[~, SortOrder]=sort([bee.Cost]);
bee=bee(SortOrder);
% Update Best Solution Ever Found
BestSol=bee(1);
% Store Best Cost Ever Found
BestCost(it)=BestSol.Cost;
% Display Iteration Information
disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(BestCost(it))]);
% Damp Neighborhood Radius
r=r*rdamp;
end
%% Results
figure;
%plot(BestCost,'LineWidth',2);
semilogy(BestCost,'LineWidth',2);
xlabel('Iteration');
ylabel('Best Cost');

6 Comments

Do you have a question?
explanation of the code about objective function of the code and constrants available in the code
You want someone to go through this code line by line and explain it to you? That's a lot to ask. Maybe you could instead ask about specific parts of the code that you don't understand.
In depth explanations of lengthy codes are way beyond the scope of Answers. That could require some to spend hours or days of time, writing explanations for things you already understand, including teaching you an entire course about optimization here, as well as MATLAB itself.
If you have a SPECIFIC question about a line in the code, then ask it. Otherwise, your question is far too broad.
only about which is the objective function and the constraints in the bee algorithm
I have some knowladge about matlab and optimization.i want to modify it for my research that is why i want about the abjective function and constriants.

Sign in to comment.

Answers (0)

Categories

Find more on Physics in Help Center and File Exchange

Tags

Asked:

on 12 Jun 2020

Commented:

on 13 Jun 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!