این هم یک کد دلفی برای کلونی زنبور
كد:
var i,j,k,ks:integer;
begin
GetParamsSetValues();
gen:=0;
randomize;
minstop:=false;
initial;
eval:=0;
for i:=1 to np do
CalculateFunction(i);
for i:=1 to np do
begin
pf[i]:=f[i];
pfit[i]:=fit[i];
end;
sortfitness;
minf:=pf[1];
enfit:=pfit[1];
for k:=1 to d do
en[k]:=p[1,k];
REPEAT
gen:=gen+1;
for i:=1 to e do
begin
for j:=1 to n1 do
begin
for k:=1 to d do
x[i,k]:=p[i,k]+ngh*(2*random-1);
CalculateFunction(i);
if fit[i]>pfit[i] then
begin end
eval:=eval+1;
end;//for j
end; // for i
for i:=e+1 to m do
begin
for j:=1 to n2 do
begin
for k:=1 to d do
x[i,k]:=p[i,k]+ngh*(2*random-1);
CalculateFunction(i);
if fit[i]>pfit[i] then
begin
pfit[i]:=fit[i];
pf[i]:=f[i];
for k:=1 to d do
p[i,k]:=x[i,k];
end;//if
eval:=eval+1;
end;//for j
end; // for i
for i:=m+1 to np do
begin
for k:=1 to d do
x[i,k]:=xlo[j]+random*(xhi[k]-xlo[k]);
CalculateFunction(i);
pfit[i]:=fit[i];
pf[i]:=f[i];
for k:=1 to d do
p[i,k]:=x[i,k];
eval:=eval+1;
end; // for i
sortfitness;
minf:=pf[1];
enfit:=pfit[1];
for k:=1 to d do
en[k]:=p[1,k];
if abs(minf-desired) min[gen]:=min[gen]+minf;
UNTIL ((gen=maxgen)or(minstop=true));
end.