|
function [Xt,Yt] = FSA_center( Xi, Yi, II, pop, pro, popminmax, sizepop, visual, step, try_number, delta,BestPop )
%function [Xt,Yt] = FSA_center( Xi, Yi, pop, pro, popminmax, sizepop, visual, step, try_number, delta,BestPop )
% 聚群行为
popmin = popminmax(1); popmax = popminmax(2); % x1
V = length(Xi);M = length(Yi);%xi,yi当前个体位置
% Xi = pop(j,:); % 当前的种群
% Yi = fitness(j); % 当前种群对应的适应度值
for k=1:sizepop
d(k) = norm( Xi-pop(k,1:V) ,2); %计算二范数,即所谓距离
end
[~,b] = find( d>0 & d<visual );%取出符合条件的个体,即在视野范围内
if(~isempty(b))%确定数组是否为空,~isempty(A)表示如果A是空元素,结果为0,否则结果为1。
Xc = zeros( size(pop(1,1:V)) );%%%不为空的话则执行该条语句,为空的话执行觅食行为。%%%%size获取矩阵大小(本文设置的是1行4列),zero把该矩阵赋值为0,即把Xc初始化为1*4数组,元素为0
for k=1:length(b)%%返回向量长度,%%%既符合要求的个体(猜)
Xc = Xc+pop(b(k),1:V);%%取出符合条件的个体
end
Xc = Xc./length(b);%%
Xc =(Xc-Xi+BestPop(1:V)-Xi)+Xi;
Yc = evaluate_objective(Xc,pro); % 适应度值
Dis = FishDis([pop;Xc Yc],M,V);
if Domination2(Yc,Yi) && Dis(end)>Dis(II) %%聚群行为的判断条件
% if Domination2(Yc,Yi) && delta>Dis(end)
Xt = Xi + ( Xc - Xi )./norm(Xc-Xi,2) .* step .*rand(1);
Xt=PopWs(Xt,pro);
Yt = evaluate_objective(Xt,pro); % 适应度值
else
% 觅食行为
[Xt,Yt] = FSA_find( Xi, Yi,pro, popminmax, visual, step, try_number,BestPop(1:V) );
end
else
% 觅食行为
[Xt,Yt] = FSA_find( Xi, Yi,pro, popminmax, visual, step, try_number,BestPop(1:V) );
end
|
|