一、获取代码方式
获取代码方式1:
完整代码已上传我的资源:【优化算法】精子群优化算法(SSO)【含Matlab源码 1465期】
获取代码方式2:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、部分源代码
%SSO source code v2.0, Generated by Hisham A. Shehadeh, 2021.
clear all
clc
N = 30; % Size of the swarm " no of objects "
Max_Iteration = 1000; % Maximum number of "iterations"
Benchmark_Function_ID= 2 %Benchmark function ID
[sgBestScore,sgBest,GlobalBestCost]= SSO(Benchmark_Function_ID, N, Max_Iteration)
sgBest
sgBestScore
semilogy(GlobalBestCost,'-r');
title(['\fontsize{12}\bf Benchmark Function: F',num2str(Benchmark_Function_ID)]);
xlabel('\fontsize{12}\bf Iteration');ylabel('\fontsize{12}\bf Fitness(Best-so-far)');
legend('\fontsize{10}\bf SSO',1);
%SSO source code v2.0, Generated by Hisham A. Shehadeh, 2021.
%-------------------------------------------%
% Adopted from: %
%-------------------------------------------%
%Shehadeh, H. A. (2021). A hybrid sperm swarm optimization and gravitational search algorithm (HSSOGSA)
%for global optimization. Neural Computing and Applications, 1-14.
%-------------------------------------------%
% Adopted from: %
%-------------------------------------------%
% Shehadeh, H. A., Ahmedy, I., & Idris, M. Y. I. (2018, September).
%Empirical study of sperm swarm optimization algorithm.
%In Proceedings of SAI Intelligent Systems Conference (pp. 1082-1104). Springer, Cham.
%-------------------------------------------%
% Adopted from: %
%-------------------------------------------%
%Shehadeh, H. A., Ahmedy, I., & Idris, M. Y. I. (2018, February).
%Sperm swarm optimization algorithm for optimizing wireless sensor network challenges.
%In Proceedings of the 6th International Conference on Communications and Broadband Networking (pp. 53-59).
% This function calculates the value of objective function.
function fit=benchmark_functions(L,Benchmark_Function_ID,dim)
%You can insert your own objective function with a new Benchmark_Function_ID.
if Benchmark_Function_ID==1
fit=sum(L.^2);
end
if Benchmark_Function_ID==2
fit=sum(abs(L))+prod(abs(L));
end
if Benchmark_Function_ID==3
fit=0;
for i=1:dim
fit=fit+sum(L(1:i))^2;
end
end
if Benchmark_Function_ID==4
fit=max(abs(L));
end
if Benchmark_Function_ID==5
fit=sum(100*(L(2:dim)-(L(1:dim-1).^2)).^2+(L(1:dim-1)-1).^2);
end
if Benchmark_Function_ID==6
fit=sum(abs((L+.5)).^2);
end
if Benchmark_Function_ID==7
fit=sum([1:dim].*(L.^4))+rand;
end
if Benchmark_Function_ID==8
fit=sum(-L.*sin(sqrt(abs(L))));
end
if Benchmark_Function_ID==9
fit=sum(L.^2-10*cos(2*pi.*L))+10*dim;
end
if Benchmark_Function_ID==10
fit=-20*exp(-.2*sqrt(sum(L.^2)/dim))-exp(sum(cos(2*pi.*L))/dim)+20+exp(1);
end
if Benchmark_Function_ID==11
fit=sum(L.^2)/4000-prod(cos(L./sqrt([1:dim])))+1;
end
if Benchmark_Function_ID==12
fit=(pi/dim)*(10*((sin(pi*(1+(L(1)+1)/4)))^2)+sum((((L(1:dim-1)+1)./4).^2).*...
(1+10.*((sin(pi.*(1+(L(2:dim)+1)./4)))).^2))+((L(dim)+1)/4)^2)+sum(Ufun(L,10,100,4));
end
if Benchmark_Function_ID==13
fit=.1*((sin(3*pi*L(1)))^2+sum((L(1:dim-1)-1).^2.*(1+(sin(3.*pi.*L(2:dim))).^2))+...
((L(dim)-1)^2)*(1+(sin(2*pi*L(dim)))^2))+sum(Ufun(L,5,100,4));
end
if Benchmark_Function_ID==14
aS=[-32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32 -32 -16 0 16 32;,...
-32 -32 -32 -32 -32 -16 -16 -16 -16 -16 0 0 0 0 0 16 16 16 16 16 32 32 32 32 32];
for j=1:25
bS(j)=sum((L'-aS(:,j)).^6);
end
fit=(1/500+sum(1./([1:25]+bS))).^(-1);
end
if Benchmark_Function_ID==15
aK=[.1957 .1947 .1735 .16 .0844 .0627 .0456 .0342 .0323 .0235 .0246];
bK=[.25 .5 1 2 4 6 8 10 12 14 16];bK=1./bK;
fit=sum((aK-((L(1).*(bK.^2+L(2).*bK))./(bK.^2+L(3).*bK+L(4)))).^2);
end
if Benchmark_Function_ID==16
fit=4*(L(1)^2)-2.1*(L(1)^4)+(L(1)^6)/3+L(1)*L(2)-4*(L(2)^2)+4*(L(2)^4);
end
if Benchmark_Function_ID==17
fit=(L(2)-(L(1)^2)*5.1/(4*(pi^2))+5/pi*L(1)-6)^2+10*(1-1/(8*pi))*cos(L(1))+10;
end
if Benchmark_Function_ID==18
fit=(1+(L(1)+L(2)+1)^2*(19-14*L(1)+3*(L(1)^2)-14*L(2)+6*L(1)*L(2)+3*L(2)^2))*...
(30+(2*L(1)-3*L(2))^2*(18-32*L(1)+12*(L(1)^2)+48*L(2)-36*L(1)*L(2)+27*(L(2)^2)));
end
if Benchmark_Function_ID==19
aH=[3 10 30;.1 10 35;3 10 30;.1 10 35];cH=[1 1.2 3 3.2];
pH=[.3689 .117 .2673;.4699 .4387 .747;.1091 .8732 .5547;.03815 .5743 .8828];
fit=0;
for i=1:4
fit=fit-cH(i)*exp(-(sum(aH(i,:).*((L-pH(i,:)).^2))));
end
end
if Benchmark_Function_ID==20
aH=[10 3 17 3.5 1.7 8;.05 10 17 .1 8 14;3 3.5 1.7 10 17 8;17 8 .05 10 .1 14];
cH=[1 1.2 3 3.2];
pH=[.1312 .1696 .5569 .0124 .8283 .5886;.2329 .4135 .8307 .3736 .1004 .9991;...
.2348 .1415 .3522 .2883 .3047 .6650;.4047 .8828 .8732 .5743 .1091 .0381];
fit=0;
for i=1:4
fit=fit-cH(i)*exp(-(sum(aH(i,:).*((L-pH(i,:)).^2))));
end
end
aSH=[4 4 4 4;1 1 1 1;8 8 8 8;6 6 6 6;3 7 3 7;2 9 2 9;5 5 3 3;8 1 8 1;6 2 6 2;7 3.6 7 3.6];
cSH=[.1 .2 .2 .4 .4 .6 .3 .7 .5 .5];
if Benchmark_Function_ID==21
fit=0;
for i=1:5
fit=fit-((L-aSH(i,:))*(L-aSH(i,:))'+cSH(i))^(-1);
end
end
if Benchmark_Function_ID==22
fit=0;
for i=1:7
fit=fit-((L-aSH(i,:))*(L-aSH(i,:))'+cSH(i))^(-1);
end
end
if Benchmark_Function_ID==23
fit=0;
for i=1:10
fit=fit-((L-aSH(i,:))*(L-aSH(i,:))'+cSH(i))^(-1);
end
end
function y=Ufun(x,a,k,m)
y=k.*((x-a).^m).*(x>a)+k.*((-x-a).^m).*(x<(-a));
return
三、运行结果
四、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.
[3]施媛波.基于改进的群居蜘蛛优化云计算任务调度算法[J].电脑编程技巧与维护. 2021,(04)
[4]李唐兵,胡锦泓,周求宽.基于改进斑点鬣狗优化算法的红外图像分割[J].红外技术. 2021,43(10)