由来:根据磷虾群觅食的特性,由Gandomi等在2012年首次提出[1]。在运动过程中,磷虾群不断地聚集以增大种群密度,并减少被捕食的几率,同时探索生存区域,尽可能缩短它们与食物的距离,最终使得种群获得食物。

算法描述:

1、磷虾个体的速度(位置X的微分)更新公式:

【优化求解】磷虾群算法(Krill Herd Algorithm,KHA)_matlab

解释:磷虾群位置的变化受到三种影响:邻居磷虾的诱导,食物位置的影响和扰动

诱导运动N

诱导运动指的是,每一个磷虾个体会受到其一定范围内的邻居磷虾个体和最佳位置的个体的影响。其形式化表达为:

【优化求解】磷虾群算法(Krill Herd Algorithm,KHA)_优化求解_02

【优化求解】磷虾群算法(Krill Herd Algorithm,KHA)_matlab_03

觅食运动F

类似于诱导运动,觅食运动包含两个部分,第一部分是食物位置,第二部分是先前关于食物位置的经验。表达形式是:

【优化求解】磷虾群算法(Krill Herd Algorithm,KHA)_matlab_04

【优化求解】磷虾群算法(Krill Herd Algorithm,KHA)_matlab_05

【优化求解】磷虾群算法(Krill Herd Algorithm,KHA)_优化求解_06

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
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

【优化求解】磷虾群算法(Krill Herd Algorithm,KHA)_matlab_07

参考资料:

论文:

  1. Krill herd_ a new bio-inspired optimization algorithm
  2. 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 = 10*ones(1,10);
LB = -10*ones(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, Ron_No] = min(Kgb(end,:))
Xgb(:,end,Ron_No)
Mean = mean(Kgb(end,:))
Worst = max(Kgb(end,:))
Standard_Deviation = std(Kgb(end,:))

% Convergence plot of the best run
semilogy(1:MI+1,Kgb(:,Ron_No),1:MI+1,mean(Kgb'))
xlabel('{\itNo. of Iterations}')
ylabel('{\itf}({\bfx_{best}})')
legend('Best run values','Average run values')

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.

【优化求解】磷虾群算法(Krill Herd Algorithm,KHA)_优化求解_08