First, the way to obtain the code

Get the code 1: by subscribing to the paid column of purple Pole Shenguang blog, you can get this code with payment voucher, private letter bloggers.

Access code 2: Open CSDN membership through the homepage of CSDN blog, and the code can be obtained by payment voucher and private letter bloggers.

[optimization algorithm] Sperm group optimization algorithm (SSO) [Matlab source code 1465 issue]

Note: For CSDN membership, only one code can be obtained free of charge (valid within three days from the date of opening); Subscribe to the paid column of purple Pole Shenguang blog, you can get 2 copies of the code for free (valid for three days from the subscription date);

Two, some source code

%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. 5359).

% 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) (2) - 4 * * L (L ^ 2 (2)) + 4 * (L) (2 ^ 4); End if Benchmark_Function_ID 17 fit = = = (L (2) - (1) ^ 2 (L) * 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 = 3.2] [1, 1.2 3; 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. CH = 3.2] [1, 1.2 3; 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;8 8 8 8;6 6 6 6;3 7 3 7;2 9 2 9 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
Copy the code

3. Operation results

Matlab version and references

1 matlab version 2014A

[1] Yang Baoyang, YU Jizhou, Yang Shan. Intelligent Optimization Algorithm and Its MATLAB Example (2nd Edition) [M]. Publishing House of Electronics Industry, 2016. [2] ZHANG Yan, WU Shuigen. MATLAB Optimization Algorithm source code [M]. Tsinghua University Press, 2017. [3] SHI Yuanbo. [4] Li Tangbing, Hu Jinhong, Zhou Qiukuan, Et al. Optimization of Cloud Computing Task Scheduling Algorithm based on Improved Swarm Spider [J]. Computer Programming Skills and Maintenance, 2021,(04) Infrared image segmentation based on improved spotted hyena optimization algorithm [J]. Infrared Technology. 201,43(10)