[Optimization] Krill swarm algorithm [including matlab source code 133]

1. Introduction

Origin: According to the foraging characteristics of krill groups, it was first proposed by Gandomi et al. in 2012 [1]. During the movement, the krill groups continue to gather to increase the population density and reduce the chance of being preyed. At the same time, they explore the living area and shorten the distance between them and the food as much as possible, so that the population can obtain food.

Algorithm description:
1. The update formula of the individual krill speed (differential of position X):
Insert picture description here
Explanation: The change of the position of the krill group is affected by three types: the induction of neighbor krill, the influence and disturbance of food position

Induced exercise N
Induced exercise means that each individual krill will be affected by the neighbor krill individuals within a certain range and the individual in the best position. Its formal expression is:
Insert picture description here

Insert picture description here
Foraging movement F is
similar to induced movement. Foraging movement consists of two parts. The first part is the food position, and the second part is the previous experience about the food position. The expression is:
Insert picture description here
Insert picture description here
Insert picture description here
4. Finally, the algorithm steps and flowchart are given

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

Insert picture description here

% 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')
 

Three, running results

Insert picture description here

Four, remarks

Complete code or writing add QQ2449341593 past review
>>>>>>
[Optimization] based on matlab particle swarm optimization gray wolf algorithm [including Matlab source code 006]
[optimization] based on matlab multi-objective gray wolf optimization algorithm MOGWO [including Matlab source code issue 007]
[optimized solution] optimal layout of charging stations based on matlab particle swarm algorithm [including Matlab source code 012]
[optimized solution] multi-traveling salesman problem based on matlab genetic algorithm [including Matlab source code 016]
[optimized solution 】Find the shortest path based on matlab genetic algorithm [including Matlab source code 023]
[Optimization solution] 3D packing problem based on matlab genetic and simulated annealing [including Matlab source code 031]
[Optimization solution] Solve the optimization of vehicle departure interval based on matlab genetic algorithm Problem [With Matlab source code 132 period]

Guess you like

Origin blog.csdn.net/TIQCmatlab/article/details/113097872