由来:根据磷虾群觅食的特性,由Gandomi等在2012年首次提出[1]。在运动过程中,磷虾群不断地聚集以增大种群密度,并减少被捕食的几率,同时探索生存区域,尽可能缩短它们与食物的距离,最终使得种群获得食物。
算法描述:
1、磷虾个体的速度(位置X的微分)更新公式:
解释:磷虾群位置的变化受到三种影响:邻居磷虾的诱导,食物位置的影响和扰动
诱导运动N
诱导运动指的是,每一个磷虾个体会受到其一定范围内的邻居磷虾个体和最佳位置的个体的影响。其形式化表达为:
觅食运动F
类似于诱导运动,觅食运动包含两个部分,第一部分是食物位置,第二部分是先前关于食物位置的经验。表达形式是:
4、最后给出算法步骤和流程图
I. Data Structures: 定义边界,确定算法参数(种群规模Np,最大迭代次数t^max,最大诱导速度N^max,最大觅食速度V_f,最大随机扩散速度D^max,诱导惯性权重w_n,觅食惯性权重w_f和步长缩放因子C_t)等. II. Initialization: 在搜索空间里随机产生初始种群. III. Fitness evaluation: 根据磷虾的位置对每个磷虾个体进行评估(适应值函数计算/优化目标函数计算). IV. Motion calculation:速度分量计算,计算运动速度和位置 * Motion induced by the presence of other individuals * Foraging motion * Physical diffusion V. Implement the genetic operators:多只采用交叉操作 VI. Updating: 在搜索空间内更新个体位置. VII. Repeating:t=t+1, 返回步骤 III 直到满足停止条件(最大迭代次数t^max). VIII. End
参考资料:
论文:
- Krill herd_ a new bio-inspired optimization algorithm
An improved krill herd algorithm: Krill herd with linear decresing step
编辑于 2020-04-01
``` % Krill Herd Algorithm V 1.1
% Main paper: % Gandomi A.H., Alavi A.H., Krill Herd: A New Bio-Inspired Optimization Algorithm. % Communications in Nonlinear Science and Numerical Simulation,
function KH clc; close all; clear all format long
%% Initial Parameter Setting NR = 10; % Number if Runs NK = 25; % Number if Krills MI = 200; % Maximum Iteration C_flag = 1; % Crossover flag [Yes=1]
% Bounds (Normalize search space in case of highly imbalanced search space) UB = 10ones(1,10); LB = -10ones(1,10);
NP = length(LB); % Number if Parameter(s) Dt = mean(abs(UB-LB))/2; % Scale Factor
F = zeros(NP,NK);D = zeros(1,NK);N = zeros(NP,NK); %R = zeros(NP,NK); Vf = 0.02; Dmax = 0.005; Nmax = 0.01; Sr = 0; %% Optimization & Simulation for nr = 1:NR %Initial Krills positions for z1 = 1:NP X(z1,:) = LB(z1) + (UB(z1) - LB(z1)).*rand(1,NK); end
for z2 = 1:NK
K(z2)=cost(X(:,z2));
end
Kib=K;
Xib=X;
[Kgb(1,nr), A] = min(K);
Xgb(:,1,nr) = X(:,A);
for j = 1:MI
% Virtual Food
for ll = 1:NP;
Sf(ll) = (sum(X(ll,:)./K));
end
Xf(:,j) = Sf./(sum(1./K)); %Food Location
Xf(:,j) =findlimits(Xf(:,j)',LB,UB,Xgb(:,j,nr)');% Bounds Checking
Kf(j) = cost(Xf(:,j));
if 2<=j
if Kf(j-1)<Kf(j)
Xf(:,j) = Xf(:,j-1);
Kf(j) = Kf(j-1);
end
end
Kw_Kgb = max(K)-Kgb(j,nr);
w = (0.1+0.8*(1-j/MI));
for i = 1:NK
% Calculation of distances
Rf = Xf(:,j)-X(:,i);
Rgb = Xgb(:,j,nr)-X(:,i);
for ii = 1:NK
RR(:,ii) = X(:,ii)-X(:,i);
end
R = sqrt(sum(RR.*RR));
% % % % % % % % % % % % % Movement Induced % % % % % % % % % %
% Calculation of BEST KRILL effect
if Kgb(j,nr) < K(i)
alpha_b = -2*(1+rand*(j/MI))*(Kgb(j,nr) - K(i)) /Kw_Kgb/ sqrt(sum(Rgb.*Rgb)) * Rgb;
else
alpha_b=0;
end
% Calculation of NEIGHBORS KRILL effect
nn=0;
ds = mean(R)/5;
alpha_n = 0;
for n=1:NK
if and(R<ds,n~=i)
nn=nn+1;
if and(nn<=4,K(i)~=K(n))
alpha_n = alpha_n-(K(n) - K(i)) /Kw_Kgb/ R(n) * RR(:,n);
end
end
end
% Movement Induced
N(:,i) = w*N(:,i)+Nmax*(alpha_b+alpha_n);
% % % % % % % % % % % % % Foraging Motion % % % % % % % % % %
% Calculation of FOOD attraction
if Kf(j) < K(i)
Beta_f=-2*(1-j/MI)*(Kf(j) - K(i)) /Kw_Kgb/ sqrt(sum(Rf.*Rf)) * Rf;
else
Beta_f=0;
end
% Calculation of BEST psition attraction
Rib = Xib(:,i)-X(:,i);
if Kib(i) < K(i)
Beta_b=-(Kib(i) - K(i)) /Kw_Kgb/ sqrt(sum(Rib.*Rib)) *Rib;
else
Beta_b=0;
end
% Foraging Motion
F(:,i) = w*F(:,i)+Vf*(Beta_b+Beta_f);
% % % % % % % % % % % % % Physical Diffusion % % % % % % % % %
D = Dmax*(1-j/MI)*floor(rand+(K(i)-Kgb(j,nr))/Kw_Kgb)*(2*rand(NP,1)-ones(NP,1));
end
%% Post-Processing [Best, RonNo] = min(Kgb(end,:)) Xgb(:,end,RonNo) Mean = mean(Kgb(end,:)) Worst = max(Kgb(end,:)) Standard_Deviation = std(Kgb(end,:))
% Convergence plot of the best run semilogy(1:MI+1,Kgb(:,RonNo),1:MI+1,mean(Kgb')) xlabel('{\itNo. of Iterations}') ylabel('{\itf}({\bfx{best}})') legend('Best run values','Average run values') ```