%
%
%
function pop = RunFLA(pop, params)
%%FLA 参数
q = params.q; % 父母人数
alpha = params.alpha; % 后代数量
beta = params.beta; %最大迭代次数
sigma = params.sigma;
CostFunction = params.CostFunction;
VarMin = params.VarMin;
VarMax = params.VarMax;
VarSize = size(pop(1).Position);
BestSol = params.BestSol;
nPop = numel(pop); % 选择概率
P = 2*(nPop+1-(1:nPop))/(nPop*(nPop+1)); % 选择概率
% 计算种群范围(最小超立方体)
LowerBound = pop(1).Position;
UpperBound = pop(1).Position;
for i = 2:nPop
LowerBound = min(LowerBound, pop(i).Position);
UpperBound = max(UpperBound, pop(i).Position);
end
%%FLA 主循环
for it = 1:beta
%选择父母
L = RandSample(P,q);
B = pop(L);
%产生后代
for k=1:alpha
%对人口进行排序
[B, SortOrder] = SortPopulation(B);
L = L(SortOrder);
% 标志
ImprovementStep2 = false;
Censorship = false;
% 改进步骤 1
NewSol1 = B(end);
Step = sigma*rand(VarSize).*(B(1).Position-B(end).Position);
NewSol1.Position = B(end).Position + Step;
if IsInRange(NewSol1.Position, VarMin, VarMax)
NewSol1.Cost = CostFunction(NewSol1.Position);
if NewSol1.Cost<B(end).Cost
B(end) = NewSol1;
else
ImprovementStep2 = true;
end
else
ImprovementStep2 = true;
end
%改进步骤 2
if ImprovementStep2
NewSol2 = B(end);
Step = sigma*rand(VarSize).*(BestSol.Position-B(end).Position);
NewSol2.Position = B(end).Position + Step;
if IsInRange(NewSol2.Position, VarMin, VarMax)
NewSol2.Cost = CostFunction(NewSol2.Position);
if NewSol2.Cost<B(end).Cost
B(end) = NewSol2;
else
Censorship = true;
end
else
Censorship = true;
end
end
% 审查制度
if Censorship
B(end).Position = unifrnd(LowerBound, UpperBound);
B(end).Cost = CostFunction(B(end).Position);
end
end
% 将子复合体返回到主复合体
pop(L) = B;
end
end