资源简介
完整的可直接运行的磷虾群优化算法,对需要进行智能优化的小伙伴有帮助。代码上有详细注释,根据不同的模块进行了分块。
代码片段和文件信息
% Krill Herd Algorithm V 1.1
% By Amir H. Gandomi (a.h.gandomi@gmail.com)
% Main paper:
% Gandomi A.H. Alavi A.H. Krill Herd: A New Bio-Inspired Optimization Algorithm.
% Communications in Nonlinear Science and Numerical Simulation
% 2012 17 (12):4831-4845.
% DOI: 10.1016/j.cnsns.2012.05.010
% Boundary Constraint Handling Scheme used in this code:
% Gandomi A.H. Yang X.S. “Evolutionary Boundary Constraint Handling Scheme“
% Neural Computing & Applications 2012 21(6):1449-1462.
% DOI: 10.1007/s00521-012-1069-0
function KH
clc; close all; clear all
format long % long fixed-decimal format 15bit
%% 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(110);
LB = -10*ones(110);
NP = length(LB); % Number if Parameter(s) 粒子的参数的个数
Dt = mean(abs(UB-LB))/2; % Scale Factor delta t 速度向量的缩放因子
F = zeros(NPNK);D = zeros(1NK);N = zeros(NPNK); %R = zeros(NPNK);
Vf = 0.02; %最大觅食速度 measured values
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(1NK);
end
%% 评价每个粒子的适应度值
for z2 = 1:NK
K(z2)=cost(X(:z2));
end
%%
Kib=K;%Kib:best fitness number of ith krill
Xib=X;%Xib:best visited position of ith krill
[Kgb(1nr) A] = min(K);%current best fitness value of X at round nr
Xgb(:1nr) = X(:A);%current best solution
%%
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)‘LBUBXgb(:jnr)‘);% Bounds Checking
Kf(j) = cost(Xf(:j));%fitness value of food at iterator j
if 2<=j%gain best fitness value of food at iterator j
if Kf(j-1) Xf(:j) = Xf(:j-1);
Kf(j) = Kf(j-1);
end
end
Kw_Kgb = max(K)-Kgb(jnr);%K_worst-K_best of j iterator at round nr
w = (0.1+0.8*(1-j/MI));%inertia weight of the motion induced(wn) and the foraging motion(wf) in the range[01]
%%
for i = 1:NK %处理每个粒子
% Calculation of distances
Rf = Xf(:j)-X(:i);%Rf是Xifood
Rgb = Xgb(:jnr)-X(:i);%Rgb是Xibest
for ii = 1:NK
RR(:ii) = X(:ii)-X(:i);
end
R = sqrt(sum(RR.*RR));
%% step3_1 Movement Induced 诱导速度Ni
% Calculation of BEST KRILL effect
if Kgb(jnr) < K
- 上一篇:matlab解N维方程组的代码
- 下一篇:Matlab实现Gabor提取图片纹理
评论
共有 条评论