受精优化算法(Fertilization Optimization algorithm, FO)
基本原理:受精优化算法(Fertilization Optimization algorithm,FO)是一种受哺乳动物繁殖过程中卵子受精启发的生物学算法,用以解决现实世界中的复杂优化问题。
参考文献:Fertilization optimization algorithm on CEC2015 and large-scale problems.
该博客主要分享FO算法的代码,并带有中文注释!
分享不易,喜欢的请大家点赞加收藏,谢谢!
FO算法主程序如下:
% Fertilization optimization algorithm(FO)
% Reference:Fertilization optimization algorithm on CEC2015 and large scale problems
% Code by Luzhenhui Yangtze University
clc
clear
%% 优化问题定义(测试函数)
CostFunction = @(x) Sphere(x); % 目标方程
nVar = 25; % 变量数目
v_size = [1 nVar]; % 变量矩阵大小
v_min = -10; % 变量取值下界
v_max = 10; % 变量取值上界
%% 算法参数
nPop = 50; % 算法种群个体数目
MaxIt = 1000; % 算法最大迭代次数
%% 算法初始化
empty_sperm.Position = [];
empty_sperm.velocity = [];
empty_sperm.Cost = [];
sperm = repmat(empty_sperm, nPop, 1);
for i = 1:nPop
% 种群个体位置信息的初始化
sperm(i).Position = unifrnd(v_min, v_max, v_size);
sperm(i).velocity = sperm(i).Position;
% 种群个体所对应的适应度值
sperm(i).Cost = CostFunction(sperm(i).Position);
end
bestfits = zeros(MaxIt, 1); % 用于记录每次迭代的最优值
%% 算法的主要流程
x=1;
d=0.95;
for it=1:MaxIt
newsperm = [];
for i = 1:nPop
K= (sperm(1).Position+sperm(round(nPop/2)).Position+sperm(end).Position)/3;
newsol = empty_sperm;
L = Levy(nVar);
newsol.velocity = exp(-1/x)*sperm(i).velocity;
ds=L.*(sperm(i).Position-sperm(i).velocity);
newsol.Position = sperm(i).Position - newsol.velocity+ds-K;
newsol.Position = max(newsol.Position, v_min);
newsol.Position = min(newsol.Position, v_max);
newsol.Cost = CostFunction(newsol.Position);
newsperm = [newsperm
newsol];
end
sperm = [sperm
newsperm ];
[~, SortOrder]=sort([sperm.Cost]);
sperm = sperm(SortOrder);
if numel(sperm)>nPop
sperm = sperm(1:nPop);
end
BestSol = sperm(1);
bestfits(it) = BestSol.Cost;
x=x*d;
disp(['It ' num2str(it) ': Best Cost = ' num2str(bestfits(it))]);
end
figure;
semilogy(bestfits,'LineWidth',3);
xlabel('Iteration');
ylabel('Best Cost');
grid on;