├── CEC2005 ├── ackley_M_D2.mat ├── fbias_data.mat ├── test_data.mat ├── ackley_M_D10.mat ├── ackley_M_D30.mat ├── ackley_M_D50.mat ├── elliptic_M_D2.mat ├── global_optima.mat ├── griewank_M_D2.mat ├── EF8F2_func_data.mat ├── E_ScafferF6_M_D2.mat ├── ackley_func_data.mat ├── b.m ├── elliptic_M_D10.mat ├── elliptic_M_D30.mat ├── elliptic_M_D50.mat ├── griewank_M_D10.mat ├── griewank_M_D30.mat ├── griewank_M_D50.mat ├── rastrigin_M_D10.mat ├── rastrigin_M_D2.mat ├── rastrigin_M_D30.mat ├── rastrigin_M_D50.mat ├── sphere_func_data.mat ├── weierstrass_M_D2.mat ├── weierstrass_data.mat ├── E_ScafferF6_M_D10.mat ├── E_ScafferF6_M_D30.mat ├── E_ScafferF6_M_D50.mat ├── griewank_func_data.mat ├── hybrid_func1_M_D10.mat ├── hybrid_func1_M_D2.mat ├── hybrid_func1_M_D30.mat ├── hybrid_func1_M_D50.mat ├── hybrid_func1_data.mat ├── hybrid_func2_M_D10.mat ├── hybrid_func2_M_D2.mat ├── hybrid_func2_M_D30.mat ├── hybrid_func2_M_D50.mat ├── hybrid_func2_data.mat ├── hybrid_func3_HM_D2.mat ├── hybrid_func3_M_D10.mat ├── hybrid_func3_M_D2.mat ├── hybrid_func3_M_D30.mat ├── hybrid_func3_M_D50.mat ├── hybrid_func3_data.mat ├── hybrid_func4_M_D10.mat ├── hybrid_func4_M_D2.mat ├── hybrid_func4_M_D30.mat ├── hybrid_func4_M_D50.mat ├── hybrid_func4_data.mat ├── schwefel_102_data.mat ├── schwefel_206_data.mat ├── schwefel_213_data.mat ├── weierstrass_M_D10.mat ├── weierstrass_M_D30.mat ├── weierstrass_M_D50.mat ├── E_ScafferF6_func_data.mat ├── hybrid_func3_HM_D10.mat ├── hybrid_func3_HM_D30.mat ├── hybrid_func3_HM_D50.mat ├── rastrigin_func_data.mat ├── rosenbrock_func_data.mat ├── table.asv ├── high_cond_elliptic_rot_data.mat ├── table.m ├── automataActSel.m ├── automataProbUp.m ├── exemplar.m ├── func_plot.m ├── body.m ├── pso.m ├── test.m ├── README.txt ├── A1.m ├── ACPSO.m └── benchmark_func.m ├── TEC2009_ACPSO ├── b.m ├── U.m ├── automataActSel.m ├── automataProbUp.m ├── exemplar.m ├── fit_func.m ├── pso.m ├── clpso.m ├── icpsoh.m ├── ACPSO.m └── rcpsoh.m ├── TEC2006_RotatedFunc ├── b.m ├── orthm_generator.m ├── automataActSel.m ├── body1.m ├── body2.m ├── automataProbUp.m ├── test.m ├── exemplar.m ├── splitswarm.m ├── body.m ├── fit_func.m ├── clpso.m ├── ACPSO.m ├── learn.m ├── icpsoh.m └── rcpsoh.m ├── TEC2006_StandardFunc ├── b.m ├── orthm_generator.m ├── automataActSel.m ├── automataProbUp.m ├── body.m ├── fit_func.m └── ACPSO.m ├── TEC2006_StandardHybridFunc ├── b.m ├── com_func1_data.mat ├── hybrid_func1_data.mat ├── hybrid_func1_M_D10.mat ├── hybrid_func1_M_D30.mat ├── orthm_generator.m ├── automataActSel.m ├── automataProbUp.m ├── body.m ├── CLPSO_new_func.m ├── fit_func.m └── ACPSO.m ├── TEC2009_HighDimensionalMultimodalProblems ├── b.m ├── run.m ├── U.m ├── orthm_generator.m ├── automataActSel.m ├── automataProbUp.m ├── body.m ├── ff.m ├── fit_func.m ├── pso.m └── ACPSO.m ├── .gitattributes ├── .gitignore └── Readme.md /CEC2005/ackley_M_D2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/ackley_M_D2.mat -------------------------------------------------------------------------------- /CEC2005/fbias_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/fbias_data.mat -------------------------------------------------------------------------------- /CEC2005/test_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/test_data.mat -------------------------------------------------------------------------------- /CEC2005/ackley_M_D10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/ackley_M_D10.mat -------------------------------------------------------------------------------- /CEC2005/ackley_M_D30.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/ackley_M_D30.mat -------------------------------------------------------------------------------- /CEC2005/ackley_M_D50.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/ackley_M_D50.mat -------------------------------------------------------------------------------- /CEC2005/elliptic_M_D2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/elliptic_M_D2.mat -------------------------------------------------------------------------------- /CEC2005/global_optima.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/global_optima.mat -------------------------------------------------------------------------------- /CEC2005/griewank_M_D2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/griewank_M_D2.mat -------------------------------------------------------------------------------- /CEC2005/EF8F2_func_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/EF8F2_func_data.mat -------------------------------------------------------------------------------- /CEC2005/E_ScafferF6_M_D2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/E_ScafferF6_M_D2.mat -------------------------------------------------------------------------------- /CEC2005/ackley_func_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/ackley_func_data.mat -------------------------------------------------------------------------------- /CEC2005/b.m: -------------------------------------------------------------------------------- 1 | function [out] = b(sbest,swarmind,pos) 2 | sbest(swarmind) = pos; 3 | out = sbest; 4 | end -------------------------------------------------------------------------------- /CEC2005/elliptic_M_D10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/elliptic_M_D10.mat -------------------------------------------------------------------------------- /CEC2005/elliptic_M_D30.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/elliptic_M_D30.mat -------------------------------------------------------------------------------- /CEC2005/elliptic_M_D50.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/elliptic_M_D50.mat -------------------------------------------------------------------------------- /CEC2005/griewank_M_D10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/griewank_M_D10.mat -------------------------------------------------------------------------------- /CEC2005/griewank_M_D30.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/griewank_M_D30.mat -------------------------------------------------------------------------------- /CEC2005/griewank_M_D50.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/griewank_M_D50.mat -------------------------------------------------------------------------------- /CEC2005/rastrigin_M_D10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/rastrigin_M_D10.mat -------------------------------------------------------------------------------- /CEC2005/rastrigin_M_D2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/rastrigin_M_D2.mat -------------------------------------------------------------------------------- /CEC2005/rastrigin_M_D30.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/rastrigin_M_D30.mat -------------------------------------------------------------------------------- /CEC2005/rastrigin_M_D50.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/rastrigin_M_D50.mat -------------------------------------------------------------------------------- /CEC2005/sphere_func_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/sphere_func_data.mat -------------------------------------------------------------------------------- /CEC2005/weierstrass_M_D2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/weierstrass_M_D2.mat -------------------------------------------------------------------------------- /CEC2005/weierstrass_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/weierstrass_data.mat -------------------------------------------------------------------------------- /CEC2005/E_ScafferF6_M_D10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/E_ScafferF6_M_D10.mat -------------------------------------------------------------------------------- /CEC2005/E_ScafferF6_M_D30.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/E_ScafferF6_M_D30.mat -------------------------------------------------------------------------------- /CEC2005/E_ScafferF6_M_D50.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/E_ScafferF6_M_D50.mat -------------------------------------------------------------------------------- /CEC2005/griewank_func_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/griewank_func_data.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func1_M_D10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func1_M_D10.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func1_M_D2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func1_M_D2.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func1_M_D30.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func1_M_D30.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func1_M_D50.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func1_M_D50.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func1_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func1_data.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func2_M_D10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func2_M_D10.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func2_M_D2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func2_M_D2.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func2_M_D30.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func2_M_D30.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func2_M_D50.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func2_M_D50.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func2_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func2_data.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func3_HM_D2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func3_HM_D2.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func3_M_D10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func3_M_D10.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func3_M_D2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func3_M_D2.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func3_M_D30.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func3_M_D30.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func3_M_D50.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func3_M_D50.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func3_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func3_data.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func4_M_D10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func4_M_D10.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func4_M_D2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func4_M_D2.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func4_M_D30.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func4_M_D30.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func4_M_D50.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func4_M_D50.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func4_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func4_data.mat -------------------------------------------------------------------------------- /CEC2005/schwefel_102_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/schwefel_102_data.mat -------------------------------------------------------------------------------- /CEC2005/schwefel_206_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/schwefel_206_data.mat -------------------------------------------------------------------------------- /CEC2005/schwefel_213_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/schwefel_213_data.mat -------------------------------------------------------------------------------- /CEC2005/weierstrass_M_D10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/weierstrass_M_D10.mat -------------------------------------------------------------------------------- /CEC2005/weierstrass_M_D30.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/weierstrass_M_D30.mat -------------------------------------------------------------------------------- /CEC2005/weierstrass_M_D50.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/weierstrass_M_D50.mat -------------------------------------------------------------------------------- /TEC2009_ACPSO/b.m: -------------------------------------------------------------------------------- 1 | function [out] = b(sbest,swarmind,pos) 2 | sbest(swarmind) = pos; 3 | out = sbest; 4 | end -------------------------------------------------------------------------------- /CEC2005/E_ScafferF6_func_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/E_ScafferF6_func_data.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func3_HM_D10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func3_HM_D10.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func3_HM_D30.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func3_HM_D30.mat -------------------------------------------------------------------------------- /CEC2005/hybrid_func3_HM_D50.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/hybrid_func3_HM_D50.mat -------------------------------------------------------------------------------- /CEC2005/rastrigin_func_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/rastrigin_func_data.mat -------------------------------------------------------------------------------- /CEC2005/rosenbrock_func_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/rosenbrock_func_data.mat -------------------------------------------------------------------------------- /CEC2005/table.asv: -------------------------------------------------------------------------------- 1 | clc 2 | G(1,:) 3 | mean(G(1,:)),std(G(1,:)) 4 | z = G(2,:); 5 | mean(z(z<3)),std(z(z<3)) 6 | 7 | 8 | -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/b.m: -------------------------------------------------------------------------------- 1 | function [out] = b(sbest,swarmind,pos) 2 | sbest(swarmind) = pos; 3 | out = sbest; 4 | end -------------------------------------------------------------------------------- /TEC2006_StandardFunc/b.m: -------------------------------------------------------------------------------- 1 | function [out] = b(sbest,swarmind,pos) 2 | sbest(swarmind) = pos; 3 | out = sbest; 4 | end -------------------------------------------------------------------------------- /TEC2006_StandardHybridFunc/b.m: -------------------------------------------------------------------------------- 1 | function [out] = b(sbest,swarmind,pos) 2 | sbest(swarmind) = pos; 3 | out = sbest; 4 | end -------------------------------------------------------------------------------- /CEC2005/high_cond_elliptic_rot_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/CEC2005/high_cond_elliptic_rot_data.mat -------------------------------------------------------------------------------- /TEC2009_HighDimensionalMultimodalProblems/b.m: -------------------------------------------------------------------------------- 1 | function [out] = b(sbest,swarmind,pos) 2 | sbest(swarmind) = pos; 3 | out = sbest; 4 | end -------------------------------------------------------------------------------- /TEC2006_StandardHybridFunc/com_func1_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/TEC2006_StandardHybridFunc/com_func1_data.mat -------------------------------------------------------------------------------- /TEC2006_StandardHybridFunc/hybrid_func1_data.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/TEC2006_StandardHybridFunc/hybrid_func1_data.mat -------------------------------------------------------------------------------- /TEC2006_StandardHybridFunc/hybrid_func1_M_D10.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/TEC2006_StandardHybridFunc/hybrid_func1_M_D10.mat -------------------------------------------------------------------------------- /TEC2006_StandardHybridFunc/hybrid_func1_M_D30.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hmofrad/Adaptive-CPSO/HEAD/TEC2006_StandardHybridFunc/hybrid_func1_M_D30.mat -------------------------------------------------------------------------------- /CEC2005/table.m: -------------------------------------------------------------------------------- 1 | clc 2 | G(1,:) 3 | mean(G(1,:)),std(G(1,:)) 4 | G(2,:) 5 | mean(G(2,:)),std(G(2,:)) 6 | z = G(2,:); 7 | 8 | mean(z(z<13)),std(z(z<13)) 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /TEC2009_ACPSO/U.m: -------------------------------------------------------------------------------- 1 | function out = U(x) 2 | a = 10; 3 | k = 100; 4 | m = 4; 5 | if (x>a) 6 | out = k*(x - a)^m; 7 | elseif (x>=-a && x<=a) 8 | out = 0; 9 | elseif (x<-a) 10 | out = k*(-x - a)^m; 11 | end -------------------------------------------------------------------------------- /TEC2009_HighDimensionalMultimodalProblems/run.m: -------------------------------------------------------------------------------- 1 | clear,clc 2 | [g11_30 f12]=ACPSO(11,50,300,30,0.1,0.1); 3 | [g12_10 f12]=ACPSO(12,50,300,10,0.1,0.1); 4 | [g12_30 f12]=ACPSO(12,50,300,30,0.1,0.1); 5 | [g13_30 f12]=ACPSO(13,50,300,50,0.1,0.1); 6 | 7 | 8 | -------------------------------------------------------------------------------- /TEC2009_HighDimensionalMultimodalProblems/U.m: -------------------------------------------------------------------------------- 1 | function out = U(x) 2 | a = 10; 3 | k = 100; 4 | m = 4; 5 | if (x>a) 6 | out = k*(x - a)^m; 7 | elseif (x>=-a && x<=a) 8 | out = 0; 9 | elseif (x<-a) 10 | out = k*(-x - a)^m; 11 | end -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/orthm_generator.m: -------------------------------------------------------------------------------- 1 | function M=orthm_generator(D) 2 | pi=3.14159; 3 | M=diag(ones(1,D)); 4 | for j=1:D%*D 5 | R1=diag(ones(1,D)); 6 | x=pi/2.*rand;angel=[cos(x) -sin(x);sin(x) cos(x)]; 7 | rc=randperm(D);row=rc(1:2); 8 | R1(row(1),row(1))=angel(1,1); 9 | R1(row(1),row(2))=angel(1,2); 10 | R1(row(2),row(1))=angel(2,1); 11 | R1(row(2),row(2))=angel(2,2); 12 | M=M*R1; 13 | end 14 | -------------------------------------------------------------------------------- /TEC2006_StandardFunc/orthm_generator.m: -------------------------------------------------------------------------------- 1 | function M=orthm_generator(D) 2 | pi=3.14159; 3 | M=diag(ones(1,D)); 4 | for j=1:D%*D 5 | R1=diag(ones(1,D)); 6 | x=pi/2.*rand;angel=[cos(x) -sin(x);sin(x) cos(x)]; 7 | rc=randperm(D);row=rc(1:2); 8 | R1(row(1),row(1))=angel(1,1); 9 | R1(row(1),row(2))=angel(1,2); 10 | R1(row(2),row(1))=angel(2,1); 11 | R1(row(2),row(2))=angel(2,2); 12 | M=M*R1; 13 | end 14 | -------------------------------------------------------------------------------- /TEC2006_StandardHybridFunc/orthm_generator.m: -------------------------------------------------------------------------------- 1 | function M=orthm_generator(D) 2 | pi=3.14159; 3 | M=diag(ones(1,D)); 4 | for j=1:D%*D 5 | R1=diag(ones(1,D)); 6 | x=pi/2.*rand;angel=[cos(x) -sin(x);sin(x) cos(x)]; 7 | rc=randperm(D);row=rc(1:2); 8 | R1(row(1),row(1))=angel(1,1); 9 | R1(row(1),row(2))=angel(1,2); 10 | R1(row(2),row(1))=angel(2,1); 11 | R1(row(2),row(2))=angel(2,2); 12 | M=M*R1; 13 | end 14 | -------------------------------------------------------------------------------- /CEC2005/automataActSel.m: -------------------------------------------------------------------------------- 1 | % Multi dimentional Action Selection 2 | function swarmTable = automataActSel(p) 3 | global action 4 | [swarmNum dim] = size(p); 5 | for i =1:dim 6 | rw = randsrc(1000,1,[action; p(:,i)']); % roulette wheel 7 | act = rw(randi(length(rw))); % selected action 8 | swarmTable(act,i) = 1; 9 | swarmTable(act ~= action,i) = 0; 10 | end 11 | end -------------------------------------------------------------------------------- /TEC2009_ACPSO/automataActSel.m: -------------------------------------------------------------------------------- 1 | % Multi dimentional Action Selection 2 | function swarmTable = automataActSel(p) 3 | global action 4 | [swarmNum dim] = size(p); 5 | for i =1:dim 6 | rw = randsrc(100,1,[action; p(:,i)']); % roulette wheel 7 | act = rw(randi(length(rw))); % selected action 8 | swarmTable(act,i) = 1; 9 | swarmTable(act ~= action,i) = 0; 10 | end 11 | end -------------------------------------------------------------------------------- /TEC2009_HighDimensionalMultimodalProblems/orthm_generator.m: -------------------------------------------------------------------------------- 1 | function M=orthm_generator(D) 2 | pi=3.14159; 3 | M=diag(ones(1,D)); 4 | for j=1:D%*D 5 | R1=diag(ones(1,D)); 6 | x=pi/2.*rand;angel=[cos(x) -sin(x);sin(x) cos(x)]; 7 | rc=randperm(D);row=rc(1:2); 8 | R1(row(1),row(1))=angel(1,1); 9 | R1(row(1),row(2))=angel(1,2); 10 | R1(row(2),row(1))=angel(2,1); 11 | R1(row(2),row(2))=angel(2,2); 12 | M=M*R1; 13 | end 14 | -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/automataActSel.m: -------------------------------------------------------------------------------- 1 | % Multi dimentional Action Selection 2 | function swarmTable = automataActSel(p) 3 | global action 4 | [swarmNum dim] = size(p); 5 | for i =1:dim 6 | rw = randsrc(1000,1,[action; p(:,i)']); % roulette wheel 7 | act = rw(randi(length(rw))); % selected action 8 | swarmTable(act,i) = 1; 9 | swarmTable(act ~= action,i) = 0; 10 | end 11 | end -------------------------------------------------------------------------------- /TEC2006_StandardFunc/automataActSel.m: -------------------------------------------------------------------------------- 1 | % Multi dimentional Action Selection 2 | function swarmTable = automataActSel(p) 3 | global action 4 | [swarmNum dim] = size(p); 5 | for i =1:dim 6 | rw = randsrc(1000,1,[action; p(:,i)']); % roulette wheel 7 | act = rw(randi(length(rw))); % selected action 8 | swarmTable(act,i) = 1; 9 | swarmTable(act ~= action,i) = 0; 10 | end 11 | end -------------------------------------------------------------------------------- /TEC2006_StandardHybridFunc/automataActSel.m: -------------------------------------------------------------------------------- 1 | % Multi dimentional Action Selection 2 | function swarmTable = automataActSel(p) 3 | global action 4 | [swarmNum dim] = size(p); 5 | for i =1:dim 6 | rw = randsrc(1000,1,[action; p(:,i)']); % roulette wheel 7 | act = rw(randi(length(rw))); % selected action 8 | swarmTable(act,i) = 1; 9 | swarmTable(act ~= action,i) = 0; 10 | end 11 | end -------------------------------------------------------------------------------- /TEC2009_HighDimensionalMultimodalProblems/automataActSel.m: -------------------------------------------------------------------------------- 1 | % Multi dimentional Action Selection 2 | function swarmTable = automataActSel(p) 3 | global action 4 | [swarmNum dim] = size(p); 5 | for i =1:dim 6 | rw = randsrc(100,1,[action; p(:,i)']); % roulette wheel 7 | act = rw(randi(length(rw))); % selected action 8 | swarmTable(act,i) = 1; 9 | swarmTable(act ~= action,i) = 0; 10 | end 11 | end -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/body1.m: -------------------------------------------------------------------------------- 1 | clear all,clc 2 | swarmNum = [3 6];nop = 40;dim=30; 3 | for i=1:2 4 | for j=9:14 5 | for k=1:25 6 | if i == 1 7 | [gh fh]=rcpsoh(j,nop,dim,swarmNum(i)); 8 | G(j-8,k) =gh(end); 9 | F(j-8,k) =fh(end); 10 | else 11 | [gh fh]=rcpsoh(j,nop,dim,swarmNum(i)); 12 | G(j-8+6,k) =gh(end); 13 | F(j-8+6,k) =fh(end); 14 | end 15 | i,j,k 16 | end 17 | end 18 | end 19 | save('rcpsohR30D.mat') 20 | -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/body2.m: -------------------------------------------------------------------------------- 1 | clear,clc 2 | %CLPSO 3 | swarmNum = [3 6];nop = 40;dim=30; 4 | for i=1:2 5 | for j=9:14 6 | for k=1:25 7 | if i == 1 8 | [gh fh]=icpsoh(j,nop,dim,swarmNum(i)); 9 | G(j-8,k) =gh(end); 10 | F(j-8,k) =fh(end); 11 | else 12 | [gh fh]=icpsoh(j,nop,dim,swarmNum(i)); 13 | G(j-8+6,k) =gh(end); 14 | F(j-8+6,k) =fh(end); 15 | end 16 | i,j,k 17 | end 18 | end 19 | end 20 | save('icpsohR30D.mat') 21 | -------------------------------------------------------------------------------- /TEC2009_ACPSO/automataProbUp.m: -------------------------------------------------------------------------------- 1 | function p = automataProbUp(p,imp_tag,swarmInd,swarmDim,swarmTable,alpha,beta) 2 | global action 3 | [swarmNum dim] = size(swarmTable); 4 | r = length(action); 5 | swarm = 1:swarmNum; 6 | swarmNind = swarm ~=swarmInd; 7 | if (imp_tag==1) 8 | p(swarmInd,swarmDim) = p(swarmInd,swarmDim) + alpha.*(1 - p(swarmInd,swarmDim)); % desired action 9 | p(swarmNind,swarmDim) = (1-alpha).*p(swarmNind,swarmDim); 10 | else 11 | p(swarmInd,swarmDim) = (1 - beta).*p(swarmInd,swarmDim); % non-desired action 12 | p(swarmNind,swarmDim) = (beta/(r-1))+(1-beta).*p(swarmNind,swarmDim); 13 | end 14 | end -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/automataProbUp.m: -------------------------------------------------------------------------------- 1 | function p = automataProbUp(p,imp_tag,swarmInd,swarmDim,swarmTable,alpha,beta) 2 | global action 3 | [swarmNum dim] = size(swarmTable); 4 | r = length(action); 5 | swarm = 1:swarmNum; 6 | swarmNind = swarm ~=swarmInd; 7 | if (imp_tag==1) 8 | p(swarmInd,swarmDim) = p(swarmInd,swarmDim) + alpha.*(1 - p(swarmInd,swarmDim)); % desired action 9 | p(swarmNind,swarmDim) = (1-alpha).*p(swarmNind,swarmDim); 10 | else 11 | p(swarmInd,swarmDim) = (1 - beta).*p(swarmInd,swarmDim); % non-desired action 12 | p(swarmNind,swarmDim) = (beta/(r-1))+(1-beta).*p(swarmNind,swarmDim); 13 | end 14 | end -------------------------------------------------------------------------------- /TEC2006_StandardFunc/automataProbUp.m: -------------------------------------------------------------------------------- 1 | function p = automataProbUp(p,imp_tag,swarmInd,swarmDim,swarmTable,alpha,beta) 2 | global action 3 | [swarmNum dim] = size(swarmTable); 4 | r = length(action); 5 | swarm = 1:swarmNum; 6 | swarmNind = swarm ~=swarmInd; 7 | if (imp_tag==1) 8 | p(swarmInd,swarmDim) = p(swarmInd,swarmDim) + alpha.*(1 - p(swarmInd,swarmDim)); % desired action 9 | p(swarmNind,swarmDim) = (1-alpha).*p(swarmNind,swarmDim); 10 | else 11 | p(swarmInd,swarmDim) = (1 - beta).*p(swarmInd,swarmDim); % non-desired action 12 | p(swarmNind,swarmDim) = (beta/(r-1))+(1-beta).*p(swarmNind,swarmDim); 13 | end 14 | end -------------------------------------------------------------------------------- /TEC2006_StandardHybridFunc/automataProbUp.m: -------------------------------------------------------------------------------- 1 | function p = automataProbUp(p,imp_tag,swarmInd,swarmDim,swarmTable,alpha,beta) 2 | global action 3 | [swarmNum dim] = size(swarmTable); 4 | r = length(action); 5 | swarm = 1:swarmNum; 6 | swarmNind = swarm ~=swarmInd; 7 | if (imp_tag==1) 8 | p(swarmInd,swarmDim) = p(swarmInd,swarmDim) + alpha.*(1 - p(swarmInd,swarmDim)); % desired action 9 | p(swarmNind,swarmDim) = (1-alpha).*p(swarmNind,swarmDim); 10 | else 11 | p(swarmInd,swarmDim) = (1 - beta).*p(swarmInd,swarmDim); % non-desired action 12 | p(swarmNind,swarmDim) = (beta/(r-1))+(1-beta).*p(swarmNind,swarmDim); 13 | end 14 | end -------------------------------------------------------------------------------- /TEC2009_HighDimensionalMultimodalProblems/automataProbUp.m: -------------------------------------------------------------------------------- 1 | function p = automataProbUp(p,imp_tag,swarmInd,swarmDim,swarmTable,alpha,beta) 2 | global action 3 | [swarmNum dim] = size(swarmTable); 4 | r = length(action); 5 | swarm = 1:swarmNum; 6 | swarmNind = swarm ~=swarmInd; 7 | if (imp_tag==1) 8 | p(swarmInd,swarmDim) = p(swarmInd,swarmDim) + alpha.*(1 - p(swarmInd,swarmDim)); % desired action 9 | p(swarmNind,swarmDim) = (1-alpha).*p(swarmNind,swarmDim); 10 | else 11 | p(swarmInd,swarmDim) = (1 - beta).*p(swarmInd,swarmDim); % non-desired action 12 | p(swarmNind,swarmDim) = (beta/(r-1))+(1-beta).*p(swarmNind,swarmDim); 13 | end 14 | end -------------------------------------------------------------------------------- /CEC2005/automataProbUp.m: -------------------------------------------------------------------------------- 1 | function p = automataProbUp(p,imp_tag,swarmInd,swarmDim,swarmTable,alpha,beta) 2 | global action 3 | [swarmNum dim] = size(swarmTable); 4 | r = length(action); 5 | swarm = 1:swarmNum; 6 | swarmNind = swarm ~=swarmInd; 7 | % nop = 30; 8 | % if (imp_tag >= nop/2) 9 | if (imp_tag==1) 10 | p(swarmInd,swarmDim) = p(swarmInd,swarmDim) + alpha.*(1 - p(swarmInd,swarmDim)); % desired action 11 | p(swarmNind,swarmDim) = (1-alpha).*p(swarmNind,swarmDim); 12 | else 13 | p(swarmInd,swarmDim) = (1 - beta).*p(swarmInd,swarmDim); % non-desired action 14 | p(swarmNind,swarmDim) = (beta/(r-1))+(1-beta).*p(swarmNind,swarmDim); 15 | end 16 | end -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/test.m: -------------------------------------------------------------------------------- 1 | clc 2 | if swarmNum == 3 3 | v1 = [numel(find((p(1,1:10)>.5))) numel(find((p(1,11:20)>.5))) numel(find((p(1,21:30)>.5)));... 4 | numel(find((p(2,1:10)>.5))) numel(find((p(2,11:20)>.5))) numel(find((p(2,21:30)>.5)));... 5 | numel(find((p(3,1:10)>.5))) numel(find((p(3,11:20)>.5))) numel(find((p(3,21:30)>.5)))]; 6 | end 7 | if swarmNum == 6 8 | v1 = [numel(find((p(1,1:5)>.5))) numel(find((p(1,6:10)>.5))) numel(find((p(1,11:15)>.5)))... 9 | numel(find((p(1,16:20)>.5))) numel(find((p(1,21:25)>.5))) numel(find((p(1,26:30)>.5)));... 10 | numel(find((p(2,1:5)>.5))) numel(find((p(2,6:10)>.5))) numel(find((p(2,11:15)>.5)))... 11 | numel(find((p(2,16:20)>.5))) numel(find((p(2,21:25)>.5))) numel(find((p(2,26:30)>.5)));... 12 | numel(find((p(3,1:5)>.5))) numel(find((p(3,6:10)>.5))) numel(find((p(3,11:15)>.5)))... 13 | numel(find((p(3,16:20)>.5))) numel(find((p(3,21:25)>.5))) numel(find((p(3,26:30)>.5)))]; 14 | end 15 | % v1 16 | % [v i]=max(p); 17 | % swarmTable=zeros(size(p)); 18 | % for j=1:dim 19 | % swarmTable(i(j),j)=1; 20 | % end 21 | v1 22 | 23 | 24 | -------------------------------------------------------------------------------- /CEC2005/exemplar.m: -------------------------------------------------------------------------------- 1 | function [pbestf] = exemplar(x,pbest,j) 2 | % j as particle index 3 | % Learning Probability PCi 4 | [nop dim]= size(x); dim = dim - 1; 5 | % pbestf = zeros(1,dim); 6 | pbestf = []; 7 | di = 1:nop; % discretized particle index 8 | Pc = 0.05+0.45*((exp(10*(di-1)/(nop-1))-1)/(exp(10)-1)); 9 | % ====================================== 10 | % calculatind exepmlar Pbest Function 11 | for k=1:dim 12 | if rand>Pc(j) 13 | pbestf(k) = pbest(j,k); 14 | else 15 | pind = di; %insert raw particles index in particle index vector 16 | pind = pind(pind ~= j); 17 | f1ind = pind(randi([1 length(pind)])); 18 | pind = pind(pind ~= f1ind); 19 | f2ind = pind(randi([1 length(pind)])); 20 | if pbest(f1ind,end)Pc(j) 13 | pbestf(k) = pbest(j,k); 14 | else 15 | pind = di; %insert raw particles index in particle index vector 16 | pind = pind(pind ~= j); 17 | f1ind = pind(randi([1 length(pind)])); 18 | pind = pind(pind ~= f1ind); 19 | f2ind = pind(randi([1 length(pind)])); 20 | if pbest(f1ind,end)Pc(j) 13 | pbestf(k) = pbest(j,k); 14 | else 15 | pind = di; %insert raw particles index in particle index vector 16 | pind = pind(pind ~= j); 17 | f1ind = pind(randi([1 length(pind)])); 18 | pind = pind(pind ~= f1ind); 19 | f2ind = pind(randi([1 length(pind)])); 20 | if pbest(f1ind,end)a) 47 | u = k*(x - a)^m; 48 | elseif (x>=-a && x<=a) 49 | u = 0; 50 | elseif (x<-a) 51 | u = k*(-x - a)^m; 52 | end 53 | end 54 | end -------------------------------------------------------------------------------- /TEC2009_HighDimensionalMultimodalProblems/fit_func.m: -------------------------------------------------------------------------------- 1 | % fitness function 2 | function f = fit_func(c,x) 3 | % c as the fitness function number 4 | func = c{1}; % benchmark number 5 | [nop D]=size(x); 6 | switch (func) 7 | case {'Schewfel',8} 8 | x=x-(-12569.5); 9 | f = sum(-x.*sin(sqrt(abs(x))),2); 10 | f = abs(f); 11 | case {'Rastrigin',9} 12 | f=sum(x.^2-10.*cos(2.*pi.*x)+10,2); 13 | case {'Ackley',10} 14 | f=sum(x.^2,2); 15 | f=20-20.*exp(-0.2.*sqrt(f./D))-exp(sum(cos(2.*pi.*x),2)./D)+exp(1); 16 | case {'Griewank',11} 17 | f=1; 18 | for i=1:D 19 | f=f.*cos((x(:,i)-100)./sqrt(i)); 20 | end 21 | f=sum((x-100).^2,2)./4000-f+1; 22 | case {'Penalized1',12} 23 | y = 1 + ((x+1)./4); 24 | f = (pi/D)*(10.*sin(pi.*y(:,1)).^2 + ... 25 | sum(((y(:,1:D-1)-1).^2).*(1+10*sin(pi.*y(:,2:D)).^2),2) + ... 26 | (y(:,D)-1).^2); 27 | for i=1:nop 28 | for j=1:D 29 | u(j) = U(x(i,j)); 30 | end 31 | f(i) = f(i) + sum(u); 32 | end 33 | case {'Penalized2',13} 34 | f = 0.1*(10.*sin(3*pi.*x(:,1)).^2 + ... 35 | sum(((x(:,1:D-1)-1).^2).*(1+sin(3*pi.*x(:,2:D)).^2),2) + ... 36 | (x(:,D)-1).^2); 37 | for i=1:nop 38 | for j=1:D 39 | u(j) = U(x(i,j)); 40 | end 41 | f(i) = f(i) + sum(u); 42 | end 43 | end 44 | function u = U(x) 45 | a = 10; k = 100; m = 4; 46 | if (x>a) 47 | u = k*(x - a)^m; 48 | elseif (x>=-a && x<=a) 49 | u = 0; 50 | elseif (x<-a) 51 | u = k*(-x - a)^m; 52 | end 53 | end 54 | end -------------------------------------------------------------------------------- /CEC2005/func_plot.m: -------------------------------------------------------------------------------- 1 | % function function_plot 2 | % clear;close all 3 | global initial_flag 4 | 5 | % Xmin=[-100,-100,-100,-100,-100,-100,0,-32,-5,-5,-0.5,-pi,-3,-100,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,2]; 6 | % Xmax=[100,100,100,100,100,100,600,32,5,5,0.5,pi,1,100,5,5,5,5,5,5,5,5,5,5,5]; 7 | 8 | for func_num=1:1 9 | if func_num==1 x=-100:5:100;y=x; %[-100,100] 10 | elseif func_num==2 x=-100:5:100; y=x;%[-10,10] 11 | elseif func_num==3 x=-100:5:100; y=x;%[-100,100] 12 | elseif func_num==4 x=-100:2:0; y=x+100;%[-100,100] 13 | elseif func_num==5 x=-200:20:200;y=x; %[-5,5] 14 | elseif func_num==6 x=78:0.05:82; y=-51.3:0.05:-47.3;%[-3,1] 15 | elseif func_num==7 x=-350:2:-250; y=-100:2:0;;%[-600,600] 16 | elseif func_num==8 x=-32:1:32; y=x;%[-32,32] 17 | elseif func_num==9 x=-5:0.1:5; y=x;%[-5,5] 18 | elseif func_num==10 x=-5:0.1:5; y=x;%[-5,5] 19 | elseif func_num==11 x=-0.5:0.01:0.5; y=x;%[-0.5,0.5] 20 | elseif func_num==12 x=-3:0.1:3; y=x;%[-pi,pi] 21 | elseif func_num==13 x=-2:0.02:-1; y=x;%[-3,1] 22 | elseif func_num==14 x=-90:0.2:-50; y=-40:0.2:0;%[-100,100] 23 | elseif func_num==15 x=-5:0.1:5; y=x;%[-5,5] 24 | elseif func_num==16 x=-5:0.1:5; y=x;%[-5,5] 25 | elseif func_num==17 x=-5:0.1:5; y=x;%[-5,5] 26 | elseif func_num==18 x=-5:0.1:5; y=x;%[-5,5] 27 | elseif func_num==19 x=-5:0.1:5; y=x;%[-5,5] 28 | elseif func_num==20 x=-5:0.1:5; y=x;%[-5,5] 29 | elseif func_num==21 x=-5:0.1:5; y=x;%[-5,5] 30 | elseif func_num==22 x=-5:0.1:5; y=x;%[-5,5] 31 | elseif func_num==23 x=-5:0.1:5; y=x;%[-5,5] 32 | elseif func_num==24 x=-5:0.1:5; y=x;%[-5,5] 33 | elseif func_num==25 x=-5:0.1:5; y=x;%[-5,5] 34 | end 35 | 36 | initial_flag=0; 37 | L=length(x); 38 | f=[]; 39 | 40 | for i=1:L 41 | for j=1:L 42 | f(i,j)=benchmark_func([x(i),y(j)],func_num); 43 | end 44 | end 45 | 46 | figure(func_num) 47 | surfc(x,y,f); 48 | end 49 | 50 | -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/body.m: -------------------------------------------------------------------------------- 1 | clear,clc 2 | alpha = 0.1;beta = 0.1; %LRP 3 | swarmNum = [3 6];nop = 10;dim=10; 4 | for i=1:2 5 | for j=9:14 6 | for k=1:25 7 | if i == 1 8 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 9 | G(j-8,k) =gh(end); 10 | F(j-8,k) =fh(end); 11 | else 12 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 13 | G(j-8+6,k) =gh(end); 14 | F(j-8+6,k) =fh(end); 15 | end 16 | swarmNum(i),i,j 17 | end 18 | end 19 | end 20 | save('ACPSORF1RP.mat') 21 | % ===================== 22 | clear,clc 23 | alpha = 0.1;beta = 0.01; %LReP 24 | swarmNum = [3 6];nop = 10;dim=10; 25 | for i=1:2 26 | for j=9:14 27 | for k=1:25 28 | if i == 1 29 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 30 | G(j-8,k) =gh(end); 31 | F(j-8,k) =fh(end); 32 | else 33 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 34 | G(j-8+6,k) =gh(end); 35 | F(j-8+6,k) =fh(end); 36 | end 37 | swarmNum(i),i,j,alpha 38 | end 39 | end 40 | end 41 | save('ACPSORF1ReP.mat') 42 | % ===================== 43 | clear,clc 44 | alpha = 0.1;beta = 0.0; %LRI 45 | swarmNum = [3 6];nop = 10;dim=10; 46 | for i=1:2 47 | for j=9:14 48 | for k=1:25 49 | if i == 1 50 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 51 | G(j-8,k) =gh(end); 52 | F(j-8,k) =fh(end); 53 | else 54 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 55 | G(j-8+6,k) =gh(end); 56 | F(j-8+6,k) =fh(end); 57 | end 58 | swarmNum(i),i,j,beta 59 | end 60 | end 61 | end 62 | save('ACPSORF1RI.mat') 63 | % ===================== -------------------------------------------------------------------------------- /CEC2005/body.m: -------------------------------------------------------------------------------- 1 | clear,clc 2 | alpha = 0.1;beta = 0.1; %LRP 3 | swarmNum = [3 6];nop = 30;dim=30; 4 | for i=1:2 5 | for j=15:25 6 | for k=1:25 7 | if i == 1 8 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 9 | G(j-14,k) =gh(end); 10 | F(j-14,k) =fh(end); 11 | else 12 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 13 | G(j-14+11,k) =gh(end); 14 | F(j-14+11,k) =fh(end); 15 | end 16 | swarmNum(i),j,k 17 | end 18 | end 19 | end 20 | save('ACPSOCF3RP.mat') 21 | % ================================== 22 | clear,clc 23 | alpha = 0.1;beta = 0.01; %LReP 24 | swarmNum = [3 6];nop = 30;dim=30; 25 | for i=1:2 26 | for j=15:25 27 | for k=1:25 28 | if i == 1 29 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 30 | G(j-14,k) =gh(end); 31 | F(j-14,k) =fh(end); 32 | else 33 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 34 | G(j-14+11,k) =gh(end); 35 | F(j-14+11,k) =fh(end); 36 | end 37 | swarmNum(i),j,k,alpha 38 | end 39 | end 40 | end 41 | save('ACPSOCF3ReP.mat') 42 | % ================================== 43 | clear,clc 44 | alpha = 0.1;beta = 0.0; %LRI 45 | swarmNum = [3 6];nop = 30;dim=30; 46 | for i=1:2 47 | for j=15:25 48 | for k=1:25 49 | if i == 1 50 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 51 | G(j-14,k) =gh(end); 52 | F(j-14,k) =fh(end); 53 | else 54 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 55 | G(j-14+11,k) =gh(end); 56 | F(j-14+11,k) =fh(end); 57 | end 58 | swarmNum(i),j,k,beta 59 | end 60 | end 61 | end 62 | save('ACPSOCF3RI.mat') -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Adaptive-Cooperative-PSO 2 |

Matlab codes for Adaptive Cooperative Particle Swarm Optimizer (ACPSO) algorithm [1].

3 |

Full Text

4 |

Abstract

5 | 6 |

An Adaptive Cooperative Particle Swarm Optimizer (ACPSO) is introduced in this paper, which facilitates cooperation technique through usage of Learning Automata (LA) algorithm. Cooperative learning strategy of ACPSO optimizes the problem collaboratively and evaluates it in different contexts. In ACPSO algorithm, a set of learning automata associated with dimensions of the problem are trying to find the correlated variables of the search space and optimize the problem intelligently. This collective behavior of ACPSO will fulfill the task of adaptive selection of swarm members. Simulations were conducted on four types of benchmark suits which contain three state-of-the-arts numerical optimization benchmark functions in addition to one new set of active coordinate rotated test functions. The results demonstrate the learning ability of ACPSO in finding correlated variables of the search space and also describe how efficiently it can optimize the coordinate rotated multimodal problems, composition functions and high-dimensional multimodal problems.

7 | 8 |

Reference

9 | 10 | 11 |

[1] Mohammad Hasanzadeh, Mohammad Reza Meybodi, and Mohammad Mehdi Ebadzadeh" Adaptive cooperative particle swarm optimizer 12 | ," Applied Intelligence, 2013, vol. 39, no. 2, pp.397-420.

13 | 14 | 15 | -------------------------------------------------------------------------------- /TEC2006_StandardHybridFunc/body.m: -------------------------------------------------------------------------------- 1 | % clear,clc 2 | % alpha = 0.1;beta = 0.1; %LRP 3 | % swarmNum = [3 6];nop = 10;dim=10; 4 | % for i=1:2 5 | % for j=15:16 6 | % for k=1:25 7 | % if i == 1 8 | % [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 9 | % G(j-14,k) =gh(end); 10 | % F(j-14,k) =fh(end); 11 | % else 12 | % [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 13 | % G(j-14+2,k) =gh(end); 14 | % F(j-14+2,k) =fh(end); 15 | % end 16 | % swarmNum(i),j,k 17 | % end 18 | % end 19 | % end 20 | % save('ACPSOSHF1RP.mat') 21 | % ===================== 22 | clear,clc 23 | alpha = 0.1;beta = 0.01; %LReP 24 | swarmNum = [3 6];nop = 10;dim=10; 25 | for i=1:2 26 | for j=15:16 27 | for k=1:25 28 | if i == 1 29 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 30 | G(j-14,k) =gh(end); 31 | F(j-14,k) =fh(end); 32 | else 33 | [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 34 | G(j-14+2,k) =gh(end); 35 | F(j-14+2,k) =fh(end); 36 | end 37 | swarmNum(i),j,k,beta 38 | end 39 | end 40 | end 41 | save('ACPSOSHF1ReP.mat') 42 | % % ===================== 43 | % clear,clc 44 | % alpha = 0.1;beta = 0.0; %LRI 45 | % swarmNum = [3 6];nop = 10;dim=10; 46 | % for i=1:2 47 | % for j=15:16 48 | % for k=1:25 49 | % if i == 1 50 | % [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 51 | % G(j-14,k) =gh(end); 52 | % F(j-14,k) =fh(end); 53 | % else 54 | % [gh fh]=ACPSO(j,nop,dim,swarmNum(i),alpha,beta); 55 | % G(j-14+2,k) =gh(end); 56 | % F(j-14+2,k) =fh(end); 57 | % end 58 | % swarmNum(i),j,k,beta 59 | % end 60 | % end 61 | % end 62 | % save('ACPSOSHF1RI.mat') 63 | % % ===================== -------------------------------------------------------------------------------- /TEC2006_StandardFunc/fit_func.m: -------------------------------------------------------------------------------- 1 | % fitness function 2 | function f = fit_func(c,x) 3 | global orthm 4 | % c as the fitness function number 5 | func = c{1}; % benchmark number 6 | [nop D]=size(x); 7 | R = 9:14; 8 | greal=[0 1 0 0 0 0 4.209687462275036e+002 0 0 0 0 0 0 0]; 9 | x=x-greal(func); 10 | if ismember(func,R) 11 | x=x*orthm; 12 | end 13 | x=x+greal(func); 14 | switch (func) 15 | case {'Sphere',1} 16 | f=sum(x.^2,2); 17 | case {'Rosenbrock',2} 18 | f=sum(100.*(x(:,1:D-1).^2-x(:,2:D)).^2+(x(:,1:D-1)-1).^2,2); 19 | case {'Ackley',3,9} 20 | f=sum(x.^2,2); 21 | f=20-20.*exp(-0.2.*sqrt(f./D))-exp(sum(cos(2.*pi.*x),2)./D)+exp(1); 22 | case {'Griewank',4,10} 23 | f=1; 24 | for i=1:D 25 | f=f.*cos(x(:,i)./sqrt(i)); 26 | end 27 | f=sum(x.^2,2)./4000-f+1; 28 | case {'Weierstrass',5,11} 29 | x=x+0.5; 30 | a = 0.5; 31 | b = 3; 32 | kmax = 20; 33 | c1(1:kmax+1) = a.^(0:kmax); 34 | c2(1:kmax+1) = 2*pi*b.^(0:kmax); 35 | f=0; 36 | c=-w(0.5,c1,c2); 37 | for i=1:D 38 | f=f+w(x(:,i)',c1,c2); 39 | end 40 | f=f+c*D; 41 | case {'rastrigin', 6,12} 42 | f=sum(x.^2-10.*cos(2.*pi.*x)+10,2); 43 | case {'Rastrigin_noncont',7,13} 44 | x=(abs(x)<0.5).*x+(abs(x)>=0.5).*(round(x.*2)./2); 45 | f=sum(x.^2-10.*cos(2.*pi.*x)+10,2); 46 | case {'Schewfel',8,14} 47 | f=0; 48 | for i=1:D 49 | f=f-(abs(x(:,i))<=500).*(x(:,i).*sin(sqrt(abs(x(:,i)))))+(abs(x(:,i))>500).*0.001.*(500-abs(x(:,i))).^2; 50 | end 51 | f=4.189828872724338e+002*D+f; 52 | end 53 | function y = w(x,c1,c2) 54 | y = zeros(length(x),1); 55 | for k = 1:length(x) 56 | y(k) = sum(c1 .* cos(c2.*x(:,k))); 57 | end 58 | end 59 | end -------------------------------------------------------------------------------- /TEC2009_ACPSO/pso.m: -------------------------------------------------------------------------------- 1 | % function [x_std gbest_fit gbest_hist] = pso(f,bnd,dim,nop,endgen) 2 | clear,clc 3 | f= 10;nop = 50;dim=300; 4 | endgen = 10^4; % maximum Generation 5 | max_fe = 5*10^6; % current fitness evaluation 6 | if f == 8; Ub = 500; end % Schwefel 7 | if f == 9; Ub = 32.768; end % Rastrigin 8 | if f == 10; Ub = 600; end % Ackley 9 | if f == 11; Ub = 0.5; end % Griewank 10 | if f == 12; Ub = 5.12; end % Penalized1 11 | if f == 13; Ub = 5.12; end % Penalized1 12 | w = 0.72; 13 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 14 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity nop = 10; dim = 9; 15 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 16 | x(:,end+1)=0; 17 | c1 = 1.49445; c2 = 1.49445; 18 | x(:,end) = fit_func({f},x(:,1:end-1)); 19 | pbest = x; %initialize Best Particle Position 20 | [mn ind] = min(x(:,end)); 21 | gbest = x(ind,:); 22 | gbest_hist = []; 23 | fe = 0; 24 | for i=1:endgen 25 | for j=1:nop 26 | if (x(j,end)Vmax)); 35 | % spd(ind) = Vmax.*sign(spd(ind)); 36 | spd=(spd>Vmax).*Vmax+(spd<=Vmax).*spd; 37 | spd=(spd<(Vmin)).*(Vmin)+(spd>=(Vmin)).*spd; 38 | 39 | x(j,1:end-1) = x(j,1:end-1)+spd(j,:); 40 | end 41 | fe = fe+nop; 42 | % x(:,end) = abs(benchmark_func(x(:,1:end-1),f)-f_bias); 43 | x(:,end) = fit_func({f},x(:,1:end-1)); 44 | % if mod(i,200) == 0,fprintf('iteration=%u,gbest=%e\n',i,gbest(end));end 45 | gbest_hist = [gbest_hist gbest(end)]; 46 | fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)) 47 | end 48 | % end -------------------------------------------------------------------------------- /TEC2009_HighDimensionalMultimodalProblems/pso.m: -------------------------------------------------------------------------------- 1 | % function [x_std gbest_fit gbest_hist] = pso(f,bnd,dim,nop,endgen) 2 | clear,clc 3 | f= 8;nop = 50;dim=30; 4 | endgen = 10^4; % maximum Generation 5 | max_fe = 10^6; % current fitness evaluation 6 | if f == 8; Ub = 500; end % Schwefel 7 | if f == 9; Ub = 32.768; end % Rastrigin 8 | if f == 10; Ub = 600; end % Ackley 9 | if f == 11; Ub = 0.5; end % Griewank 10 | if f == 12; Ub = 5.12; end % Penalized1 11 | if f == 13; Ub = 5.12; end % Penalized1 12 | w = 0.72; 13 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 14 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity nop = 10; dim = 9; 15 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 16 | x(:,end+1)=0; 17 | c1 = 1.49445; c2 = 1.49445; 18 | x(:,end) = fit_func({f},x(:,1:end-1)); 19 | pbest = x; %initialize Best Particle Position 20 | [mn ind] = min(x(:,end)); 21 | gbest = x(ind,:); 22 | gbest_hist = []; 23 | fe = 0; 24 | for i=1:endgen 25 | for j=1:nop 26 | if (x(j,end)Vmax)); 35 | % spd(ind) = Vmax.*sign(spd(ind)); 36 | spd=(spd>Vmax).*Vmax+(spd<=Vmax).*spd; 37 | spd=(spd<(Vmin)).*(Vmin)+(spd>=(Vmin)).*spd; 38 | 39 | x(j,1:end-1) = x(j,1:end-1)+spd(j,:); 40 | end 41 | fe = fe+nop; 42 | % x(:,end) = abs(benchmark_func(x(:,1:end-1),f)-f_bias); 43 | x(:,end) = fit_func({f},x(:,1:end-1)); 44 | % if mod(i,200) == 0,fprintf('iteration=%u,gbest=%e\n',i,gbest(end));end 45 | gbest_hist = [gbest_hist gbest(end)]; 46 | fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)) 47 | end 48 | % end -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/fit_func.m: -------------------------------------------------------------------------------- 1 | % fitness function 2 | function f = fit_func(c,x) 3 | global orthm1 orthm2 swarm1 swarm2 K1 K2 K1len K2len s 4 | swarmNum = s; 5 | % c as the fitness function number 6 | func = c{1}; % benchmark number 7 | [nop D]=size(x); 8 | greal=[0 1 0 0 0 0 4.209687462275036e+002 0 0 0 0 0 0 0]; 9 | x=x-greal(func); 10 | if K1 == 0 11 | for i=1:swarmNum 12 | x(:,swarm2(i,:))=x(:,swarm2(i,:))*orthm2(:,swarm2(i,:)); 13 | end 14 | else 15 | for i=1:K1 16 | x(:,swarm1(i,:))=x(:,swarm1(i,:))*orthm1(:,swarm1(i,:)); 17 | end 18 | if K2len ~= 1 19 | for i=1:K2 20 | x(:,swarm2(i,:)-K1*K1len)=x(:,swarm2(i,:)-K1*K1len)*orthm2(:,swarm2(i,:)-K1*K1len); 21 | end 22 | end 23 | end 24 | 25 | x=x+greal(func); 26 | 27 | switch (func) 28 | case {'Sphere',1} 29 | f=sum(x.^2,2); 30 | 31 | case {'Rosenbrock',2} 32 | f=sum(100.*(x(:,1:D-1).^2-x(:,2:D)).^2+(x(:,1:D-1)-1).^2,2); 33 | case {'Ackley',3,9} 34 | f=sum(x.^2,2); 35 | f=20-20.*exp(-0.2.*sqrt(f./D))-exp(sum(cos(2.*pi.*x),2)./D)+exp(1); 36 | case {'Griewank',4,10} 37 | f=1; 38 | for i=1:D 39 | f=f.*cos(x(:,i)./sqrt(i)); 40 | end 41 | f=sum(x.^2,2)./4000-f+1; 42 | case {'Weierstrass',5,11} 43 | x=x+0.5; 44 | a = 0.5; 45 | b = 3; 46 | kmax = 20; 47 | c1(1:kmax+1) = a.^(0:kmax); 48 | c2(1:kmax+1) = 2*pi*b.^(0:kmax); 49 | f=0; 50 | c=-w(0.5,c1,c2); 51 | for i=1:D 52 | f=f+w(x(:,i)',c1,c2); 53 | end 54 | f=f+c*D; 55 | case {'rastrigin', 6,12} 56 | f=sum(x.^2-10.*cos(2.*pi.*x)+10,2); 57 | case {'Rastrigin_noncont',7,13} 58 | x=(abs(x)<0.5).*x+(abs(x)>=0.5).*(round(x.*2)./2); 59 | f=sum(x.^2-10.*cos(2.*pi.*x)+10,2); 60 | case {'Schewfel',8,14} 61 | f=0; 62 | for i=1:D 63 | f=f-(abs(x(:,i))<=500).*(x(:,i).*sin(sqrt(abs(x(:,i)))))+(abs(x(:,i))>500).*0.001.*(500-abs(x(:,i))).^2; 64 | end 65 | f=4.189828872724338e+002*D+f; 66 | end 67 | 68 | function y = w(x,c1,c2) 69 | y = zeros(length(x),1); 70 | for k = 1:length(x) 71 | y(k) = sum(c1 .* cos(c2.*x(:,k))); 72 | end 73 | end 74 | end -------------------------------------------------------------------------------- /TEC2009_ACPSO/clpso.m: -------------------------------------------------------------------------------- 1 | function [gbest_hist fe_hist] = clpso(f,nop,dim) 2 | % clear,clc 3 | % f= 11;nop = 50;dim=300; 4 | endgen = 10^5; % maximum Generation 5 | max_fe = 7*10^6; % 3750000 rcurrent fitness evaluation 6 | 7 | if f == 8; Ub = 500; end % Schwefel 8 | if f == 9; Ub = 5.12; end % Rastrigin 9 | if f == 10; Ub = 32.768; end % Ackley 10 | if f == 11; Ub = 600; end % Griewank 11 | if f == 12; Ub = 50; end % Penalized1 12 | if f == 13; Ub = 50; end % Penalized2 13 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 14 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 15 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 16 | x(:,end+1)=0; % calculate each particle fittness 17 | c = 1.49445; 18 | w_max = 0.9; w_min = 0.4; 19 | for i=1:nop 20 | x(i,end) = fit_func({f},x(i,1:end-1)); 21 | end 22 | 23 | pbest = x; %initialize Best Particle Position 24 | [bst ind] = min(x(:,end)); 25 | gbest = x(ind,:); % initialize global best position 26 | gbest_hist = []; 27 | % initialise pbestf 28 | pbestf = []; pbestftmp = []; 29 | for j = 1:nop 30 | for i = 1:dim 31 | Pind = randi([1 nop]); % Particle Index 32 | Dind = randi([1 dim]); % Dimension Index 33 | pbestftmp = [pbestftmp pbest(Pind,Dind)]; 34 | end 35 | pbestf = [pbestf; pbestftmp]; 36 | pbestftmp = []; 37 | end 38 | fe_hist = []; gbest_hist = [];fe=0;m=7; 39 | while i<=endgen && fe<=max_fe 40 | w = w_max-(w_max-w_min)*i/endgen; 41 | for j=1:nop 42 | w = w_max*((w_max-w_min)*i/endgen); 43 | if mod(i, m) == 0 44 | pbestf(j,:) = exemplar(x,pbest,j); 45 | end 46 | if (x(j,end) < pbest(j,end)) 47 | pbest(j,:) = x(j,:); 48 | end 49 | if (pbest(j,end) < gbest(end)) 50 | gbest = pbest(j,:); 51 | end 52 | end 53 | spd = w.*spd+c.*rand(nop,dim).*(pbestf-x(:,1:end-1)); 54 | spd=(spd>Vmax).*Vmax+(spd<=Vmax).*spd; 55 | spd=(spd<(Vmin)).*(Vmin)+(spd>=(Vmin)).*spd; 56 | x(:,1:end-1) = x(:,1:end-1)+spd; 57 | x(:,end) = fit_func({f},x(:,1:end-1)); 58 | fe = fe+nop; 59 | gbest_hist = [gbest_hist gbest(end)]; fe_hist = [fe_hist fe]; 60 | if mod(i,1000)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 61 | if ((i>1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0),break,end 62 | i = i + 1; 63 | end 64 | end -------------------------------------------------------------------------------- /CEC2005/pso.m: -------------------------------------------------------------------------------- 1 | % function [x_std gbest_fit gbest_hist] = pso(f,bnd,dim,nop,endgen) 2 | clear,clc 3 | f= 12;nop = 30;dim=30;swarmNum=6;alpha=0.1;beta=0.1; 4 | % [gh fe]=ACPSO(15,30,30,3,0.01,0.01); 5 | endgen = 10^4; % maximum Generation 6 | max_fe = 10^6; % current fitness evaluation 7 | global initial_flag action 8 | initial_flag = 0; 9 | if f == 1; Bounds=[-100,100]; f_bias=-450;end 10 | if f == 2; Bounds=[-100,100]; f_bias=-450;end 11 | if f == 3; Bounds=[-100,100]; f_bias=-450;end 12 | if f == 4; Bounds=[-100,100]; f_bias=-450;end 13 | if f == 5; Bounds=[-100,100]; f_bias=-310;end 14 | if f == 6; Bounds=[-100,100]; f_bias=+390;end 15 | if f == 7; Bounds=[0,600]; f_bias=-180;end 16 | if f == 8; Bounds=[-32, 32]; f_bias=-140;end 17 | if f == 9; Bounds=[-5,5]; f_bias=-330;end 18 | if f == 10;Bounds=[-5,5]; f_bias=-330;end 19 | if f == 11;Bounds=[-0.5,0.5]; f_bias=+90;end 20 | if f == 12;Bounds=[-100,100]; f_bias=-460;end 21 | if f == 13,Bounds=[-3,1]; f_bias=-130;end 22 | if f == 14;Bounds=[-100,100]; f_bias=-300;end 23 | if f == 15;Bounds=[-5,5]; f_bias= 120;end 24 | if f == 16;Bounds=[-5,5]; f_bias= 120;end 25 | if f == 17;Bounds=[-5,5]; f_bias= 120;end 26 | if f == 18;Bounds=[-5,5]; f_bias=10;end 27 | if f == 19;Bounds=[-5,5]; f_bias=10;end 28 | if f == 20;Bounds=[-5,5]; f_bias=10;end 29 | if f == 21;Bounds=[-5,5]; f_bias=360;end 30 | if f == 22;Bounds=[-5,5]; f_bias=360;end 31 | if f == 23;Bounds=[-5,5]; f_bias=360;end 32 | if f == 24;Bounds=[-5,5]; f_bias=260;end 33 | if f == 25;Bounds=[-2,5]; f_bias=260;end 34 | w = 0.72; 35 | Ub = Bounds(2); 36 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 37 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity nop = 10; dim = 9; 38 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 39 | x(:,end+1)=0; 40 | c1 = 1.49445; c2 = 1.49445; 41 | x(:,end) = benchmark_func(x(:,1:end-1),f)-f_bias; 42 | pbest = x; %initialize Best Particle Position 43 | [mn ind] = min(x(:,end)); 44 | gbest = x(ind,:); 45 | gbest_hist = []; 46 | fe = 0; 47 | for i=1:endgen 48 | for j=1:nop 49 | if (x(j,end)Vmax)); 58 | % spd(ind) = Vmax.*sign(spd(ind)); 59 | spd=(spd>Vmax).*Vmax+(spd<=Vmax).*spd; 60 | spd=(spd<(Vmin)).*(Vmin)+(spd>=(Vmin)).*spd; 61 | 62 | x(j,1:end-1) = x(j,1:end-1)+spd(j,:); 63 | end 64 | fe = fe+nop; 65 | % x(:,end) = abs(benchmark_func(x(:,1:end-1),f)-f_bias); 66 | x(:,end) = benchmark_func(x(:,1:end-1),f)-f_bias; 67 | % if mod(i,200) == 0,fprintf('iteration=%u,gbest=%e\n',i,gbest(end));end 68 | gbest_hist = [gbest_hist gbest(end)]; 69 | fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)) 70 | end 71 | % end -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/clpso.m: -------------------------------------------------------------------------------- 1 | function [gbest_hist fe_hist] = clpso(f,nop,dim,swarmNum) 2 | % clear,clc 3 | % f= 14;nop = 10;dim=10;swarmNum=6; 4 | endgen = 10^4; % maximum Generation 5 | % if dim == 10, max_fe = 2*10^4; end 6 | % if dim == 30, max_fe = 8*10^5; end 7 | if dim == 10, max_fe = 3*10^4; end 8 | if dim == 30, max_fe = 3*10^5; end 9 | 10 | 11 | global orthm1 orthm2 swarm1 swarm2 K1 K2 K1len K2len s 12 | if f == 9; Ub = 32.768; end % Rotated Ackley 13 | if f == 10; Ub = 600; end % Rotated Griewank 14 | if f == 11; Ub = 0.5; end % Rotated Weierstrass 15 | if f == 12; Ub = 5.12; end % Rotated Rastrigin 16 | if f == 13; Ub = 5.12; end % Rotated Rastrigin_noncont 17 | if f == 14; Ub = 500; end % Rotated Schewfel 18 | % ================= Rotation ======================= 19 | s = swarmNum; 20 | K1 = mod(dim,swarmNum); K1len = ceil(dim/swarmNum); orthm1 = []; 21 | K2 = swarmNum - K1; K2len = floor((dim/swarmNum)); orthm2 = []; 22 | rc=1:dim; swarm1=[]; swarm2=[]; 23 | if K1 == 0 24 | for i=1:K2 25 | orthm2 = [orthm2 orthm_generator(K2len)]; 26 | end 27 | else 28 | for i=1:K1 29 | orthm1 = [orthm1 orthm_generator(K1len)]; 30 | end 31 | for i=1:K1 32 | swarm1(i,:)=rc((i*K1len-K1len+1):(i*K1len)); 33 | end 34 | if K2len == 1 35 | orthm2 = []; 36 | else 37 | for i=1:K2 38 | orthm2 = [orthm2 orthm_generator(K2len)]; 39 | end 40 | end 41 | end 42 | for i=1:K2 43 | swarm2(i,:)=rc((K1*K1len+i*K2len-K2len+1):(K1*K1len+i*K2len)); 44 | end 45 | 46 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 47 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 48 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 49 | x(:,end+1)=0; % calculate each particle fittness 50 | c = 1.49445; 51 | w_max = 0.9; w_min = 0.4; 52 | for i=1:nop 53 | x(i,end) = fit_func({f},x(i,1:end-1)); 54 | end 55 | 56 | pbest = x; %initialize Best Particle Position 57 | [bst ind] = min(x(:,end)); 58 | gbest = x(ind,:); % initialize global best position 59 | gbest_hist = []; 60 | % initialise pbestf 61 | pbestf = []; pbestftmp = []; 62 | for j = 1:nop 63 | for i = 1:dim 64 | Pind = randi([1 nop]); % Particle Index 65 | Dind = randi([1 dim]); % Dimension Index 66 | pbestftmp = [pbestftmp pbest(Pind,Dind)]; 67 | end 68 | pbestf = [pbestf; pbestftmp]; 69 | pbestftmp = []; 70 | end 71 | fe_hist = []; gbest_hist = [];fe=0;m=7; 72 | while i<=endgen && fe<=max_fe 73 | w = w_max-(w_max-w_min)*i/endgen; 74 | for j=1:nop 75 | w = w_max*((w_max-w_min)*i/endgen); 76 | if mod(i, m) == 0 77 | pbestf(j,:) = exemplar(x,pbest,j); 78 | end 79 | if (x(j,end) < pbest(j,end)) 80 | pbest(j,:) = x(j,:); 81 | end 82 | if (pbest(j,end) < gbest(end)) 83 | gbest = pbest(j,:); 84 | end 85 | end 86 | spd = w.*spd+c.*rand(nop,dim).*(pbestf-x(:,1:end-1)); 87 | spd=(spd>Vmax).*Vmax+(spd<=Vmax).*spd; 88 | spd=(spd<(Vmin)).*(Vmin)+(spd>=(Vmin)).*spd; 89 | x(:,1:end-1) = x(:,1:end-1)+spd; 90 | x(:,end) = fit_func({f},x(:,1:end-1)); 91 | fe = fe+nop; 92 | gbest_hist = [gbest_hist gbest(end)]; fe_hist = [fe_hist fe]; 93 | if mod(i,1000)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 94 | if ((i>1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0),break,end 95 | i = i + 1; 96 | end 97 | end -------------------------------------------------------------------------------- /TEC2006_StandardHybridFunc/CLPSO_new_func.m: -------------------------------------------------------------------------------- 1 | function [gbest,gbestval,fitcount]= CLPSO_new_func(fhd,Max_Gen,Max_FES,Particle_Number,Dimension,VRmin,VRmax,varargin) 2 | %[gbest,gbestval,fitcount]= CLPSO_new_func('f8',3500,200000,30,30,-5.12,5.12) 3 | rand('state',sum(100*clock)); 4 | me=Max_Gen; 5 | ps=Particle_Number; 6 | D=Dimension; 7 | cc=[1 1]; %acceleration constants 8 | t=0:1/(ps-1):1;t=5.*t; 9 | Pc=0.0+(0.5-0.0).*(exp(t)-exp(t(1)))./(exp(t(ps))-exp(t(1))); 10 | % Pc=0.5.*ones(1,ps); 11 | m=0.*ones(ps,1); 12 | iwt=0.9-(1:me)*(0.7/me); 13 | % iwt=0.729-(1:me)*(0.0/me); 14 | cc=[1.49445 1.49445]; 15 | if length(VRmin)==1 16 | VRmin=repmat(VRmin,1,D); 17 | VRmax=repmat(VRmax,1,D); 18 | end 19 | mv=0.2*(VRmax-VRmin); 20 | VRmin=repmat(VRmin,ps,1); 21 | VRmax=repmat(VRmax,ps,1); 22 | Vmin=repmat(-mv,ps,1); 23 | Vmax=-Vmin; 24 | pos=VRmin+(VRmax-VRmin).*rand(ps,D); 25 | 26 | for i=1:ps; 27 | e(i,1)=feval(fhd,pos(i,:),varargin{:}); 28 | end 29 | 30 | fitcount=ps; 31 | vel=Vmin+2.*Vmax.*rand(ps,D);%initialize the velocity of the particles 32 | pbest=pos; 33 | pbestval=e; %initialize the pbest and the pbest's fitness value 34 | [gbestval,gbestid]=min(pbestval); 35 | gbest=pbest(gbestid,:);%initialize the gbest and the gbest's fitness value 36 | gbestrep=repmat(gbest,ps,1); 37 | 38 | stay_num=zeros(ps,1); 39 | 40 | ai=zeros(ps,D); 41 | f_pbest=1:ps;f_pbest=repmat(f_pbest',1,D); 42 | for k=1:ps 43 | ar=randperm(D); 44 | ai(k,ar(1:m(k)))=1; 45 | fi1=ceil(ps*rand(1,D)); 46 | fi2=ceil(ps*rand(1,D)); 47 | fi=(pbestval(fi1)=pbestval(fi2))'.*fi2; 48 | bi=ceil(rand(1,D)-1+Pc(k)); 49 | if bi==zeros(1,D),rc=randperm(D);bi(rc(1))=1;end 50 | f_pbest(k,:)=bi.*fi+(1-bi).*f_pbest(k,:); 51 | end 52 | 53 | stop_num=0; 54 | i=1; 55 | 56 | 57 | while i<=me&fitcount<=Max_FES 58 | i=i+1; 59 | for k=1:ps 60 | 61 | if stay_num(k)>=5 62 | % if round(i/10)==i/10%|stay_num(k)>=5 63 | stay_num(k)=0; 64 | ai(k,:)=zeros(1,D); 65 | f_pbest(k,:)=k.*ones(1,D); 66 | ar=randperm(D); 67 | ai(k,ar(1:m(k)))=1; 68 | fi1=ceil(ps*rand(1,D)); 69 | fi2=ceil(ps*rand(1,D)); 70 | fi=(pbestval(fi1)=pbestval(fi2))'.*fi2; 71 | bi=ceil(rand(1,D)-1+Pc(k)); 72 | if bi==zeros(1,D),rc=randperm(D);bi(rc(1))=1;end 73 | f_pbest(k,:)=bi.*fi+(1-bi).*f_pbest(k,:); 74 | end 75 | 76 | for dimcnt=1:D 77 | pbest_f(k,dimcnt)=pbest(f_pbest(k,dimcnt),dimcnt); 78 | end 79 | aa(k,:)=cc(1).*(1-ai(k,:)).*rand(1,D).*(pbest_f(k,:)-pos(k,:))+cc(2).*ai(k,:).*rand(1,D).*(gbestrep(k,:)-pos(k,:));%~~~~~~~~~~~~~~~~~~~~~~ 80 | vel(k,:)=iwt(i).*vel(k,:)+aa(k,:); 81 | vel(k,:)=(vel(k,:)>mv).*mv+(vel(k,:)<=mv).*vel(k,:); 82 | vel(k,:)=(vel(k,:)<(-mv)).*(-mv)+(vel(k,:)>=(-mv)).*vel(k,:); 83 | pos(k,:)=pos(k,:)+vel(k,:); 84 | 85 | if (sum(pos(k,:)>VRmax(k,:))+sum(pos(k,:)1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0),break,end 101 | i=i+1; 102 | end 103 | end -------------------------------------------------------------------------------- /TEC2006_StandardHybridFunc/fit_func.m: -------------------------------------------------------------------------------- 1 | function f=fit_func(fun,x) 2 | [ps,D]=size(x); 3 | 4 | if fun==15 5 | f=com_func1(x); 6 | 7 | elseif fun==16 8 | f=hybrid_func1(x); 9 | 10 | end 11 | 12 | %--------------------------------------------------- 13 | % 1.com Composition Function 1 14 | function fit=com_func1(x) 15 | global initial_flag 16 | persistent fun_num func o sigma lamda bias M 17 | if initial_flag==0 18 | [ps,D]=size(x); 19 | initial_flag=1; 20 | fun_num=10; 21 | load com_func1_data % saved the predefined optima 22 | if length(o(1,:))>=D 23 | o=o(:,1:D); 24 | else 25 | o=-5+10*rand(fun_num,D); 26 | end 27 | o(10,:)=zeros(1,D); 28 | func.f1=str2func('fsphere'); 29 | func.f2=str2func('fsphere'); 30 | func.f3=str2func('fsphere'); 31 | func.f4=str2func('fsphere'); 32 | func.f5=str2func('fsphere'); 33 | func.f6=str2func('fsphere'); 34 | func.f7=str2func('fsphere'); 35 | func.f8=str2func('fsphere'); 36 | func.f9=str2func('fsphere'); 37 | func.f10=str2func('fsphere'); 38 | bias=((1:fun_num)-1).*100; 39 | sigma=ones(1,fun_num); 40 | lamda=5/100.*ones(fun_num,1); 41 | lamda=repmat(lamda,1,D); 42 | for i=1:fun_num 43 | eval(['M.M' int2str(i) '=diag(ones(1,D));']); 44 | end 45 | end 46 | fit=hybrid_composition_func(x,fun_num,func,o,sigma,lamda,bias,M); 47 | %---------------------------------------------------------------- 48 | % 4. Rotated Hybrid Composition Function 1 49 | function fit=hybrid_func1(x) 50 | global initial_flag 51 | persistent fun_num func o sigma lamda bias M 52 | if initial_flag==0 53 | [ps,D]=size(x); 54 | initial_flag=1; 55 | fun_num=10; 56 | load hybrid_func1_data % saved the predefined optima 57 | if length(o(1,:))>=D 58 | o=o(:,1:D); 59 | else 60 | o=-5+10*rand(fun_num,D); 61 | end 62 | o(10,:)=0; 63 | func.f1=str2func('fackley'); 64 | func.f2=str2func('fackley'); 65 | func.f3=str2func('frastrigin'); 66 | func.f4=str2func('frastrigin'); 67 | func.f5=str2func('fweierstrass'); 68 | func.f6=str2func('fweierstrass'); 69 | func.f7=str2func('fgriewank'); 70 | func.f8=str2func('fgriewank'); 71 | func.f9=str2func('fsphere'); 72 | func.f10=str2func('fsphere'); 73 | bias=((1:fun_num)-1).*100; 74 | sigma=ones(1,fun_num); 75 | lamda=[5/32; 5/32; 1; 1; 10; 10; 5/100; 5/100; 5/100; 5/100]; 76 | lamda=repmat(lamda,1,D); 77 | if D==10 78 | load hybrid_func1_M_D10, 79 | elseif D==30 80 | load hybrid_func1_M_D30, 81 | else 82 | for i=1:fun_num 83 | eval(['M.M' int2str(i) '=orthm_generator(D);']); 84 | end 85 | end 86 | end 87 | fit=hybrid_composition_func(x,fun_num,func,o,sigma,lamda,bias,M); 88 | %---------------------------------------------------------------- 89 | 90 | function fit=hybrid_composition_func(x,fun_num,func,o,sigma,lamda,bias,M) 91 | [ps,D]=size(x); 92 | for i=1:fun_num 93 | oo=repmat(o(i,:),ps,1); 94 | weight(:,i)=exp(-sum((x-oo).^2,2)./2./(D*sigma(i)^2)); 95 | weight 96 | pause 97 | end 98 | weight 99 | [tmp,tmpid]=sort(weight,2); 100 | for i=1:ps 101 | weight(i,:)=(weight(i,:)==tmp(i,fun_num)).*weight(i,:)+(weight(i,:)~=tmp(i,fun_num)).*(weight(i,:).*(1-tmp(i,fun_num).^10)); 102 | end 103 | weight=weight./repmat(sum(weight,2),1,fun_num); 104 | 105 | fit=0; 106 | for i=1:fun_num 107 | oo=repmat(o(i,:),ps,1); 108 | eval(['f=feval(func.f' int2str(i) ',((x-oo)./repmat(lamda(i,:),ps,1))*M.M' int2str(i) ');']); 109 | x1=5*ones(1,D); 110 | eval(['f1=feval(func.f' int2str(i) ',(x1./lamda(i,:))*M.M' int2str(i) ');']); 111 | fit1=2000.*f./f1; 112 | fit=fit+weight(:,i).*(fit1+bias(i)); 113 | end 114 | %------------------------------------------------- 115 | %basic functions 116 | 117 | function f=fsphere(x) 118 | %Please notice there is no use to rotate a sphere function, with rotation 119 | %here just for a similar structure as other functions and easy programming 120 | [ps,D]=size(x); 121 | f=sum(x.^2,2); 122 | %-------------------------------- 123 | function f=fgriewank(x) 124 | [ps,D]=size(x); 125 | f=1; 126 | for i=1:D 127 | f=f.*cos(x(:,i)./sqrt(i)); 128 | end 129 | f=sum(x.^2,2)./4000-f+1; 130 | %-------------------------------- 131 | function f=fackley(x) 132 | [ps,D]=size(x); 133 | f=sum(x.^2,2); 134 | f=20-20.*exp(-0.2.*sqrt(f./D))-exp(sum(cos(2.*pi.*x),2)./D)+exp(1); 135 | %-------------------------------- 136 | function f=frastrigin(x) 137 | [ps,D]=size(x); 138 | f=sum(x.^2-10.*cos(2.*pi.*x)+10,2); 139 | %-------------------------------- 140 | function [f]=fweierstrass(x) 141 | [ps,D]=size(x); 142 | x=x+0.5; 143 | a = 0.5; 144 | b = 3; 145 | kmax = 20; 146 | c1(1:kmax+1) = a.^(0:kmax); 147 | c2(1:kmax+1) = 2*pi*b.^(0:kmax); 148 | f=0; 149 | c=-w(0.5,c1,c2); 150 | for i=1:D 151 | f=f+w(x(:,i)',c1,c2); 152 | end 153 | f=f+c*D; 154 | 155 | function y = w(x,c1,c2) 156 | y = zeros(length(x),1); 157 | for k = 1:length(x) 158 | y(k) = sum(c1 .* cos(c2.*x(:,k))); 159 | end 160 | -------------------------------------------------------------------------------- /CEC2005/test.m: -------------------------------------------------------------------------------- 1 | cd 'C:\Users\M0RBiD\Documents\MATLAB\PSO implementation\CPSOLA_Final\CEC2005' 2 | clear 3 | clc 4 | global initial_flag orthm swarmNum action alpha beta 5 | % f = 1; Bounds=[-100,100]; f_bias=-450; 6 | % f = 2; Bounds=[-100,100]; f_bias=-450; 7 | % f = 3; Bounds=[-100,100]; f_bias=-450; 8 | % f = 4; Bounds=[-100,100]; f_bias=-450; 9 | % f = 5; Bounds=[-100,100]; f_bias=-310; 10 | % f = 6; Bounds=[-100,100]; f_bias=+390; 11 | % f = 7; Bounds=[0,600]; f_bias=-180; 12 | % f = 8; Bounds=[-32, 32]; f_bias=-140; 13 | % f = 9; Bounds=[-5,5]; f_bias=-330; 14 | % f = 10;Bounds=[-5,5]; f_bias=-330; 15 | % f = 11;Bounds=[-0.5,0.5]; f_bias=90; 16 | % f = 12;Bounds=[-100,100]; f_bias=-460; 17 | % f = 13;Bounds=[-3,1]; f_bias=-130; 18 | % f = 14;Bounds=[-100,100]; f_bias=-300; 19 | % f = 15;Bounds=[-5,5]; f_bias= 120; 20 | % f = 16;Bounds=[-5,5]; f_bias= 120; 21 | % f = 17;Bounds=[-5,5]; f_bias= 120; 22 | % f = 18;Bounds=[-5,5]; f_bias=10; 23 | % f = 19;Bounds=[-5,5]; f_bias=10; 24 | % f = 20;Bounds=[-5,5]; f_bias=10; 25 | f = 21;Bounds=[-5,5]; f_bias=360; 26 | % f = 22;Bounds=[-5,5]; f_bias=360; 27 | % f = 23;Bounds=[-5,5]; f_bias=360; 28 | % f = 24;Bounds=[-5,5]; f_bias=260; 29 | % f = 25;Bounds=[-2,5]; f_bias=260; 30 | 31 | nop = 30;dim = 25;swarmNum = 3; 32 | Ub = Bounds(2); 33 | Lb = -Ub; bnd = [Lb Ub]; vm = Ub; 34 | Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 35 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 36 | endgen = 10^3; % maximum Generation 37 | max_fe = 10^6; % current fitness evaluation 38 | fe = 0; 39 | w=0.9-(1:endgen)*(0.7/endgen); 40 | s = 1*10^5; % Maximum Stagnation epochs 41 | tr_num = 1*10^5; % train epochs 42 | alpha = 0.01; beta = 0.01; 43 | c1 = 1.49445; c2 = 1.49445; 44 | w_max = 0.9; w_min = 0.4; 45 | 46 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 47 | 48 | pbest = x; %initialize Best Particle Position 49 | 50 | sbest_fit = []; % swarm best fitness 51 | sbest_hist = []; % swarm best history 52 | 53 | % ===== calculate sbest of each swarm ===== 54 | [mn ind] = min(abs(benchmark_func(x,f)-f_bias)); 55 | sbest = x(ind,:); 56 | 57 | % ====== Learning Automata initialization ======= 58 | action = 1:swarmNum; r = length(action); 59 | p = repmat(1/r,swarmNum,dim); % action probability vector 60 | % p(1,1:10) = 0.5;p(1,11:20) = 0.25;p(1,21:30) = 0.25; 61 | % p(2,1:10) = 0.25;p(2,11:20) = 0.5;p(2,21:30) = 0.25; 62 | % p(3,1:10) = 0.25;p(3,11:20) = 0.25;p(3,21:30) = 0.5; 63 | i = 1; 64 | while i<=endgen && fe<=max_fe 65 | w = w_max-(w_max-w_min)*i/endgen; 66 | % Train Learning Automata Phase 67 | % if i < tr_num 68 | 69 | % else 70 | % Play Learning Automata Phase 71 | swarmTable = automataActSel(p); 72 | for j = 1:swarmNum 73 | swarmDim = find(swarmTable(j,:) == 1); 74 | swarmLength = length(swarmDim); 75 | if ~isempty(swarmDim) 76 | sbest_tmp = benchmark_func(sbest,f)+f_bias; 77 | for jj =1:swarmLength 78 | for k = 1:nop 79 | 80 | if benchmark_func(b(sbest,swarmDim(jj),x(k,swarmDim(jj))),f)+f_bias... 81 | < benchmark_func(b(sbest,swarmDim(jj),x(k,swarmDim(jj))),f)+f_bias 82 | pbest(k,swarmDim(jj)) = x(k,swarmDim(jj)); 83 | end 84 | 85 | if benchmark_func(b(sbest,swarmDim(jj),pbest(k,swarmDim(jj))),f)+f_bias < benchmark_func(sbest,f)+f_bias 86 | sbest(swarmDim(jj)) = pbest(k,swarmDim(jj)); 87 | end 88 | spd(k,swarmDim(jj)) = w.* spd(k,swarmDim(jj))... 89 | +c1.*rand(1,length(swarmDim(jj))).*(pbest(k,swarmDim(jj))-x(k,swarmDim(jj)))... 90 | +c2.*rand(1,length(swarmDim(jj))).*(sbest(swarmDim(jj)) -x(k,swarmDim(jj))); 91 | % spd(k,swarmDim(jj))=(spd(k,swarmDim(jj))>Vmax).*Vmax+(spd(k,swarmDim(jj))<=Vmax).*spd(k,swarmDim(jj)); 92 | % spd(k,swarmDim(jj))=(spd(k,swarmDim(jj))<(Vmin)).*(Vmin)+(spd(k,swarmDim(jj))>=(Vmin)).*spd(k,swarmDim(jj)); 93 | spdtmp = spd(k,swarmDim(jj)); ind = find(abs(spdtmp>vm)); 94 | spdtmp(ind) = vm.*sign(spdtmp(ind)); spd(k,swarmDim(jj)) = spdtmp; 95 | x(k,swarmDim(jj)) = x(k,swarmDim(jj))+spd(k,swarmDim(jj)); 96 | sbest_fit = benchmark_func(sbest,f)+f_bias; 97 | sbest_hist = [sbest_hist sbest_fit]; 98 | end 99 | fe = fe + nop; 100 | end 101 | p = automataProbUp(p,swarmDim,swarmTable,sbest_fit,sbest_tmp); 102 | end 103 | end 104 | % end 105 | 106 | % Ackley Griewank Rastrigin_N Schewfel 107 | % sigma = sigma * e^ tau .* normrnd(0,1,[nop dim]); 108 | % x = x + sigma .* normrnd(0,1,[nop dim]); 109 | 110 | fprintf('Fitness Evaluation=%u,SBEST=%e\n',fe,sbest_fit) 111 | if (mod(fe,s) == 0 && (sbest_hist(fe-s+1) == sbest_fit)) || sbest_fit ==0, break, end 112 | i = i + 1; 113 | end 114 | sbest_hist(end:max_fe) = sbest_hist(end); 115 | plot(log(sbest_hist)) 116 | -------------------------------------------------------------------------------- /TEC2006_StandardHybridFunc/ACPSO.m: -------------------------------------------------------------------------------- 1 | function [gbest_hist fe_hist]=ACPSO(f,nop,dim,swarmNum,alpha,beta) 2 | clear,clc 3 | %f= 15 ;nop = 40;dim=30;swarmNum=3;alpha=0.1;beta=0.1; 4 | % [gh fe]=ACPSO(13,40,30,3,0.1,0.1); 5 | endgen = 10^4; % maximum Generation 6 | max_fe = 3*10^5; % current fitness evaluation 7 | global action initial_flag 8 | if f == 15; Ub = 500; end % Composition function 1 (CF1) 9 | if f == 16; Ub = 500; end % Composition function 5 (CF5) 10 | initial_flag=0; 11 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 12 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 13 | x=Lb/100+(Ub/100-Lb/100).*rand(nop,dim); % initialize position 14 | tr_num = 500; % train epochs 15 | c1 = 1.49445; c2 = 1.49445; 16 | w_max = 0.9; w_min = 0.4; 17 | pbest = x; %initialize Best Particle Position 18 | imp_tag = 0; % improvement TAG 19 | gbest_hist = []; % swarm best history 20 | fe_hist = []; 21 | % ===== calculate sbest of each swarm ===== 22 | [mn ind] = min(fit_func(f,x)); 23 | gbest = x(ind,:); gbest(end+1) = mn; 24 | % ====== Learning Automata initialization ======= 25 | action = 1:swarmNum; r = length(action); 26 | p = repmat(1/r,swarmNum,dim); % action probability vector 27 | swarmTable = automataActSel(p); 28 | swarm_ind= []; dim_ind = []; 29 | i = 1; fe = 0; 30 | initial_flag=0; 31 | while i<=endgen && fe<=max_fe 32 | w = w_max-(w_max-w_min)*i/endgen; 33 | % Train Learning Automata Phase 34 | if i < tr_num 35 | 36 | for j = 1:swarmNum 37 | swarmDim = find(swarmTable(j,:) == 1); 38 | swarmLength = length(swarmDim); 39 | if ~isempty(swarmLength) 40 | for k = 1:nop 41 | if fit_func(f,b(gbest(1:end-1),swarmDim,x(k,swarmDim)))Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 54 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 55 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 56 | gbest_hist = [gbest_hist gbest(end)]; 57 | fe = fe + nop; 58 | if i>1 && j == swarm_ind 59 | p = automataProbUp(p,imp_tag,j,dim_ind,swarmTable,alpha,beta); 60 | end 61 | imp_tag = 0; 62 | end 63 | end 64 | dim_ind = mod(i,dim); 65 | if dim_ind == 0 66 | dim_ind = dim; 67 | end 68 | rc=randperm(swarmNum); swarm_ind=rc(1); 69 | if swarmTable(swarm_ind,dim_ind) == 1 70 | swarm_ind=rc(2); 71 | end 72 | swarmTable(:,dim_ind) = 0; 73 | swarmTable(swarm_ind,dim_ind) = 1; 74 | else 75 | % ========= Play Learning Automata Phase ========== 76 | swarmTable = automataActSel(p); 77 | for j = 1:swarmNum 78 | swarmDim = find(swarmTable(j,:) == 1); 79 | swarmLength = length(swarmDim); 80 | if ~isempty(swarmLength) 81 | for k = 1:nop 82 | if fit_func(f,b(gbest(1:end-1),swarmDim,x(k,swarmDim)))Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 95 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 96 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 97 | gbest_hist = [gbest_hist gbest(end)]; 98 | fe = fe + nop; 99 | p = automataProbUp(p,imp_tag,j,swarmDim,swarmTable,alpha,beta); 100 | imp_tag = 0; 101 | end 102 | end 103 | end 104 | gbest_hist = [gbest_hist gbest(end)]; fe_hist = [fe_hist fe]; 105 | if mod(i,500)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 106 | if ((i>1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0) 107 | % gbest_hist(end+1) = gbest(end); fe_hist(end+1) = max_fe; 108 | break 109 | end 110 | i = i + 1; 111 | end 112 | % plot(fe_hist,log(gbest_hist)) 113 | end -------------------------------------------------------------------------------- /CEC2005/README.txt: -------------------------------------------------------------------------------- 1 | % Prepared by Jane J. Liang. Email: liangjing@pmail.ntu.edu.sg February 20, 2005. 2 | 3 | benchmark_func.m is the main function for these minimization problems 4 | f=benchmark_func(x,func_num) 5 | x is the variable, f is the function value, func_num is the function num, 6 | data files save the necessary information. 7 | func_plot.m is used to plot the 2-D function map 8 | 9 | 25 functions in all, from 1 to 25, are 10 | 11 | Unimodal Functions (5): 12 | 1. Shifted Sphere Function Bounds[-100,100] f_bias=-450 13 | 2. Shifted Schwefel's Problem 1.2 Bounds[-100,100] f_bias=-450 14 | 3. Shifted Rotated High Conditioned Elliptic Function Bounds[-100,100] f_bias=-450 15 | 4. Shifted Schwefel's Problem 1.2 with Noise in Fitness Bounds[-100,100] f_bias=-450 16 | 5. Schwefel's Problem 2.6 with Global Optimum on Bounds Bounds[-100,100] f_bias=-310 17 | 18 | Multimodal Functions (20): 19 | 20 | Basic Functions (7): 21 | 6. Shifted Rosenbrock's Function Bounds[-100,100] f_bias=390 22 | 7. Shifted Rotated Griewank's Function without Bounds Intilization Range [0, 600] f_bias=-180 23 | 8. Shifted Rotated Ackley's with Global Optimum on Bounds Bounds[-32,32] f_bias=-140 24 | 9. Shifted Rastrigin's Function Bounds[-5,5] f_bias=-330 25 | 10. Shifted Rotated Rastrigin's Function Bounds[-5,5] f_bias=-330 26 | 11. Shifted Rotated Weierstrass Function Bounds[-0.5,0.5] f_bias=90 27 | 12. Schwefel's Problem 2.13 Bounds[-100,100] f_bias=-460 28 | 29 | Expanded Functions (2): 30 | 13. Expanded Extended Griewank's + Rosenbrock's (F8F2) Bounds[-3,1] f_bias=-130 31 | 14. Expanded Rotated Extended Scaffe's F6 Bounds[-100,100] f_bias=-300 32 | 33 | Hybrid Composition Functions (11): 34 | 15. Hybrid Composition Function 1 Bounds[-5,5] f_bias= 120 35 | 16. Rotated Hybrid Comp. Fn 1 Bounds[-5,5] f_bias= 120 36 | 17. Rotated Hybrid Comp. Fn 1 with Noise in Fitness Bounds[-5,5] f_bias= 120 37 | 18. Rotated Hybrid Comp. Fn 2 Bounds[-5,5] f_bias=10 38 | 19. Rotated Hybrid Comp. Fn 2 with Narrow Global Optimal Basin Bounds[-5,5]] f_bias=10 39 | 20. Rotated Hybrid Comp. Fn 2 with the Global Optimum on Bounds Bounds[-5,5] f_bias=10 40 | 21. Rotated Hybrid Comp. Fn 3 Bounds[-5,5] f_bias=360 41 | 22. Rotated Hybrid Comp. Fn 3 with High Condition Number Matrix Bounds[-5,5] f_bias=360 42 | 23. Non-Continuous Rotated Hybrid Comp. Fn 3 Bounds[-5,5] f_bias=360 43 | 24. Rotated Hybrid Comp. Fn 4 Bounds[-5,5] f_bias=260 44 | 25. Rotated Hybrid Comp. Fn 4 without Bounds Intilization Range[-2,5] f_bias=260 45 | 46 | 47 | 48 | 49 | ***Please note: 50 | When you use the test function, remember to set a global variable initial_flag, and make 51 | sure initial_flag=0 before each search. 52 | 53 | For details of the test functions, please read intro-2-functions.doc file 54 | 55 | %~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~% 56 | Files: 57 | 58 | %~~~~~~~~~~~~~~~% 59 | Matlab *.m files: 60 | %~~~~~~~~~~~~~~~% 61 | benchmark_func.m 62 | %benchmark_func.m is the main function with all the minimization problems 63 | %f=benchmark_func(x,func_num) 64 | %x is the variable, f is the function value, func_num is the function number (1 to 25), 65 | 66 | func_plot.m 67 | %used to plot the 2-D function map 68 | 69 | %~~~~~~~~~~~~~~~% 70 | Matlab *.mat data files: 71 | %~~~~~~~~~~~~~~~% 72 | 73 | test_data.mat 74 | % 10 points (50D each) & corresponding fitnesses given to assist verification for code translation. 75 | % Variables:x1,x2,x3,....x25 76 | % Corresponding Function Values: f1,f2,f3,....f25 77 | ***Notice, for function 4,17,24,25, since they have noise, please set noise to 0 (e.g setting 0.0*N(0,1)) before test. 78 | 79 | fbias_data.mat 80 | % contain a 1*25 vector f_bias which are the global optimal function values. 81 | 82 | global_optima.mat 83 | % all 25 global optimal points (25 x 100 matrix) for the 25 test functions, 84 | % please note, function 5,8,20 set the global optima on the bounds, so the corresponding 85 | % global optima are: 86 | % if func_num==5,o(1:ceil(D/4))=-100;x(max(floor(0.75*D),1):D)=100;end 87 | % if func_num==8,o(2.*[1:floor(D/2)]-1)=-32;end 88 | % if func_num==20,o(1,2.*[1:floor(D/2)])=5;end 89 | 90 | sphere_func_data.mat 91 | 92 | schwefel_102_data.mat 93 | 94 | high_cond_elliptic_rot_data.mat 95 | elliptic_M_D2.mat 96 | elliptic_M_D10.mat 97 | elliptic_M_D30.mat 98 | elliptic_M_D50.mat 99 | 100 | schwefel_206_data.mat 101 | 102 | rosenbrock_func_data.mat 103 | 104 | griewank_func_data.mat 105 | griewank_M_D2.mat 106 | griewank_M_D10.mat 107 | griewank_M_D30.mat 108 | griewank_M_D50.mat 109 | 110 | ackley_func_data.mat 111 | ackley_M_D2.mat 112 | ackley_M_D10.mat 113 | ackley_M_D30.mat 114 | ackley_M_D50.mat 115 | 116 | rastrigin_func_data.mat 117 | rastrigin_M_D2.mat 118 | rastrigin_M_D10.mat 119 | rastrigin_M_D30.mat 120 | rastrigin_M_D50.mat 121 | 122 | weierstrass_data.mat 123 | weierstrass_M_D2.mat 124 | weierstrass_M_D10.mat 125 | weierstrass_M_D30.mat 126 | weierstrass_M_D50.mat 127 | 128 | schwefel_213_data.mat 129 | 130 | EF8F2_func_data.mat 131 | 132 | E_ScafferF6_func_data.mat 133 | E_ScafferF6_M_D2.mat 134 | E_ScafferF6_M_D10.mat 135 | E_ScafferF6_M_D30.mat 136 | E_ScafferF6_M_D50.mat 137 | 138 | hybrid_func1_data.mat 139 | hybrid_func1_M_D2.mat 140 | hybrid_func1_M_D10.mat 141 | hybrid_func1_M_D30.mat 142 | hybrid_func1_M_D50.mat 143 | 144 | hybrid_func2_data.mat 145 | hybrid_func2_M_D2.mat 146 | hybrid_func2_M_D10.mat 147 | hybrid_func2_M_D30.mat 148 | hybrid_func2_M_D50.mat 149 | 150 | hybrid_func3_data.mat 151 | hybrid_func3_M_D2.mat 152 | hybrid_func3_M_D10.mat 153 | hybrid_func3_M_D30.mat 154 | hybrid_func3_M_D50.mat 155 | 156 | hybrid_func4_data.mat 157 | hybrid_func4_M_D2.mat 158 | hybrid_func4_M_D10.mat 159 | hybrid_func4_M_D30.mat 160 | hybrid_func4_M_D50.mat 161 | 162 | 163 | %%%%%%%%%% 164 | PLEASE NOTE: 165 | hybrid_func1_M_D......matrix data in matlab mat format contain a structure variable M, 166 | and M.M1,M.M2...M.M10 are ten D*D matrix 167 | 168 | -------------------------------------------------------------------------------- /TEC2009_ACPSO/ACPSO.m: -------------------------------------------------------------------------------- 1 | function [gbest_hist fe_hist]=ACPSO(f,nop,dim,swarmNum,alpha,beta) 2 | % clear,clc 3 | % f= 8;nop = 50;dim=300;swarmNum=60;alpha=0.1;beta=0.1; 4 | endgen = 10^5; % maximum Generation 5 | max_fe = 5*10^6; % 3750000 rcurrent fitness evaluation 6 | global action 7 | if f == 8; Ub = 500; end % Schwefel 8 | if f == 9; Ub = 5.12; end % Rastrigin 9 | if f == 10; Ub = 32.768; end % Ackley 10 | if f == 11; Ub = 600; end % Griewank 11 | if f == 12; Ub = 50; end % Penalized1 12 | if f == 13; Ub = 50; end % Penalized2 13 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 14 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 15 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 16 | tr_num = 300; % train epochs 17 | c1 = 1.49445; c2 = 1.49445; 18 | w_max = 0.9; w_min = 0.4; 19 | % ================= Rotation ======================= 20 | % orthm = orthm_generator(dim); 21 | % ====================================================== 22 | pbest = x; %initialize Best Particle Position 23 | imp_tag = 0; % improvement TAG 24 | gbest_hist = []; % swarm best history 25 | fe_hist = []; 26 | % ====== Learning Automata initialization ======= 27 | action = 1:swarmNum; r = length(action); 28 | p = repmat(1/r,swarmNum,dim); % action probability vector 29 | swarmTable = automataActSel(p); 30 | % ===== calculate sbest of each swarm ===== 31 | [mn ind] = min(fit_func({f},x)); 32 | gbest = x(ind,:); gbest(end+1) = mn; 33 | swarm_ind= []; dim_ind = []; 34 | i = 0; fe = 0; 35 | while i<=endgen && fe<=max_fe 36 | w = w_max-(w_max-w_min)*i/endgen; 37 | % Train Learning Automata Phase 38 | if i < tr_num 39 | 40 | for j = 1:swarmNum 41 | swarmDim = find(swarmTable(j,:) == 1); 42 | swarmLength = length(swarmDim); 43 | if ~isempty(swarmLength) 44 | for k = 1:nop 45 | if fit_func({f},b(gbest(1:end-1),swarmDim,x(k,swarmDim)))Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 58 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 59 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 60 | fe = fe + nop; 61 | if i>0 && j == swarm_ind 62 | p = automataProbUp(p,imp_tag,j,dim_ind,swarmTable,alpha,beta); 63 | end 64 | imp_tag = 0; 65 | end 66 | end 67 | dim_ind = mod(i,dim)+1; 68 | rc=randperm(swarmNum); swarm_ind=rc(1); 69 | if swarmTable(swarm_ind,dim_ind) == 1 70 | swarm_ind=rc(2); 71 | end 72 | swarmTable(:,dim_ind) = 0; 73 | swarmTable(swarm_ind,dim_ind) = 1; 74 | else 75 | % ========= Play Learning Automata Phase ========== 76 | swarmTable = automataActSel(p); 77 | for j = 1:swarmNum 78 | swarmDim = find(swarmTable(j,:) == 1); 79 | swarmLength = length(swarmDim); 80 | if ~isempty(swarmLength) 81 | for k = 1:nop 82 | if fit_func({f},b(gbest(1:end-1),swarmDim,x(k,swarmDim)))Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 95 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 96 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 97 | fe = fe + nop; 98 | p = automataProbUp(p,imp_tag,j,swarmDim,swarmTable,alpha,beta); 99 | imp_tag = 0; 100 | end 101 | end 102 | end 103 | gbest_hist = [gbest_hist gbest(end)]; fe_hist = [fe_hist fe]; 104 | if mod(i,500)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 105 | if ((i>1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0) 106 | % gbest_hist(end+1) = gbest(end); fe_hist(end+1) = max_fe; 107 | break 108 | end 109 | i = i + 1; 110 | end 111 | if f == 8, gbest_hist(end) = gbest_hist(end) + (-12569.5); end 112 | gbest(end) 113 | -------------------------------------------------------------------------------- /TEC2009_HighDimensionalMultimodalProblems/ACPSO.m: -------------------------------------------------------------------------------- 1 | function [gbest_hist fe_hist]=ACPSO(f,nop,dim,swarmNum,alpha,beta) 2 | % clear,clc 3 | % f= 12;nop = 50;dim=300;swarmNum=10;alpha=0.1;beta=0.1; 4 | endgen = 10^5; % maximum Generation 5 | max_fe = 5*10^6; % 3750000 rcurrent fitness evaluation 6 | global action 7 | if f == 8; Ub = 500; end % Schwefel 8 | if f == 9; Ub = 5.12; end % Rastrigin 9 | if f == 10; Ub = 32.768; end % Ackley 10 | if f == 11; Ub = 600; end % Griewank 11 | if f == 12; Ub = 50; end % Penalized1 12 | if f == 13; Ub = 50; end % Penalized2 13 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 14 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 15 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 16 | tr_num = 500; % train epochs 17 | c1 = 1.49445; c2 = 1.49445; 18 | w_max = 0.9; w_min = 0.4; 19 | % ================= Rotation ======================= 20 | % orthm = orthm_generator(dim); 21 | % ====================================================== 22 | pbest = x; %initialize Best Particle Position 23 | imp_tag = 0; % improvement TAG 24 | gbest_hist = []; % swarm best history 25 | fe_hist = []; 26 | % ====== Learning Automata initialization ======= 27 | action = 1:swarmNum; r = length(action); 28 | p = repmat(1/r,swarmNum,dim); % action probability vector 29 | swarmTable = automataActSel(p); 30 | % ===== calculate sbest of each swarm ===== 31 | [mn ind] = min(fit_func({f},x)); 32 | gbest = x(ind,:); gbest(end+1) = mn; 33 | swarm_ind= []; dim_ind = []; 34 | i = 1; fe = 0; 35 | while i<=endgen && fe<=max_fe 36 | w = w_max-(w_max-w_min)*i/endgen; 37 | % Train Learning Automata Phase 38 | if i < tr_num 39 | 40 | for j = 1:swarmNum 41 | swarmDim = find(swarmTable(j,:) == 1); 42 | swarmLength = length(swarmDim); 43 | if ~isempty(swarmLength) 44 | for k = 1:nop 45 | if fit_func({f},b(gbest(1:end-1),swarmDim,x(k,swarmDim)))Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 58 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 59 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 60 | fe = fe + nop; 61 | if i>1 && j == swarm_ind 62 | p = automataProbUp(p,imp_tag,j,dim_ind,swarmTable,alpha,beta); 63 | end 64 | imp_tag = 0; 65 | end 66 | end 67 | dim_ind = mod(i,dim); 68 | if dim_ind == 0 69 | dim_ind = dim; 70 | end 71 | rc=randperm(swarmNum); swarm_ind=rc(1); 72 | if swarmTable(swarm_ind,dim_ind) == 1 73 | swarm_ind=rc(2); 74 | end 75 | swarmTable(:,dim_ind) = 0; 76 | swarmTable(swarm_ind,dim_ind) = 1; 77 | i = i + 1; 78 | else 79 | % ========= Play Learning Automata Phase ========== 80 | swarmTable = automataActSel(p); 81 | for j = 1:swarmNum 82 | swarmDim = find(swarmTable(j,:) == 1); 83 | swarmLength = length(swarmDim); 84 | if ~isempty(swarmLength) 85 | for k = 1:nop 86 | if fit_func({f},b(gbest(1:end-1),swarmDim,x(k,swarmDim)))Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 99 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 100 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 101 | fe = fe + nop; 102 | p = automataProbUp(p,imp_tag,j,swarmDim,swarmTable,alpha,beta); 103 | imp_tag = 0; 104 | end 105 | end 106 | end 107 | gbest_hist = [gbest_hist gbest(end)]; fe_hist = [fe_hist fe]; 108 | if mod(i,100)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 109 | if ((i>1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0) 110 | % gbest_hist(end+1) = gbest(end); fe_hist(end+1) = max_fe; 111 | break 112 | end 113 | i = i + 1; 114 | end 115 | if f == 8, gbest_hist(end) = gbest_hist(end) + (-12569.5); end 116 | gbest(end) 117 | -------------------------------------------------------------------------------- /TEC2006_StandardFunc/ACPSO.m: -------------------------------------------------------------------------------- 1 | function [gbest_hist fe_hist]=ACPSO(f,nop,dim,swarmNum,alpha,beta) 2 | clear,clc 3 | %f= 14;nop = 10;dim=10;swarmNum=3;alpha=0.1;beta=0.1; 4 | %[gh fe]=ACPSO(13,30,30,3,0.01,0.01); 5 | endgen = 10^4; % maximum Generation 6 | max_fe = 3*10^5; % current fitness evaluation 7 | global orthm action 8 | if f == 1; Ub = 100; end % Sphere 9 | if f == 2; Ub = 2.048; end % Rosenbrock 10 | if f == 3; Ub = 32.768; end % Ackley 3 11 | if f == 4; Ub = 600; end % Griewank 3 12 | if f == 5; Ub = 0.5; end % Weierstrass 3 13 | if f == 6; Ub = 5.12; end % Rastrigin 6 14 | if f == 7; Ub = 5.12; end % Rastrigin_noncont 15 | if f == 8; Ub = 500; end % Schewfel 16 | if f == 9; Ub = 32.768; end % Rotated Ackley 17 | if f == 10; Ub = 600; end % Rotated Griewank 18 | if f == 11; Ub = 0.5; end % Rotated Weierstrass 19 | if f == 12; Ub = 5.12; end % Rotated Rastrigin 20 | if f == 13; Ub = 5.12; end % Rotated Rastrigin_noncont 21 | if f == 14; Ub = 500; end % Rotated Schewfel 22 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 23 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 24 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 25 | tr_num = 500; % train epochs 26 | c1 = 1.49445; c2 = 1.49445; 27 | w_max = 0.9; w_min = 0.4; 28 | % ================= Rotation ======================= 29 | orthm = orthm_generator(dim); 30 | % ====================================================== 31 | pbest = x; %initialize Best Particle Position 32 | imp_tag = 0; % improvement TAG 33 | gbest_hist = []; % swarm best history 34 | fe_hist = []; 35 | % ====== Learning Automata initialization ======= 36 | action = 1:swarmNum; r = length(action); 37 | p = repmat(1/r,swarmNum,dim); % action probability vector 38 | swarmTable = automataActSel(p); 39 | % ===== calculate sbest of each swarm ===== 40 | [mn ind] = min(fit_func({f},x)); 41 | gbest = x(ind,:); gbest(end+1) = mn; 42 | swarm_ind= []; dim_ind = []; 43 | i = 1; fe = 0; 44 | while i<=endgen && fe<=max_fe 45 | w = w_max-(w_max-w_min)*i/endgen; 46 | % Train Learning Automata Phase 47 | if i < tr_num 48 | 49 | for j = 1:swarmNum 50 | swarmDim = find(swarmTable(j,:) == 1); 51 | swarmLength = length(swarmDim); 52 | if ~isempty(swarmLength) 53 | for k = 1:nop 54 | if fit_func({f},b(gbest(1:end-1),swarmDim,x(k,swarmDim)))Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 67 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 68 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 69 | fe = fe + nop; 70 | if i>1 && j == swarm_ind 71 | p = automataProbUp(p,imp_tag,j,dim_ind,swarmTable,alpha,beta); 72 | end 73 | imp_tag = 0; 74 | end 75 | end 76 | dim_ind = mod(i,dim); 77 | if dim_ind == 0 78 | dim_ind = dim; 79 | end 80 | rc=randperm(swarmNum); swarm_ind=rc(1); 81 | if swarmTable(swarm_ind,dim_ind) == 1 82 | swarm_ind=rc(2); 83 | end 84 | swarmTable(:,dim_ind) = 0; 85 | swarmTable(swarm_ind,dim_ind) = 1; 86 | else 87 | % ========= Play Learning Automata Phase ========== 88 | swarmTable = automataActSel(p); 89 | for j = 1:swarmNum 90 | swarmDim = find(swarmTable(j,:) == 1); 91 | swarmLength = length(swarmDim); 92 | if ~isempty(swarmLength) 93 | for k = 1:nop 94 | if fit_func({f},b(gbest(1:end-1),swarmDim,x(k,swarmDim)))Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 107 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 108 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 109 | fe = fe + nop; 110 | p = automataProbUp(p,imp_tag,j,swarmDim,swarmTable,alpha,beta); 111 | imp_tag = 0; 112 | end 113 | end 114 | end 115 | gbest_hist = [gbest_hist gbest(end)]; fe_hist = [fe_hist fe]; 116 | if mod(i,500)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 117 | if ((i>1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0) 118 | % gbest_hist(end+1) = gbest(end); fe_hist(end+1) = max_fe; 119 | break 120 | end 121 | i = i + 1; 122 | end 123 | % gbest(end) 124 | % plot(fe_hist,log(gbest_hist)) 125 | end 126 | %gbest(end) 127 | -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/ACPSO.m: -------------------------------------------------------------------------------- 1 | % function [gbest_hist fe_hist]=ACPSO(f,nop,dim,swarmNum,alpha,beta) 2 | clear,clc 3 | f= 10;nop = 40;dim=30;swarmNum=3;alpha=0.1;beta=0.01; 4 | %[gh fe]=ACPSO(13,30,30,3,0.01,0.01); 5 | endgen = 10^4; % maximum Generation 6 | max_fe = 10^6; % current fitness evaluation 7 | global orthm1 orthm2 swarm1 swarm2 K1 K2 K1len K2len action 8 | if f == 9; Ub = 32.768; end % Rotated Ackley 9 | if f == 10; Ub = 600; end % Rotated Griewank 10 | if f == 11; Ub = 0.5; end % Rotated Weierstrass 11 | if f == 12; Ub = 5.12; end % Rotated Rastrigin 12 | if f == 13; Ub = 5.12; end % Rotated Rastrigin_noncont 13 | if f == 14; Ub = 500; end % Rotated Schewfel 14 | % ================= Rotation ======================= 15 | K1 = mod(dim,swarmNum); K1len = ceil(dim/swarmNum); orthm1 = []; 16 | K2 = swarmNum - K1; K2len = floor((dim/swarmNum)); orthm2 = []; 17 | rc=1:dim; swarm1=[]; swarm2=[]; 18 | if K1 == 0 19 | for i=1:K2 20 | orthm2 = [orthm2 orthm_generator(K2len)]; 21 | end 22 | else 23 | for i=1:K1 24 | orthm1 = [orthm1 orthm_generator(K1len)]; 25 | end 26 | for i=1:K1 27 | swarm1(i,:)=rc((i*K1len-K1len+1):(i*K1len)); 28 | end 29 | if K2len == 1 30 | orthm2 = []; 31 | else 32 | for i=1:K2 33 | orthm2 = [orthm2 orthm_generator(K2len)]; 34 | end 35 | end 36 | end 37 | for i=1:K2 38 | swarm2(i,:)=rc((K1*K1len+i*K2len-K2len+1):(K1*K1len+i*K2len)); 39 | end 40 | 41 | % ====================================================== 42 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 43 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 44 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 45 | tr_num = 500; % train epochs 46 | c1 = 1.49445; c2 = 1.49445; 47 | w_max = 0.9; w_min = 0.4; 48 | pbest = x; %initialize Best Particle Position 49 | imp_tag = 0; % improvement TAG 50 | gbest_hist = []; % swarm best history 51 | fe_hist = []; 52 | % ====== Learning Automata initialization ======= 53 | action = 1:swarmNum; r = length(action); 54 | p = repmat(1/r,swarmNum,dim); % action probability vector 55 | swarmTable = automataActSel(p); 56 | % ===== calculate sbest of each swarm ===== 57 | [mn ind] = min(fit_func({f},x)); 58 | gbest = x(ind,:); gbest(end+1) = mn; 59 | swarm_ind= []; dim_ind = []; 60 | i = 1; fe = 0; 61 | while i<=endgen && fe<=max_fe 62 | w = w_max-(w_max-w_min)*i/endgen; 63 | % Train Learning Automata Phase 64 | if i < tr_num 65 | for j = 1:swarmNum 66 | swarmDim = find(swarmTable(j,:) == 1); 67 | swarmLength = length(swarmDim); 68 | if ~isempty(swarmLength) 69 | for k = 1:nop 70 | if fit_func({f},b(gbest(1:end-1),swarmDim,x(k,swarmDim)))Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 83 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 84 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 85 | fe = fe + nop; 86 | if i>1 && j == swarm_ind 87 | p = automataProbUp(p,imp_tag,j,dim_ind,swarmTable,alpha,beta); 88 | end 89 | imp_tag = 0; 90 | end 91 | end 92 | dim_ind = mod(i,dim); 93 | if dim_ind == 0 94 | dim_ind = dim; 95 | end 96 | rc=randperm(swarmNum); swarm_ind=rc(1); 97 | if swarmTable(swarm_ind,dim_ind) == 1 98 | swarm_ind=rc(2); 99 | end 100 | swarmTable(:,dim_ind) = 0; 101 | swarmTable(swarm_ind,dim_ind) = 1; 102 | else 103 | % ========= Play Learning Automata Phase ========== 104 | swarmTable = automataActSel(p); 105 | for j = 1:swarmNum 106 | swarmDim = find(swarmTable(j,:) == 1); 107 | swarmLength = length(swarmDim); 108 | if ~isempty(swarmLength) 109 | for k = 1:nop 110 | if fit_func({f},b(gbest(1:end-1),swarmDim,x(k,swarmDim)))Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 123 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 124 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 125 | fe = fe + nop; 126 | p = automataProbUp(p,imp_tag,j,swarmDim,swarmTable,alpha,beta); 127 | imp_tag = 0; 128 | end 129 | end 130 | end 131 | gbest_hist = [gbest_hist gbest(end)]; fe_hist = [fe_hist fe]; 132 | if mod(i,500)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 133 | if ((i>1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0) 134 | break 135 | end 136 | i = i + 1; 137 | end 138 | % gbest(end) 139 | % plot(fe_hist,log(gbest_hist)) 140 | % end -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/learn.m: -------------------------------------------------------------------------------- 1 | % function [gbest_hist fe_hist]=ACPSO(f,nop,dim,swarmNum,alpha,beta) 2 | clear,clc 3 | f= 11;nop = 40;dim=30;swarmNum=3;alpha=0.1;beta=0.0; 4 | %[gh fe]=ACPSO(13,30,30,3,0.01,0.01); 5 | endgen = 10^4; % maximum Generation 6 | max_fe = 10^6; % current fitness evaluation 7 | global orthm1 orthm2 swarm1 swarm2 K1 K2 K1len K2len action 8 | if f == 9; Ub = 32.768; end % Rotated Ackley 9 | if f == 10; Ub = 600; end % Rotated Griewank 10 | if f == 11; Ub = 0.5; end % Rotated Weierstrass 11 | if f == 12; Ub = 5.12; end % Rotated Rastrigin 12 | if f == 13; Ub = 5.12; end % Rotated Rastrigin_noncont 13 | if f == 14; Ub = 500; end % Rotated Schewfel 14 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 15 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 16 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 17 | tr_num = 500; % train epochs 18 | c1 = 1.49445; c2 = 1.49445; 19 | w_max = 0.9; w_min = 0.4; 20 | 21 | % ================= Rotation ======================= 22 | K1 = mod(dim,swarmNum); K1len = ceil(dim/swarmNum); orthm1 = []; 23 | K2 = swarmNum - K1; K2len = floor((dim/swarmNum)); orthm2 = []; 24 | rc=1:dim; swarm1=[]; swarm2=[]; 25 | if K1 == 0 26 | for i=1:K2 27 | orthm2 = [orthm2 orthm_generator(K2len)]; 28 | end 29 | else 30 | for i=1:K1 31 | orthm1 = [orthm1 orthm_generator(K1len)]; 32 | end 33 | for i=1:K1 34 | swarm1(i,:)=rc((i*K1len-K1len+1):(i*K1len)); 35 | end 36 | if K2len == 1 37 | orthm2 = []; 38 | else 39 | for i=1:K2 40 | orthm2 = [orthm2 orthm_generator(K2len)]; 41 | end 42 | end 43 | end 44 | for i=1:K2 45 | swarm2(i,:)=rc((K1*K1len+i*K2len-K2len+1):(K1*K1len+i*K2len)); 46 | end 47 | 48 | % ====================================================== 49 | pbest = x; %initialize Best Particle Position 50 | imp_tag = 0; % improvement TAG 51 | gbest_hist = []; % swarm best history 52 | fe_hist = []; 53 | % ====== Learning Automata initialization ======= 54 | action = 1:swarmNum; r = length(action); 55 | p = repmat(1/r,swarmNum,dim); % action probability vector 56 | swarmTable = automataActSel(p); 57 | % ===== calculate sbest of each swarm ===== 58 | [mn ind] = min(fit_func({f},x)); 59 | gbest = x(ind,:); gbest(end+1) = mn; 60 | swarm_ind= []; dim_ind = []; 61 | i = 1; fe = 0; 62 | while i<=endgen && fe<=max_fe 63 | w = w_max-(w_max-w_min)*i/endgen; 64 | % Train Learning Automata Phase 65 | if i < tr_num 66 | for j = 1:swarmNum 67 | swarmDim = find(swarmTable(j,:) == 1); 68 | swarmLength = length(swarmDim); 69 | if ~isempty(swarmLength) 70 | for k = 1:nop 71 | if fit_func({f},b(gbest(1:end-1),swarmDim,x(k,swarmDim)))Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 84 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 85 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 86 | fe = fe + nop; 87 | if i>1 && j == swarm_ind 88 | p = automataProbUp(p,imp_tag,j,dim_ind,swarmTable,alpha,beta); 89 | end 90 | imp_tag = 0; 91 | end 92 | end 93 | dim_ind = mod(i,dim); 94 | if dim_ind == 0 95 | dim_ind = dim; 96 | end 97 | rc=randperm(swarmNum); swarm_ind=rc(1); 98 | if swarmTable(swarm_ind,dim_ind) == 1 99 | swarm_ind=rc(2); 100 | end 101 | swarmTable(:,dim_ind) = 0; 102 | swarmTable(swarm_ind,dim_ind) = 1; 103 | else 104 | % ========= Play Learning Automata Phase ========== 105 | swarmTable = automataActSel(p); 106 | for j = 1:swarmNum 107 | swarmDim = find(swarmTable(j,:) == 1); 108 | swarmLength = length(swarmDim); 109 | if ~isempty(swarmLength) 110 | for k = 1:nop 111 | if fit_func({f},b(gbest(1:end-1),swarmDim,x(k,swarmDim)))Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 124 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 125 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 126 | fe = fe + nop; 127 | p = automataProbUp(p,imp_tag,j,swarmDim,swarmTable,alpha,beta); 128 | imp_tag = 0; 129 | end 130 | end 131 | end 132 | gbest_hist = [gbest_hist gbest(end)]; fe_hist = [fe_hist fe]; 133 | if mod(i,500)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 134 | if ((i>1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0) 135 | % gbest_hist(end+1) = gbest(end); fe_hist(end+1) = max_fe; 136 | break 137 | end 138 | i = i + 1; 139 | end 140 | gbest(end) 141 | % plot(fe_hist,log(gbest_hist)) 142 | % end -------------------------------------------------------------------------------- /CEC2005/A1.m: -------------------------------------------------------------------------------- 1 | % Adaptive Cooperative Particle Swarm Optimization 2 | % function [gbest_hist fe_hist]=ACPSO(f,nop,dim,swarmNum,alpha,beta) 3 | clear,clc 4 | f= 16;nop = 30;dim=30;swarmNum=6;alpha=0.1;beta=0.1; 5 | % [gh fe]=ACPSO(15,30,30,3,0.01,0.01); 6 | endgen = 10^4; % maximum Generation 7 | max_fe = 3*10^5; % current fitness evaluation 8 | global initial_flag action 9 | initial_flag = 0; 10 | if f == 1; Bounds=[-100,100]; f_bias=-450;end 11 | if f == 2; Bounds=[-100,100]; f_bias=-450;end 12 | if f == 3; Bounds=[-100,100]; f_bias=-450;end 13 | if f == 4; Bounds=[-100,100]; f_bias=-450;end 14 | if f == 5; Bounds=[-100,100]; f_bias=-310;end 15 | if f == 6; Bounds=[-100,100]; f_bias=+390;end 16 | if f == 7; Bounds=[0,600]; f_bias=-180;end 17 | if f == 8; Bounds=[-32, 32]; f_bias=-140;end 18 | if f == 9; Bounds=[-5,5]; f_bias=-330;end 19 | if f == 10;Bounds=[-5,5]; f_bias=-330;end 20 | if f == 11;Bounds=[-0.5,0.5]; f_bias=+90;end 21 | if f == 12;Bounds=[-100,100]; f_bias=-460;end 22 | if f == 13,Bounds=[-3,1]; f_bias=-130;end 23 | if f == 14;Bounds=[-100,100]; f_bias=-300;end 24 | if f == 15;Bounds=[-5,5]; f_bias= 120;end 25 | if f == 16;Bounds=[-5,5]; f_bias= 120;end 26 | if f == 17;Bounds=[-5,5]; f_bias= 120;end 27 | if f == 18;Bounds=[-5,5]; f_bias=10;end 28 | if f == 19;Bounds=[-5,5]; f_bias=10;end 29 | if f == 20;Bounds=[-5,5]; f_bias=10;end 30 | if f == 21;Bounds=[-5,5]; f_bias=360;end 31 | if f == 22;Bounds=[-5,5]; f_bias=360;end 32 | if f == 23;Bounds=[-5,5]; f_bias=360;end 33 | if f == 24;Bounds=[-5,5]; f_bias=260;end 34 | if f == 25;Bounds=[-2,5]; f_bias=260;end 35 | Ub=Bounds(2); 36 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 37 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 38 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 39 | tr_num = 500; % train epochs 40 | c1 = 1.49445; c2 = 1.49445; 41 | w_max = 0.9; w_min = 0.4; 42 | % ====================================================== 43 | pbest = x; %initialize Best Particle Position 44 | imp_tag = 0; % improvement TAG 45 | gbest_hist = []; % swarm best history 46 | fe_hist = []; 47 | % ====== Learning Automata initialization ======= 48 | action = 1:swarmNum; r = length(action); 49 | p = repmat(1/r,swarmNum,dim); % action probability vector 50 | swarmTable = automataActSel(p); 51 | % ===== calculate sbest of each swarm ===== 52 | B=[]; 53 | for i=1:nop 54 | B = [B benchmark_func(x(i,:),f)-f_bias]; 55 | end 56 | [mn ind] = min(B); 57 | gbest = x(ind,:); gbest(end+1) = mn; 58 | swarm_ind= []; dim_ind = []; 59 | i = 1; fe = 0; cpy=10; 60 | % Train Learning Automata Phase 61 | for i=1:tr_num 62 | w = w_max-(w_max-w_min)*i/endgen; 63 | for j = 1:swarmNum 64 | swarmDim = find(swarmTable(j,:) == 1); 65 | swarmLength = length(swarmDim); 66 | if ~isempty(swarmLength) 67 | for k = 1:nop 68 | if benchmark_func(b(gbest(1:end-1),swarmDim,x(k,swarmDim)),f)-f_bias<... 69 | benchmark_func(b(gbest(1:end-1),swarmDim,pbest(k,swarmDim)),f)-f_bias 70 | pbest(k,swarmDim) = x(k,swarmDim); 71 | % imp_tag = imp_tag+1; 72 | end 73 | if benchmark_func(b(gbest(1:end-1),swarmDim,pbest(k,swarmDim)),f)-f_bias < gbest(end) 74 | gbest(swarmDim) = pbest(k,swarmDim); 75 | gbest(end) = benchmark_func(gbest(1:end-1),f)-f_bias; 76 | imp_tag = 1; 77 | end 78 | end 79 | spd(:,swarmDim) = w.* spd(:,swarmDim)... 80 | +c1.*rand(nop,length(swarmDim)).*(pbest(:,swarmDim)-x(:,swarmDim))... 81 | +c2.*rand(nop,length(swarmDim)).*(repmat(gbest(swarmDim),nop,1)-x(:,swarmDim)); 82 | spd(:,swarmDim)=(spd(:,swarmDim)>Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 83 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 84 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 85 | if i>1 && j == swarm_ind 86 | p = automataProbUp(p,imp_tag,j,dim_ind,swarmTable,alpha,beta); 87 | end 88 | imp_tag = 0; 89 | end 90 | end 91 | fe = fe + swarmNum*nop; 92 | dim_ind = mod(i,dim); 93 | if dim_ind == 0 94 | dim_ind = dim; 95 | end 96 | rc=randperm(swarmNum); swarm_ind=rc(1); 97 | if swarmTable(swarm_ind,dim_ind) == 1 98 | swarm_ind=rc(2); 99 | end 100 | swarmTable(:,dim_ind) = 0; 101 | swarmTable(swarm_ind,dim_ind) = 1; 102 | if mod(i,cpy)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 103 | end 104 | % % ========= Play Learning Automata Phase ========== 105 | while i<=endgen && fe<=max_fe 106 | w = w_max-(w_max-w_min)*i/endgen; 107 | swarmTable = automataActSel(p); 108 | for j = 1:swarmNum 109 | swarmDim = find(swarmTable(j,:) == 1); 110 | swarmLength = length(swarmDim); 111 | if ~isempty(swarmLength) 112 | for k = 1:nop 113 | if benchmark_func(b(gbest(1:end-1),swarmDim,x(k,swarmDim)),f)-f_bias<... 114 | benchmark_func(b(gbest(1:end-1),swarmDim,pbest(k,swarmDim)),f)-f_bias 115 | % imp_tag = imp_tag+1; 116 | end 117 | if benchmark_func(b(gbest(1:end-1),swarmDim,pbest(k,swarmDim)),f)-f_bias < gbest(end) 118 | gbest(swarmDim) = pbest(k,swarmDim); 119 | gbest(end) = benchmark_func(gbest(1:end-1),f)-f_bias; 120 | imp_tag = 1; 121 | end 122 | end 123 | spd(:,swarmDim) = w.* spd(:,swarmDim)... 124 | +c1.*rand(nop,length(swarmDim)).*(pbest(:,swarmDim)-x(:,swarmDim))... 125 | +c2.*rand(nop,length(swarmDim)).*(repmat(gbest(swarmDim),nop,1)-x(:,swarmDim)); 126 | spd(:,swarmDim)=(spd(:,swarmDim)>Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 127 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 128 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 129 | p = automataProbUp(p,imp_tag,j,swarmDim,swarmTable,alpha,beta); 130 | imp_tag = 0; 131 | end 132 | end 133 | fe = fe + swarmNum*nop; 134 | gbest_hist = [gbest_hist gbest(end)]; fe_hist = [fe_hist fe]; 135 | if mod(i,cpy)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 136 | if ((i>1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0) 137 | % gbest_hist(end+1) = gbest(end); fe_hist(end+1) = max_fe; 138 | break 139 | end 140 | i = i + 1; 141 | end 142 | 143 | % gbest(end) 144 | % plot(fe_hist,log(gbest_hist)) 145 | % end 146 | -------------------------------------------------------------------------------- /CEC2005/ACPSO.m: -------------------------------------------------------------------------------- 1 | % Adaptive Cooperative Particle Swarm Optimization 2 | function [gbest_hist fe_hist]=ACPSO(f,nop,dim,swarmNum,alpha,beta) 3 | clear,clc 4 | % f= 1;nop = 30;dim=30;swarmNum=6;alpha=0.1;beta=0.1; 5 | % [gh fe]=ACPSO(15,30,30,3,0.01,0.01); 6 | endgen = 10^4; % maximum Generation 7 | max_fe = 10^6; % current fitness evaluation 8 | global initial_flag action 9 | initial_flag = 0; 10 | if f == 1; Bounds=[-100,100]; f_bias=-450;end 11 | if f == 2; Bounds=[-100,100]; f_bias=-450;end 12 | if f == 3; Bounds=[-100,100]; f_bias=-450;end 13 | if f == 4; Bounds=[-100,100]; f_bias=-450;end 14 | if f == 5; Bounds=[-100,100]; f_bias=-310;end 15 | if f == 6; Bounds=[-100,100]; f_bias=+390;end 16 | if f == 7; Bounds=[0,600]; f_bias=-180;end 17 | if f == 8; Bounds=[-32, 32]; f_bias=-140;end 18 | if f == 9; Bounds=[-5,5]; f_bias=-330;end 19 | if f == 10;Bounds=[-5,5]; f_bias=-330;end 20 | if f == 11;Bounds=[-0.5,0.5]; f_bias=+90;end 21 | if f == 12;Bounds=[-100,100]; f_bias=-460;end 22 | if f == 13,Bounds=[-3,1]; f_bias=-130;end 23 | if f == 14;Bounds=[-100,100]; f_bias=-300;end 24 | if f == 15;Bounds=[-5,5]; f_bias= 120;end 25 | if f == 16;Bounds=[-5,5]; f_bias= 120;end 26 | if f == 17;Bounds=[-5,5]; f_bias= 120;end 27 | if f == 18;Bounds=[-5,5]; f_bias=10;end 28 | if f == 19;Bounds=[-5,5]; f_bias=10;end 29 | if f == 20;Bounds=[-5,5]; f_bias=10;end 30 | if f == 21;Bounds=[-5,5]; f_bias=360;end 31 | if f == 22;Bounds=[-5,5]; f_bias=360;end 32 | if f == 23;Bounds=[-5,5]; f_bias=360;end 33 | if f == 24;Bounds=[-5,5]; f_bias=260;end 34 | if f == 25;Bounds=[-2,5]; f_bias=260;end 35 | 36 | Ub = Bounds(2); 37 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 38 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity nop = 10; dim = 9; 39 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 40 | tr_num = 500; % train epochs 41 | c1 = 1.49445; c2 = 1.49445; 42 | w_max = 0.9; w_min = 0.4; 43 | pbest = x; %initialize Best Particle Position 44 | imp_tag = 0; % improvement TAG 45 | gbest_hist = []; % swarm best history 46 | fe_hist = []; 47 | % ===== calculate sbest of each swarm ===== 48 | [mn ind] = min(abs(benchmark_func(x,f)-f_bias)); 49 | gbest = x(ind,:); 50 | % gbest(end+1) = mn; 51 | % ====== Learning Automata initialization ======= 52 | action = 1:swarmNum; r = length(action); 53 | p = repmat(1/r,swarmNum,dim); % action probability vector 54 | swarmTable = automataActSel(p); 55 | swarm_ind= []; dim_ind = []; 56 | i = 1; fe = 0; 57 | initial_flag = 0; 58 | while i<=endgen && fe<=max_fe 59 | w = w_max-(w_max-w_min)*i/endgen; 60 | if i < tr_num% ============= Train Learning Automata Phase ============= 61 | for j = 1:swarmNum 62 | swarmDim = find(swarmTable(j,:) == 1); 63 | swarmLength = length(swarmDim); 64 | if ~isempty(swarmLength) 65 | for k = 1:nop 66 | if abs(benchmark_func(b(gbest,swarmDim,x(k,swarmDim)),f)-f_bias)... 67 | < abs(benchmark_func(b(gbest,swarmDim,x(k,swarmDim)),f)-f_bias) 68 | j 69 | pbest(k,swarmDim) = x(k,swarmDim); 70 | % imp_tag = imp_tag+1; 71 | end 72 | if abs(benchmark_func(b(gbest,swarmDim,pbest(k,swarmDim)),f)-f_bias) < abs(benchmark_func(gbest,f)-f_bias) 73 | gbest(swarmDim) = pbest(k,swarmDim); 74 | % gbest(end) = benchmark_func(gbest(1:end-1),f)-f_bias; 75 | imp_tag = 1; 76 | end 77 | end 78 | spd(:,swarmDim) = w.* spd(:,swarmDim)... 79 | +c1.*rand(nop,length(swarmDim)).*(pbest(:,swarmDim)-x(:,swarmDim))... 80 | +c2.*rand(nop,length(swarmDim)).*(repmat(gbest(swarmDim),nop,1)-x(:,swarmDim)); 81 | spd(:,swarmDim)=(spd(:,swarmDim)>Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 82 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 83 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 84 | fe = fe + nop; 85 | if i>1 && j == swarm_ind 86 | p = automataProbUp(p,imp_tag,j,dim_ind,swarmTable,alpha,beta); 87 | end 88 | imp_tag = 0; 89 | end 90 | end 91 | dim_ind = mod(i,dim); 92 | if dim_ind == 0, dim_ind = dim; end 93 | rc=randperm(swarmNum); swarm_ind=rc(1); 94 | if swarmTable(swarm_ind,dim_ind) == 1, swarm_ind=rc(2); end 95 | swarmTable(:,dim_ind) = 0; swarmTable(swarm_ind,dim_ind) = 1; 96 | else % ========= Play Learning Automata Phase ========== 97 | swarmTable = automataActSel(p); 98 | % initial_flag = 0; 99 | for j = 1:swarmNum 100 | swarmDim = find(swarmTable(j,:) == 1); 101 | swarmLength = length(swarmDim); 102 | if ~isempty(swarmLength) 103 | for k = 1:nop 104 | if abs(benchmark_func(b(gbest,swarmDim,x(k,swarmDim)),f)-f_bias)... 105 | < abs(benchmark_func(b(gbest,swarmDim,x(k,swarmDim)),f)-f_bias) 106 | pbest(k,swarmDim) = x(k,swarmDim); 107 | % imp_tag = imp_tag+1; 108 | end 109 | if abs((benchmark_func(b(gbest,swarmDim,pbest(k,swarmDim)),f)-f_bias) < abs(benchmark_func(gbest,f))-f_bias) 110 | gbest(swarmDim) = pbest(k,swarmDim); 111 | % gbest(end) = benchmark_func(gbest(1:end-1),f)-f_bias; 112 | imp_tag = 1; 113 | end 114 | end 115 | spd(:,swarmDim) = w.* spd(:,swarmDim)... 116 | +c1.*rand(nop,length(swarmDim)).*(pbest(:,swarmDim)-x(:,swarmDim))... 117 | +c2.*rand(nop,length(swarmDim)).*(repmat(gbest(swarmDim),nop,1)-x(:,swarmDim)); 118 | spd(:,swarmDim)=(spd(:,swarmDim)>Vmax).*Vmax+(spd(:,swarmDim)<=Vmax).*spd(:,swarmDim); 119 | spd(:,swarmDim)=(spd(:,swarmDim)<(Vmin)).*(Vmin)+(spd(:,swarmDim)>=(Vmin)).*spd(:,swarmDim); 120 | x(:,swarmDim) = x(:,swarmDim)+spd(:,swarmDim); 121 | fe = fe + nop; 122 | p = automataProbUp(p,imp_tag,j,swarmDim,swarmTable,alpha,beta); 123 | imp_tag = 0; 124 | end 125 | end 126 | end 127 | gbest_hist = [gbest_hist abs(benchmark_func(gbest,f)-f_bias)]; fe_hist = [fe_hist fe]; 128 | if mod(i,10)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 129 | if ((i>1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0) 130 | % gbest_hist(end+1) = gbest(end); fe_hist(end+1) = max_fe; 131 | break 132 | end 133 | i = i + 1; 134 | end 135 | % plot(fe_hist,log(gbest_hist)) 136 | end -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/icpsoh.m: -------------------------------------------------------------------------------- 1 | % Idealized CPSO-H 2 | function [gbest_hist fe_hist] = icpsoh(f,nop,dim,swarmNum) 3 | % clear,clc 4 | % f= 9;nop = 10;dim=10;swarmNum=6; 5 | endgen = 10^4; % maximum Generation 6 | if dim == 10, max_fe = 3*10^4; end 7 | if dim == 30, max_fe = 3*10^5; end 8 | 9 | global orthm1 orthm2 swarm1 swarm2 K1 K2 K1len K2len s 10 | if f == 9; Ub = 32.768; end % Rotated Ackley 11 | if f == 10; Ub = 600; end % Rotated Griewank 12 | if f == 11; Ub = 0.5; end % Rotated Weierstrass 13 | if f == 12; Ub = 5.12; end % Rotated Rastrigin 14 | if f == 13; Ub = 5.12; end % Rotated Rastrigin_noncont 15 | if f == 14; Ub = 500; end % Rotated Schewfel 16 | % ================= Rotation ======================= 17 | s = swarmNum; 18 | K1 = mod(dim,swarmNum); K1len = ceil(dim/swarmNum); orthm1 = []; 19 | K2 = swarmNum - K1; K2len = floor((dim/swarmNum)); orthm2 = []; 20 | rc=1:dim;swarm1=[]; swarm2=[]; 21 | if K1 == 0 22 | for i=1:K2 23 | orthm2 = [orthm2 orthm_generator(K2len)]; 24 | end 25 | else 26 | for i=1:K1 27 | orthm1 = [orthm1 orthm_generator(K1len)]; 28 | end 29 | for i=1:K1 30 | swarm1(i,:)=rc((i*K1len-K1len+1):(i*K1len)); 31 | end 32 | if K2len == 1 33 | orthm2 = []; 34 | else 35 | for i=1:K2 36 | orthm2 = [orthm2 orthm_generator(K2len)]; 37 | end 38 | end 39 | end 40 | for i=1:K2 41 | swarm2(i,:)=rc((K1*K1len+i*K2len-K2len+1):(K1*K1len+i*K2len)); 42 | end 43 | 44 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 45 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 46 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 47 | c1 = 1.49445; c2 = 1.49445; 48 | w_max = 0.9; w_min = 0.4; 49 | [bst ind]=min(fit_func({f},x)); 50 | gbest = x(ind,:); gbest(end+1) = bst; 51 | pbest = x; %initialize Best Particle Position 52 | gbest_hist = []; fe_hist=[]; 53 | % ======================== 54 | % initilise Q Swarm parameters 55 | % ======================== 56 | x1 = Lb+(Ub-Lb).*rand(nop,dim); % initialize position 57 | spd1 = Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 58 | x1(:,end+1)=0; 59 | for i=1:nop 60 | x1(i,end) = fit_func({f},x1(i,1:end-1)); 61 | end 62 | pbest1 = x1; %initialise Best Particle Position 63 | [bst ind] = min(x1(:,end)); 64 | gbest1 = x1(ind,:); % initialise global best position 65 | fe =0;i=1; 66 | while i<=endgen && fe<=max_fe 67 | w = w_max-(w_max-w_min)*i/endgen; 68 | if mod(i,2) == 1 69 | if K1 == 0 70 | for ii=1:K2 71 | for k=1:nop 72 | if fit_func({f},b(gbest(1:end-1),swarm2(ii,:),x(k,swarm2(ii,:)))) <... 73 | fit_func({f},b(gbest(1:end-1),swarm2(ii,:),pbest(k,swarm2(ii,:)))) 74 | pbest(k,swarm2(ii,:)) = x(k,swarm2(ii,:)); 75 | end 76 | if fit_func({f},b(gbest(1:end-1),swarm2(ii,:),pbest(k,swarm2(ii,:)))) < gbest(end) 77 | gbest(swarm2(ii,:)) = pbest(k,swarm2(ii,:)); 78 | gbest(end)=fit_func({f},gbest(1:end-1)); 79 | end 80 | end 81 | spd(:,swarm2(ii,:)) = w.* spd(:,swarm2(ii,:))... 82 | +c1.*rand(nop,K2len).*(pbest(:,swarm2(ii,:))-x(:,swarm2(ii,:)))... 83 | +c2.*rand(nop,K2len).*(repmat(gbest(swarm2(ii,:)),nop,1)-x(:,swarm2(ii,:))); 84 | spd(:,swarm2(ii,:))=(spd(:,swarm2(ii,:))>Vmax).*Vmax+(spd(:,swarm2(ii,:))<=Vmax).*spd(:,swarm2(ii,:)); 85 | spd(:,swarm2(ii,:))=(spd(:,swarm2(ii,:))<(Vmin)).*(Vmin)+(spd(:,swarm2(ii,:))>=(Vmin)).*spd(:,swarm2(ii,:)); 86 | x(:,swarm2(ii,:)) = x(:,swarm2(ii,:))+spd(:,swarm2(ii,:)); 87 | end 88 | else 89 | for ii=1:K1 90 | for k=1:nop 91 | if fit_func({f},b(gbest(1:end-1),swarm1(ii,:),x(k,swarm1(ii,:)))) <... 92 | fit_func({f},b(gbest(1:end-1),swarm1(ii,:),pbest(k,swarm1(ii,:)))) 93 | pbest(k,swarm1(ii,:)) = x(k,swarm1(ii,:)); 94 | end 95 | if fit_func({f},b(gbest(1:end-1),swarm1(ii,:),pbest(k,swarm1(ii,:)))) < gbest(end) 96 | gbest(swarm1(ii,:)) = pbest(k,swarm1(ii,:)); 97 | gbest(end)=fit_func({f},gbest(1:end-1)); 98 | end 99 | end 100 | spd(:,swarm1(ii,:)) = w.* spd(:,swarm1(ii,:))... 101 | +c1.*rand(nop,K1len).*(pbest(:,swarm1(ii,:))-x(:,swarm1(ii,:)))... 102 | +c2.*rand(nop,K1len).*(repmat(gbest(swarm1(ii,:)),nop,1)-x(:,swarm1(ii,:))); 103 | spd(:,swarm1(ii,:))=(spd(:,swarm1(ii,:))>Vmax).*Vmax+(spd(:,swarm1(ii,:))<=Vmax).*spd(:,swarm1(ii,:)); 104 | spd(:,swarm1(ii,:))=(spd(:,swarm1(ii,:))<(Vmin)).*(Vmin)+(spd(:,swarm1(ii,:))>=(Vmin)).*spd(:,swarm1(ii,:)); 105 | x(:,swarm1(ii,:)) = x(:,swarm1(ii,:))+spd(:,swarm1(ii,:)); 106 | end 107 | for ii=1:K2 108 | for k=1:nop 109 | if fit_func({f},b(gbest(1:end-1),swarm2(ii,:),x(k,swarm2(ii,:)))) <... 110 | fit_func({f},b(gbest(1:end-1),swarm2(ii,:),pbest(k,swarm2(ii,:)))) 111 | pbest(k,swarm2(ii,:)) = x(k,swarm2(ii,:)); 112 | end 113 | if fit_func({f},b(gbest(1:end-1),swarm2(ii,:),pbest(k,swarm2(ii,:)))) < gbest(end) 114 | gbest(swarm2(ii,:)) = pbest(k,swarm2(ii,:)); 115 | gbest(end)=fit_func({f},gbest(1:end-1)); 116 | end 117 | end 118 | spd(:,swarm2(ii,:)) = w.* spd(:,swarm2(ii,:))... 119 | +c1.*rand(nop,K2len).*(pbest(:,swarm2(ii,:))-x(:,swarm2(ii,:)))... 120 | +c2.*rand(nop,K2len).*(repmat(gbest(swarm2(ii,:)),nop,1)-x(:,swarm2(ii,:))); 121 | spd(:,swarm2(ii,:))=(spd(:,swarm2(ii,:))>Vmax).*Vmax+(spd(:,swarm2(ii,:))<=Vmax).*spd(:,swarm2(ii,:)); 122 | spd(:,swarm2(ii,:))=(spd(:,swarm2(ii,:))<(Vmin)).*(Vmin)+(spd(:,swarm2(ii,:))>=(Vmin)).*spd(:,swarm2(ii,:)); 123 | x(:,swarm2(ii,:)) = x(:,swarm2(ii,:))+spd(:,swarm2(ii,:)); 124 | end 125 | end 126 | fe = fe + swarmNum*nop; 127 | rc=randperm(round(nop/2)); ind=rc(1); 128 | if x1(ind,end) == gbest1(end) 129 | ind=rc(2); 130 | end 131 | x1(ind,:) = gbest; 132 | else 133 | % Q SWARM 134 | for j=1:nop 135 | if (x1(j,end) < pbest1(j,end)) 136 | pbest1(j,:) = x1(j,:); 137 | end 138 | if (pbest1(j,end) < gbest1(end)) 139 | gbest1 = pbest1(j,:); 140 | end 141 | end 142 | spd1 = w.* spd1+c1.*rand(nop,dim).*(pbest1(:,1:end-1)-x1(:,1:end-1))... 143 | +c2.*rand(nop,dim).*(repmat(gbest1(1:end-1),nop,1) - x1(:,1:end-1)); 144 | spd1=(spd1>Vmax).*Vmax+(spd1<=Vmax).*spd1; 145 | spd1=(spd1<(Vmin)).*(Vmin)+(spd1>=(Vmin)).*spd1; 146 | x1(:,1:end-1) = x1(:,1:end-1)+spd1; 147 | x1(:,end) = fit_func({f},x1(:,1:end-1)); 148 | fe = fe+nop; 149 | % ==== Interval THREE ==== 150 | if K1 == 0 151 | for ii=1:K2 152 | rc=randperm(round(nop/2)); ind=rc(1); 153 | if x(ind,swarm2(ii,:)) == gbest(swarm2(ii,:)) 154 | ind=rc(2); 155 | end 156 | x(ind,swarm2(ii,:)) = gbest1(swarm2(ii,:)); 157 | end 158 | else 159 | for ii=1:K1 160 | rc=randperm(round(nop/2)); ind=rc(1); 161 | if x(ind,swarm1(ii,:)) == gbest(swarm1(ii,:)) 162 | ind=rc(2); 163 | end 164 | x(ind,swarm1(ii,:)) = gbest1(swarm1(ii,:)); 165 | end 166 | for ii=1:K2 167 | rc=randperm(round(nop/2)); ind=rc(1); 168 | if x(ind,swarm2(ii,:)) == gbest(swarm2(ii,:)) 169 | ind=rc(2); 170 | end 171 | x(ind,swarm2(ii,:)) = gbest1(swarm2(ii,:)); 172 | end 173 | end 174 | end 175 | gbest_hist = [gbest_hist gbest(end)]; fe_hist = [fe_hist fe]; 176 | if mod(i,00)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 177 | if ((i>1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0),break,end 178 | i=i+1; 179 | end 180 | end -------------------------------------------------------------------------------- /TEC2006_RotatedFunc/rcpsoh.m: -------------------------------------------------------------------------------- 1 | % Randomized CPSO-H 2 | function [gbest_hist fe_hist] = rcpsoh(f,nop,dim,swarmNum) 3 | % clear,clc 4 | % f= 9;nop = 10;dim=10;swarmNum=3; 5 | endgen = 10^4; % maximum Generation 6 | if dim == 10, max_fe = 3*10^4; end 7 | if dim == 30, max_fe = 3*10^5; end 8 | 9 | global orthm1 orthm2 swarm1 swarm2 K1 K2 K1len K2len s 10 | if f == 9; Ub = 32.768; end % Rotated Ackley 11 | if f == 10; Ub = 600; end % Rotated Griewank 12 | if f == 11; Ub = 0.5; end % Rotated Weierstrass 13 | if f == 12; Ub = 5.12; end % Rotated Rastrigin 14 | if f == 13; Ub = 5.12; end % Rotated Rastrigin_noncont 15 | if f == 14; Ub = 500; end % Rotated Schewfel 16 | % ================= Rotation ======================= 17 | s = swarmNum; 18 | K1 = mod(dim,swarmNum); K1len = ceil(dim/swarmNum); orthm1 = []; 19 | K2 = swarmNum - K1; K2len = floor((dim/swarmNum)); orthm2 = []; 20 | % define rotation 21 | K1 = mod(dim,swarmNum); K1len = ceil(dim/swarmNum); orthm1 = []; 22 | K2 = swarmNum - K1; K2len = floor((dim/swarmNum)); orthm2 = []; 23 | % ========================= 24 | rc=1:dim;swarm1=[]; swarm2=[]; 25 | if K1 == 0 26 | for i=1:K2 27 | orthm2 = [orthm2 orthm_generator(K2len)]; 28 | end 29 | else 30 | for i=1:K1 31 | orthm1 = [orthm1 orthm_generator(K1len)]; 32 | end 33 | for i=1:K1 34 | swarm1(i,:)=rc((i*K1len-K1len+1):(i*K1len)); 35 | end 36 | if K2len == 1 37 | orthm2 = []; 38 | else 39 | for i=1:K2 40 | orthm2 = [orthm2 orthm_generator(K2len)]; 41 | end 42 | end 43 | end 44 | for i=1:K2 45 | swarm2(i,:)=rc((K1*K1len+i*K2len-K2len+1):(K1*K1len+i*K2len)); 46 | end 47 | % randomized swarm members 48 | rc=randperm(dim);swarm11=[]; swarm22=[]; 49 | if K1 ~= 0 50 | for i=1:K1 51 | swarm11(i,:)=rc((i*K1len-K1len+1):(i*K1len)); 52 | end 53 | end 54 | for i=1:K2 55 | swarm22(i,:)=rc((K1*K1len+i*K2len-K2len+1):(K1*K1len+i*K2len)); 56 | end 57 | 58 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 59 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 60 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 61 | c1 = 1.49445; c2 = 1.49445; 62 | w_max = 0.9; w_min = 0.4; 63 | [bst ind]=min(fit_func({f},x)); 64 | gbest = x(ind,:); gbest(end+1) = bst; 65 | pbest = x; %initialize Best Particle Position 66 | gbest_hist = []; fe_hist=[]; 67 | % ======================== 68 | % initilise Q Swarm parameters 69 | % ======================== 70 | x1 = Lb+(Ub-Lb).*rand(nop,dim); % initialize position 71 | spd1 = Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 72 | x1(:,end+1)=0; 73 | for i=1:nop 74 | x1(i,end) = fit_func({f},x1(i,1:end-1)); 75 | end 76 | pbest1 = x1; %initialise Best Particle Position 77 | [bst ind] = min(x1(:,end)); 78 | gbest1 = x1(ind,:); % initialise global best position 79 | fe =0;i=1; 80 | while i<=endgen && fe<=max_fe 81 | w = w_max-(w_max-w_min)*i/endgen; 82 | if mod(i,2) == 1 83 | if K1 == 0 84 | for ii=1:K2 85 | for k=1:nop 86 | if fit_func({f},b(gbest(1:end-1),swarm22(ii,:),x(k,swarm22(ii,:)))) <... 87 | fit_func({f},b(gbest(1:end-1),swarm22(ii,:),pbest(k,swarm22(ii,:)))) 88 | pbest(k,swarm22(ii,:)) = x(k,swarm22(ii,:)); 89 | end 90 | if fit_func({f},b(gbest(1:end-1),swarm22(ii,:),pbest(k,swarm22(ii,:)))) < gbest(end) 91 | gbest(swarm22(ii,:)) = pbest(k,swarm22(ii,:)); 92 | gbest(end)=fit_func({f},gbest(1:end-1)); 93 | end 94 | end 95 | spd(:,swarm22(ii,:)) = w.* spd(:,swarm22(ii,:))... 96 | +c1.*rand(nop,K2len).*(pbest(:,swarm22(ii,:))-x(:,swarm22(ii,:)))... 97 | +c2.*rand(nop,K2len).*(repmat(gbest(swarm22(ii,:)),nop,1)-x(:,swarm22(ii,:))); 98 | spd(:,swarm22(ii,:))=(spd(:,swarm22(ii,:))>Vmax).*Vmax+(spd(:,swarm22(ii,:))<=Vmax).*spd(:,swarm22(ii,:)); 99 | spd(:,swarm22(ii,:))=(spd(:,swarm22(ii,:))<(Vmin)).*(Vmin)+(spd(:,swarm22(ii,:))>=(Vmin)).*spd(:,swarm22(ii,:)); 100 | x(:,swarm22(ii,:)) = x(:,swarm22(ii,:))+spd(:,swarm22(ii,:)); 101 | end 102 | else 103 | for ii=1:K1 104 | for k=1:nop 105 | if fit_func({f},b(gbest(1:end-1),swarm11(ii,:),x(k,swarm11(ii,:)))) <... 106 | fit_func({f},b(gbest(1:end-1),swarm11(ii,:),pbest(k,swarm11(ii,:)))) 107 | pbest(k,swarm11(ii,:)) = x(k,swarm11(ii,:)); 108 | end 109 | if fit_func({f},b(gbest(1:end-1),swarm11(ii,:),pbest(k,swarm11(ii,:)))) < gbest(end) 110 | gbest(swarm11(ii,:)) = pbest(k,swarm11(ii,:)); 111 | gbest(end)=fit_func({f},gbest(1:end-1)); 112 | end 113 | end 114 | spd(:,swarm11(ii,:)) = w.* spd(:,swarm11(ii,:))... 115 | +c1.*rand(nop,K1len).*(pbest(:,swarm11(ii,:))-x(:,swarm11(ii,:)))... 116 | +c2.*rand(nop,K1len).*(repmat(gbest(swarm11(ii,:)),nop,1)-x(:,swarm11(ii,:))); 117 | spd(:,swarm11(ii,:))=(spd(:,swarm11(ii,:))>Vmax).*Vmax+(spd(:,swarm11(ii,:))<=Vmax).*spd(:,swarm11(ii,:)); 118 | spd(:,swarm11(ii,:))=(spd(:,swarm11(ii,:))<(Vmin)).*(Vmin)+(spd(:,swarm11(ii,:))>=(Vmin)).*spd(:,swarm11(ii,:)); 119 | x(:,swarm11(ii,:)) = x(:,swarm11(ii,:))+spd(:,swarm11(ii,:)); 120 | end 121 | for ii=1:K2 122 | for k=1:nop 123 | if fit_func({f},b(gbest(1:end-1),swarm22(ii,:),x(k,swarm22(ii,:)))) <... 124 | fit_func({f},b(gbest(1:end-1),swarm22(ii,:),pbest(k,swarm22(ii,:)))) 125 | pbest(k,swarm22(ii,:)) = x(k,swarm22(ii,:)); 126 | end 127 | if fit_func({f},b(gbest(1:end-1),swarm22(ii,:),pbest(k,swarm22(ii,:)))) < gbest(end) 128 | gbest(swarm22(ii,:)) = pbest(k,swarm22(ii,:)); 129 | gbest(end)=fit_func({f},gbest(1:end-1)); 130 | end 131 | end 132 | spd(:,swarm22(ii,:)) = w.* spd(:,swarm22(ii,:))... 133 | +c1.*rand(nop,K2len).*(pbest(:,swarm22(ii,:))-x(:,swarm22(ii,:)))... 134 | +c2.*rand(nop,K2len).*(repmat(gbest(swarm22(ii,:)),nop,1)-x(:,swarm22(ii,:))); 135 | spd(:,swarm22(ii,:))=(spd(:,swarm22(ii,:))>Vmax).*Vmax+(spd(:,swarm22(ii,:))<=Vmax).*spd(:,swarm22(ii,:)); 136 | spd(:,swarm22(ii,:))=(spd(:,swarm22(ii,:))<(Vmin)).*(Vmin)+(spd(:,swarm22(ii,:))>=(Vmin)).*spd(:,swarm22(ii,:)); 137 | x(:,swarm22(ii,:)) = x(:,swarm22(ii,:))+spd(:,swarm22(ii,:)); 138 | end 139 | end 140 | fe = fe + swarmNum*nop; 141 | rc=randperm(round(nop/2)); ind=rc(1); 142 | if x1(ind,end) == gbest1(end) 143 | ind=rc(2); 144 | end 145 | x1(ind,:) = gbest; 146 | else 147 | % Q SWARM 148 | for j=1:nop 149 | if (x1(j,end) < pbest1(j,end)) 150 | pbest1(j,:) = x1(j,:); 151 | end 152 | if (pbest1(j,end) < gbest1(end)) 153 | gbest1 = pbest1(j,:); 154 | end 155 | end 156 | spd1 = w.* spd1+c1.*rand(nop,dim).*(pbest1(:,1:end-1)-x1(:,1:end-1))... 157 | +c2.*rand(nop,dim).*(repmat(gbest1(1:end-1),nop,1) - x1(:,1:end-1)); 158 | spd1=(spd1>Vmax).*Vmax+(spd1<=Vmax).*spd1; 159 | spd1=(spd1<(Vmin)).*(Vmin)+(spd1>=(Vmin)).*spd1; 160 | x1(:,1:end-1) = x1(:,1:end-1)+spd1; 161 | x1(:,end) = fit_func({f},x1(:,1:end-1)); 162 | fe = fe+nop; 163 | % ==== Interval THREE ==== 164 | if K1 == 0 165 | for ii=1:K2 166 | rc=randperm(round(nop/2)); ind=rc(1); 167 | if x(ind,swarm22(ii,:)) == gbest(swarm22(ii,:)) 168 | ind=rc(2); 169 | end 170 | x(ind,swarm22(ii,:)) = gbest1(swarm22(ii,:)); 171 | end 172 | else 173 | for ii=1:K1 174 | rc=randperm(round(nop/2)); ind=rc(1); 175 | if x(ind,swarm11(ii,:)) == gbest(swarm11(ii,:)) 176 | ind=rc(2); 177 | end 178 | x(ind,swarm11(ii,:)) = gbest1(swarm11(ii,:)); 179 | end 180 | for ii=1:K2 181 | rc=randperm(round(nop/2)); ind=rc(1); 182 | if x(ind,swarm22(ii,:)) == gbest(swarm22(ii,:)) 183 | ind=rc(2); 184 | end 185 | x(ind,swarm22(ii,:)) = gbest1(swarm22(ii,:)); 186 | end 187 | end 188 | end 189 | gbest_hist = [gbest_hist gbest(end)]; fe_hist = [fe_hist fe]; 190 | if mod(i,500)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 191 | if ((i>1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0),break,end 192 | i=i+1; 193 | end 194 | end -------------------------------------------------------------------------------- /TEC2009_ACPSO/rcpsoh.m: -------------------------------------------------------------------------------- 1 | % Randomized CPSO-H 2 | function [gbest_hist fe_hist] = rcpsoh(f,nop,dim,swarmNum) 3 | % clear,clc 4 | % f= 10;nop = 30;dim=30;swarmNum=6; 5 | endgen = 10^4; % maximum Generation 6 | max_fe = 3*10^5; % current fitness evaluation 7 | global initial_flag 8 | initial_flag = 0; 9 | if f == 1; Bounds=[-100,100]; f_bias=-450;end 10 | if f == 2; Bounds=[-100,100]; f_bias=-450;end 11 | if f == 3; Bounds=[-100,100]; f_bias=-450;end 12 | if f == 4; Bounds=[-100,100]; f_bias=-450;end 13 | if f == 5; Bounds=[-100,100]; f_bias=-310;end 14 | if f == 6; Bounds=[-100,100]; f_bias=+390;end 15 | if f == 7; Bounds=[0,600]; f_bias=-180;end 16 | if f == 8; Bounds=[-32, 32]; f_bias=-140;end 17 | if f == 9; Bounds=[-5,5]; f_bias=-330;end 18 | if f == 10;Bounds=[-5,5]; f_bias=-330;end 19 | if f == 11;Bounds=[-0.5,0.5]; f_bias=+90;end 20 | if f == 12;Bounds=[-100,100]; f_bias=-460;end 21 | if f == 13,Bounds=[-3,1]; f_bias=-130;end 22 | if f == 14;Bounds=[-100,100]; f_bias=-300;end 23 | if f == 15;Bounds=[-5,5]; f_bias= 120;end 24 | if f == 16;Bounds=[-5,5]; f_bias= 120;end 25 | if f == 17;Bounds=[-5,5]; f_bias= 120;end 26 | if f == 18;Bounds=[-5,5]; f_bias=10;end 27 | if f == 19;Bounds=[-5,5]; f_bias=10;end 28 | if f == 20;Bounds=[-5,5]; f_bias=10;end 29 | if f == 21;Bounds=[-5,5]; f_bias=360;end 30 | if f == 22;Bounds=[-5,5]; f_bias=360;end 31 | if f == 23;Bounds=[-5,5]; f_bias=360;end 32 | if f == 24;Bounds=[-5,5]; f_bias=260;end 33 | if f == 25;Bounds=[-2,5]; f_bias=260;end 34 | Ub=Bounds(2); 35 | Lb = -Ub; Vmin = -0.2*(Ub-Lb); Vmax = -Vmin; 36 | spd=Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 37 | x=Lb+(Ub-Lb).*rand(nop,dim); % initialize position 38 | c1 = 1.49445; c2 = 1.49445; 39 | w_max = 0.9; w_min = 0.4; 40 | % ======================================================= 41 | s = swarmNum; 42 | K1 = mod(dim,swarmNum); K1len = ceil(dim/swarmNum); 43 | K2 = swarmNum - K1; K2len = floor((dim/swarmNum)); 44 | % randomized swarm members 45 | rc=randperm(dim);swarm1=[]; swarm2=[]; 46 | if K1 ~= 0 47 | for i=1:K1 48 | swarm1(i,:)=rc((i*K1len-K1len+1):(i*K1len)); 49 | end 50 | end 51 | for i=1:K2 52 | swarm2(i,:)=rc((K1*K1len+i*K2len-K2len+1):(K1*K1len+i*K2len)); 53 | end 54 | 55 | % ======================================================= 56 | pbest = x; %initialize Best Particle Position 57 | gbest_hist = []; % swarm best history 58 | fe_hist = []; 59 | % ===== calculate sbest of each swarm ===== 60 | B=[]; 61 | for i=1:nop 62 | B = [B benchmark_func(x(i,:),f)-f_bias]; 63 | end 64 | [mn ind] = min(B); 65 | gbest = x(ind,:); gbest(end+1) = mn; 66 | % ======================== 67 | % initilise Q Swarm parameters 68 | % ======================== 69 | x1 = Lb+(Ub-Lb).*rand(nop,dim); % initialize position 70 | spd1 = Vmin+2.*Vmax.*rand(nop,dim); % initialize velocity 71 | x1(:,end+1)=0; 72 | for i=1:nop 73 | x1(i,end) = benchmark_func(x1(i,1:end-1),f)-f_bias; 74 | end 75 | pbest1 = x1; %initialise Best Particle Position 76 | [bst ind] = min(x1(:,end)); 77 | gbest1 = x1(ind,:); % initialise global best position 78 | fe =0;i=1; 79 | while i<=endgen && fe<=max_fe 80 | w = w_max-(w_max-w_min)*i/endgen; 81 | if mod(i,2) == 1 82 | if K1 == 0 83 | for ii=1:K2 84 | for k=1:nop 85 | if benchmark_func(b(gbest(1:end-1),swarm2(ii,:),x(k,swarm2(ii,:))),f)-f_bias <... 86 | benchmark_func(b(gbest(1:end-1),swarm2(ii,:),pbest(k,swarm2(ii,:))),f)-f_bias 87 | pbest(k,swarm2(ii,:)) = x(k,swarm2(ii,:)); 88 | end 89 | if benchmark_func(b(gbest(1:end-1),swarm2(ii,:),pbest(k,swarm2(ii,:))),f)-f_bias < gbest(end) 90 | gbest(swarm2(ii,:)) = pbest(k,swarm2(ii,:)); 91 | gbest(end)=benchmark_func(gbest(1:end-1),f)-f_bias; 92 | end 93 | end 94 | spd(:,swarm2(ii,:)) = w.* spd(:,swarm2(ii,:))... 95 | +c1.*rand(nop,K2len).*(pbest(:,swarm2(ii,:))-x(:,swarm2(ii,:)))... 96 | +c2.*rand(nop,K2len).*(repmat(gbest(swarm2(ii,:)),nop,1)-x(:,swarm2(ii,:))); 97 | spd(:,swarm2(ii,:))=(spd(:,swarm2(ii,:))>Vmax).*Vmax+(spd(:,swarm2(ii,:))<=Vmax).*spd(:,swarm2(ii,:)); 98 | spd(:,swarm2(ii,:))=(spd(:,swarm2(ii,:))<(Vmin)).*(Vmin)+(spd(:,swarm2(ii,:))>=(Vmin)).*spd(:,swarm2(ii,:)); 99 | x(:,swarm2(ii,:)) = x(:,swarm2(ii,:))+spd(:,swarm2(ii,:)); 100 | end 101 | else 102 | for ii=1:K1 103 | for k=1:nop 104 | if benchmark_func(b(gbest(1:end-1),swarm1(ii,:),x(k,swarm1(ii,:))),f)-f_bias <... 105 | benchmark_func(b(gbest(1:end-1),swarm1(ii,:),pbest(k,swarm1(ii,:))),f)-f_bias 106 | pbest(k,swarm1(ii,:)) = x(k,swarm1(ii,:)); 107 | end 108 | if benchmark_func(b(gbest(1:end-1),swarm1(ii,:),pbest(k,swarm1(ii,:))),f)-f_bias < gbest(end) 109 | gbest(swarm1(ii,:)) = pbest(k,swarm1(ii,:)); 110 | gbest(end)=benchmark_func(gbest(1:end-1),f)-f_bias; 111 | end 112 | end 113 | spd(:,swarm1(ii,:)) = w.* spd(:,swarm1(ii,:))... 114 | +c1.*rand(nop,K1len).*(pbest(:,swarm1(ii,:))-x(:,swarm1(ii,:)))... 115 | +c2.*rand(nop,K1len).*(repmat(gbest(swarm1(ii,:)),nop,1)-x(:,swarm1(ii,:))); 116 | spd(:,swarm1(ii,:))=(spd(:,swarm1(ii,:))>Vmax).*Vmax+(spd(:,swarm1(ii,:))<=Vmax).*spd(:,swarm1(ii,:)); 117 | spd(:,swarm1(ii,:))=(spd(:,swarm1(ii,:))<(Vmin)).*(Vmin)+(spd(:,swarm1(ii,:))>=(Vmin)).*spd(:,swarm1(ii,:)); 118 | x(:,swarm1(ii,:)) = x(:,swarm1(ii,:))+spd(:,swarm1(ii,:)); 119 | end 120 | for ii=1:K2 121 | for k=1:nop 122 | if benchmark_func(b(gbest(1:end-1),swarm2(ii,:),x(k,swarm2(ii,:))),f)-f_bias <... 123 | benchmark_func(b(gbest(1:end-1),swarm2(ii,:),pbest(k,swarm2(ii,:))),f)-f_bias 124 | pbest(k,swarm2(ii,:)) = x(k,swarm2(ii,:)); 125 | end 126 | if benchmark_func(b(gbest(1:end-1),swarm2(ii,:),pbest(k,swarm2(ii,:))),f)-f_bias < gbest(end) 127 | gbest(swarm2(ii,:)) = pbest(k,swarm2(ii,:)); 128 | gbest(end)=benchmark_func(gbest(1:end-1)); 129 | end 130 | end 131 | spd(:,swarm2(ii,:)) = w.* spd(:,swarm2(ii,:))... 132 | +c1.*rand(nop,K2len).*(pbest(:,swarm2(ii,:))-x(:,swarm2(ii,:)))... 133 | +c2.*rand(nop,K2len).*(repmat(gbest(swarm2(ii,:)),nop,1)-x(:,swarm2(ii,:))); 134 | spd(:,swarm2(ii,:))=(spd(:,swarm2(ii,:))>Vmax).*Vmax+(spd(:,swarm2(ii,:))<=Vmax).*spd(:,swarm2(ii,:)); 135 | spd(:,swarm2(ii,:))=(spd(:,swarm2(ii,:))<(Vmin)).*(Vmin)+(spd(:,swarm2(ii,:))>=(Vmin)).*spd(:,swarm2(ii,:)); 136 | x(:,swarm2(ii,:)) = x(:,swarm2(ii,:))+spd(:,swarm2(ii,:)); 137 | end 138 | end 139 | fe = fe + swarmNum*nop; 140 | rc=randperm(round(nop/2)); ind=rc(1); 141 | if x1(ind,end) == gbest1(end) 142 | ind=rc(2); 143 | end 144 | x1(ind,:) = gbest; 145 | else 146 | % Q SWARM 147 | for j=1:nop 148 | if (x1(j,end) < pbest1(j,end)) 149 | pbest1(j,:) = x1(j,:); 150 | end 151 | if (pbest1(j,end) < gbest1(end)) 152 | gbest1 = pbest1(j,:); 153 | end 154 | end 155 | spd1 = w.* spd1+c1.*rand(nop,dim).*(pbest1(:,1:end-1)-x1(:,1:end-1))... 156 | +c2.*rand(nop,dim).*(repmat(gbest1(1:end-1),nop,1) - x1(:,1:end-1)); 157 | spd1=(spd1>Vmax).*Vmax+(spd1<=Vmax).*spd1; 158 | spd1=(spd1<(Vmin)).*(Vmin)+(spd1>=(Vmin)).*spd1; 159 | x1(:,1:end-1) = x1(:,1:end-1)+spd1; 160 | for jj=1:nop 161 | x1(jj,end) = benchmark_func(x1(jj,1:end-1),f)-f_bias; 162 | end 163 | fe = fe+nop; 164 | % ==== Interval THREE ==== 165 | if K1 == 0 166 | for ii=1:K2 167 | rc=randperm(round(nop/2)); ind=rc(1); 168 | if x(ind,swarm2(ii,:)) == gbest(swarm2(ii,:)) 169 | ind=rc(2); 170 | end 171 | x(ind,swarm2(ii,:)) = gbest1(swarm2(ii,:)); 172 | end 173 | else 174 | for ii=1:K1 175 | rc=randperm(round(nop/2)); ind=rc(1); 176 | if x(ind,swarm1(ii,:)) == gbest(swarm1(ii,:)) 177 | ind=rc(2); 178 | end 179 | x(ind,swarm1(ii,:)) = gbest1(swarm1(ii,:)); 180 | end 181 | for ii=1:K2 182 | rc=randperm(round(nop/2)); ind=rc(1); 183 | if x(ind,swarm2(ii,:)) == gbest(swarm2(ii,:)) 184 | ind=rc(2); 185 | end 186 | x(ind,swarm2(ii,:)) = gbest1(swarm2(ii,:)); 187 | end 188 | end 189 | end 190 | gbest_hist = [gbest_hist gbest(end)]; fe_hist = [fe_hist fe]; 191 | if mod(i,500)==0,fprintf('fun=%u,Gene=%u,Fit_Eval=%u,Gbest=%e\n',f,i,fe,gbest(end)),end 192 | if ((i>1300 && gbest_hist(length(gbest_hist)-500) == gbest(end)) || gbest(end) ==0),break,end 193 | i=i+1; 194 | end 195 | end -------------------------------------------------------------------------------- /CEC2005/benchmark_func.m: -------------------------------------------------------------------------------- 1 | function f=benchmark_func(x,func_num) 2 | global initial_flag 3 | persistent fhd f_bias 4 | 5 | % benchmark_func.m is the main function for 25 test functions, all minimize 6 | % problems 7 | % e.g. f=benchmark_func(x,func_num) 8 | % x is the variable, f is the function value 9 | % func_num is the function num, 10 | 11 | % 25 TEST FUCNTIONS 12 | % Unimodal Functions (5): 13 | % 1. Shifted Sphere Function Bounds[-100,100] f_bias=-450 14 | % 2. Shifted Schwefel's Problem 1.2 Bounds[-100,100] f_bias=-450 15 | % 3. Shifted Rotated High Conditioned Elliptic Function Bounds[-100,100] f_bias=-450 16 | % 4. Shifted Schwefel's Problem 1.2 with Noise in Fitness Bounds[-100,100] f_bias=-450 17 | % 5. Schwefel's Problem 2.6 with Global Optimum on Bounds Bounds[-100,100] f_bias=-310 18 | % 19 | % Multimodal Functions (20): 20 | % Basic Functions (7): 21 | % 6. Shifted Rosenbrock's Function Bounds[-100,100] f_bias=390 22 | % 7. Shifted Rotated Griewank's Function without Bounds Initilization Range [0, 600] f_bias=-180 23 | % 8. Shifted Rotated Ackley's Function with Global Optimum on Bounds Bounds[-32,32] f_bias=-140 24 | % 9. Shifted Rastrigin's Function Bounds[-5,5] f_bias=-330 25 | % 10. Shifted Rotated Rastrigin's Function Bounds[-5,5] f_bias=-330 26 | % 11. Shifted Rotated Weierstrass Function Bounds[-0.5,0.5] f_bias=90 27 | % 12. Schwefel's Problem 2.13 Bounds[-100,100] f_bias=-460 28 | % Expanded Functions (2): 29 | % 13. Expanded Extended Griewank's plus Rosenbrock's Function (F8F2) Bounds[-3,1] f_bias=-130 30 | % 14. Expanded Rotated Extended Scaffe's F6 Bounds[-100,100] f_bias=-300 31 | % Hybrid Composition Functions (11): 32 | % 15. Hybrid Composition Function 1 Bounds[-5,5] f_bias= 120 33 | % 16. Rotated Hybrid Composition Function 1 Bounds[-5,5] f_bias= 120 34 | % 17. Rotated Hybrid Composition Function 1 with Noise in Fitness Bounds[-5,5] f_bias= 120 35 | % 18. Rotated Hybrid Composition Function 2 Bounds[-5,5] f_bias=10 36 | % 19. Rotated Hybrid Composition Function 2 with a Narrow Basin for the Global Optimum Bounds[-5,5]] f_bias=10 37 | % 20. Rotated Hybrid Composition Function 2 with the Global Optimum on the Bounds Bounds[-5,5] f_bias=10 38 | % 21. Rotated Hybrid Composition Function 3 Bounds[-5,5] f_bias=360 39 | % 22. Rotated Hybrid Composition Function 3 with High Condition Number Matrix Bounds[-5,5] f_bias=360 40 | % 23. Non-Continuous Rotated Hybrid Composition Function 3 Bounds[-5,5] f_bias=360 41 | % 24. Rotated Hybrid Composition Function 4 Bounds[-5,5] f_bias=260 42 | % 25. Rotated Hybrid Composition Function 4 without Bounds Intilization Range[-2,5] f_bias=260 43 | % 44 | %J. J. Liang & P. N. Suganthan 2005.Feb 18 45 | 46 | if initial_flag==0 47 | if func_num==1 fhd=str2func('sphere_func'); %[-100,100] 48 | elseif func_num==2 fhd=str2func('schwefel_102'); %[-100,100] 49 | elseif func_num==3 fhd=str2func('high_cond_elliptic_rot_func'); %[-100,100] 50 | elseif func_num==4 fhd=str2func('schwefel_102_noise_func'); %[-100,100] 51 | elseif func_num==5 fhd=str2func('schwefel_206'); %[no bound],initial[-100,100]; 52 | elseif func_num==6 fhd=str2func('rosenbrock_func'); %[-100,100] 53 | elseif func_num==7 fhd=str2func('griewank_rot_func'); %[-600,600] 54 | elseif func_num==8 fhd=str2func('ackley_rot_func'); %[-32,32] 55 | elseif func_num==9 fhd=str2func('rastrigin_func'); %[-5,5] 56 | elseif func_num==10 fhd=str2func('rastrigin_rot_func'); %[-5,5] 57 | elseif func_num==11 fhd=str2func('weierstrass_rot'); %[-0.5,0.5] 58 | elseif func_num==12 fhd=str2func('schwefel_213'); %[-pi,pi] 59 | elseif func_num==13 fhd=str2func('EF8F2_func'); %[-3,1] 60 | elseif func_num==14 fhd=str2func('E_ScafferF6_func'); %[-100,100] 61 | elseif func_num==15 fhd=str2func('hybrid_func1'); %[-5,5] 62 | elseif func_num==16 fhd=str2func('hybrid_rot_func1'); %[-5,5] 63 | elseif func_num==17 fhd=str2func('hybrid_rot_func1_noise'); %[-5,5] 64 | elseif func_num==18 fhd=str2func('hybrid_rot_func2'); %[-5,5] 65 | elseif func_num==19 fhd=str2func('hybrid_rot_func2_narrow'); %[-5,5] 66 | elseif func_num==20 fhd=str2func('hybrid_rot_func2_onbound'); %[-5,5] 67 | elseif func_num==21 fhd=str2func('hybrid_rot_func3'); %[-5,5] 68 | elseif func_num==22 fhd=str2func('hybrid_rot_func3_highcond'); %[-5,5] 69 | elseif func_num==23 fhd=str2func('hybrid_rot_func3_noncont'); %[-5,5] 70 | elseif func_num==24 fhd=str2func('hybrid_rot_func4'); %[-5,5] 71 | elseif func_num==25 fhd=str2func('hybrid_rot_func4'); %[-5,5] 72 | end 73 | load fbias_data; 74 | end 75 | 76 | f=feval(fhd,x)+f_bias(func_num); 77 | 78 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 79 | %%%%%%%%%%%%%Unimodal%%%%%%%%%%%%%%%%%%%%%%%%%%% 80 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 81 | % 1.Shifted Sphere Function 82 | function fit=sphere_func(x) 83 | global initial_flag 84 | persistent o M 85 | [ps,D]=size(x); 86 | if initial_flag==0 87 | load sphere_func_data 88 | if length(o)>=D 89 | o=o(1:D); 90 | else 91 | o=-100+200*rand(1,D); 92 | end 93 | initial_flag=1; 94 | end 95 | x=x-repmat(o,ps,1); 96 | fit=sum(x.^2,2); 97 | 98 | % 2.Shifted Schwefel's Problem 1.2 99 | function f=schwefel_102(x) 100 | global initial_flag 101 | persistent o 102 | [ps,D]=size(x); 103 | if initial_flag==0 104 | load schwefel_102_data 105 | if length(o)>=D 106 | o=o(1:D); 107 | else 108 | o=-100+200*rand(1,D); 109 | end 110 | initial_flag=1; 111 | end 112 | x=x-repmat(o,ps,1); 113 | f=0; 114 | for i=1:D 115 | f=f+sum(x(:,1:i),2).^2; 116 | end 117 | 118 | % 3.Shifted Rotated High Conditioned Elliptic Function 119 | function fit=high_cond_elliptic_rot_func(x) 120 | global initial_flag 121 | persistent o M 122 | [ps,D]=size(x); 123 | if initial_flag==0 124 | load high_cond_elliptic_rot_data 125 | if length(o)>=D 126 | o=o(1:D); 127 | else 128 | o=-100+200*rand(1,D); 129 | end 130 | c=1; 131 | if D==2,load elliptic_M_D2, 132 | elseif D==10,load elliptic_M_D10, 133 | elseif D==30,load elliptic_M_D30, 134 | elseif D==50,load elliptic_M_D50, 135 | else 136 | A=normrnd(0,1,D,D);[M,r]=cGram_Schmidt(A); 137 | end 138 | initial_flag=1; 139 | end 140 | x=x-repmat(o,ps,1); 141 | x=x*M; 142 | a=1e+6; 143 | fit=0; 144 | for i=1:D 145 | fit=fit+a.^((i-1)/(D-1)).*x(:,i).^2; 146 | end 147 | 148 | % 4.Shifted Schwefel's Problem 1.2 with Noise in Fitness 149 | function f=schwefel_102_noise_func(x) 150 | global initial_flag 151 | persistent o 152 | [ps,D]=size(x); 153 | if initial_flag==0 154 | load schwefel_102_data 155 | if length(o)>=D 156 | o=o(1:D); 157 | else 158 | o=-100+200*rand(1,D); 159 | end 160 | initial_flag=1; 161 | end 162 | x=x-repmat(o,ps,1); 163 | f=0; 164 | for i=1:D 165 | f=f+sum(x(:,1:i),2).^2; 166 | end 167 | f=f.*(1+0.0.*abs(normrnd(0,1,ps,1))); 168 | 169 | % 5.Schwefel's Problem 2.6 170 | function f=schwefel_206(x)%after Fletcher and Powell 171 | global initial_flag 172 | persistent A B o 173 | [ps,D]=size(x); 174 | if initial_flag==0 175 | initial_flag=1; 176 | load schwefel_206_data 177 | if length(o)>=D 178 | A=A(1:D,1:D);o=o(1:D); 179 | else 180 | o=-100+200*rand(1,D); 181 | A=round(-100+2*100.*rand(D,D)); 182 | while det(A)==0 183 | A=round(-100+2*100.*rand(D,D)); 184 | end 185 | end 186 | o(1:ceil(D/4))=-100;o(max(floor(0.75*D),1):D)=100; 187 | B=A*o'; 188 | end 189 | for i=1:ps 190 | f(i,1)=max(abs(A*(x(i,:)')-B)); 191 | end 192 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 193 | %%%%%%%%%%%%%Multimodal%%%%%%%%%%%%%%%%%%%%%%%%%%% 194 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 195 | % 6.Shifted Rosenbrock's Function 196 | function f=rosenbrock_func(x) 197 | global initial_flag 198 | persistent o 199 | [ps,D]=size(x); 200 | if initial_flag==0 201 | load rosenbrock_func_data 202 | if length(o)>=D 203 | o=o(1:D); 204 | else 205 | o=-90+180*rand(1,D); 206 | end 207 | initial_flag=1; 208 | end 209 | x=x-repmat(o,ps,1)+1; 210 | f=sum(100.*(x(:,1:D-1).^2-x(:,2:D)).^2+(x(:,1:D-1)-1).^2,2); 211 | 212 | % 7.Shifted Rotated Griewank's Function 213 | function f=griewank_rot_func(x) 214 | global initial_flag 215 | persistent o M 216 | [ps,D]=size(x); 217 | if initial_flag==0 218 | load griewank_func_data 219 | if length(o)>=D 220 | o=o(1:D); 221 | else 222 | o=-600+0*rand(1,D); 223 | end 224 | c=3; 225 | if D==2,load griewank_M_D2, 226 | elseif D==10,load griewank_M_D10, 227 | elseif D==30,load griewank_M_D30, 228 | elseif D==50,load griewank_M_D50, 229 | else 230 | M=rot_matrix(D,c); 231 | M=M.*(1+0.3.*normrnd(0,1,D,D)); 232 | end 233 | o=o(1:D); 234 | initial_flag=1; 235 | end 236 | x=x-repmat(o,ps,1); 237 | x=x*M; 238 | f=1; 239 | for i=1:D 240 | f=f.*cos(x(:,i)./sqrt(i)); 241 | end 242 | f=sum(x.^2,2)./4000-f+1; 243 | 244 | % 8.Shifted Rotated Ackley's Function with Global Optimum on Bounds 245 | function f=ackley_rot_func(x) 246 | global initial_flag 247 | persistent o M 248 | [ps,D]=size(x); 249 | if initial_flag==0 250 | load ackley_func_data 251 | if length(o)>=D 252 | o=o(1:D); 253 | else 254 | o=-30+60*rand(1,D); 255 | end 256 | o(2.*[1:floor(D/2)]-1)=-32; 257 | c=100; 258 | if D==2,load ackley_M_D2,, 259 | elseif D==10,load ackley_M_D10, 260 | elseif D==30,load ackley_M_D30, 261 | elseif D==50,load ackley_M_D50, 262 | else 263 | M=rot_matrix(D,c); 264 | end 265 | initial_flag=1; 266 | end 267 | x=x-repmat(o,ps,1); 268 | x=x*M; 269 | f=sum(x.^2,2); 270 | f=20-20.*exp(-0.2.*sqrt(f./D))-exp(sum(cos(2.*pi.*x),2)./D)+exp(1); 271 | 272 | % 9.Shifted Rastrign's Function 273 | function f=rastrigin_func(x) 274 | global initial_flag 275 | persistent o 276 | [ps,D]=size(x); 277 | if initial_flag==0 278 | load rastrigin_func_data 279 | if length(o)>=D 280 | o=o(1:D); 281 | else 282 | o=-5+10*rand(1,D); 283 | end 284 | initial_flag=1; 285 | end 286 | x=x-repmat(o,ps,1); 287 | f=sum(x.^2-10.*cos(2.*pi.*x)+10,2); 288 | 289 | % 10.Shifted Rotated Rastrign's Function 290 | function f=rastrigin_rot_func(x) 291 | global initial_flag 292 | persistent o M 293 | [ps,D]=size(x); 294 | if initial_flag==0 295 | load rastrigin_func_data 296 | if length(o)>=D 297 | o=o(1:D); 298 | else 299 | o=-5+10*rand(1,D); 300 | end 301 | c=2; 302 | if D==2,load rastrigin_M_D2,, 303 | elseif D==10,load rastrigin_M_D10, 304 | elseif D==30,load rastrigin_M_D30, 305 | elseif D==50,load rastrigin_M_D50, 306 | else 307 | M=rot_matrix(D,c); 308 | end 309 | initial_flag=1; 310 | end 311 | x=x-repmat(o,ps,1); 312 | x=x*M; 313 | f=sum(x.^2-10.*cos(2.*pi.*x)+10,2); 314 | 315 | % 11.Shifted Rotated Weierstrass Function 316 | function [f]=weierstrass_rot(x) 317 | global initial_flag 318 | persistent o M 319 | [ps,D]=size(x); 320 | if initial_flag==0 321 | load weierstrass_data 322 | if length(o)>=D 323 | o=o(1:D); 324 | else 325 | o=-0.5+0.5*rand(1,D); 326 | end 327 | c=5; 328 | if D==2,load weierstrass_M_D2,, 329 | elseif D==10,load weierstrass_M_D10, 330 | elseif D==30,load weierstrass_M_D30, 331 | elseif D==50,load weierstrass_M_D50, 332 | else 333 | M=rot_matrix(D,c); 334 | end 335 | initial_flag=1; 336 | end 337 | x=x-repmat(o,ps,1); 338 | x=x*M; 339 | x=x+0.5; 340 | a = 0.5;%0=D 365 | alpha=alpha(1:D);a=a(1:D,1:D);b=b(1:D,1:D); 366 | else 367 | alpha=-3+6*rand(1,D); 368 | a=round(-100+200.*rand(D,D)); 369 | b=round(-100+200.*rand(D,D)); 370 | end 371 | alpha=repmat(alpha,D,1); 372 | A=sum(a.*sin(alpha)+b.*cos(alpha),2); 373 | end 374 | 375 | for i=1:ps 376 | xx=repmat(x(i,:),D,1); 377 | B=sum(a.*sin(xx)+b.*cos(xx),2); 378 | f(i,1)=sum((A-B).^2,1); 379 | end 380 | 381 | % 13. Expanded Extended Griewank's plus Rosenbrock's Function (F8F2) 382 | function fit=EF8F2_func(x) 383 | %-3,1 384 | global initial_flag 385 | persistent o 386 | [ps,D]=size(x); 387 | if initial_flag==0 388 | load EF8F2_func_data 389 | if length(o)>=D 390 | o=o(1:D); 391 | else 392 | o=-1+1*rand(1,D); 393 | end 394 | initial_flag=1; 395 | end 396 | x=x-repmat(o,ps,1)+1; 397 | fit=0; 398 | for i=1:(D-1) 399 | fit=fit+F8F2(x(:,[i,i+1])); 400 | end 401 | fit=fit+F8F2(x(:,[D,1])); 402 | 403 | function f=F8F2(x) 404 | f2=100.*(x(:,1).^2-x(:,2)).^2+(1-x(:,1)).^2; 405 | f=1+f2.^2./4000-cos(f2); 406 | 407 | % --------------------------------------------------------------- 408 | % 14. Expanded Rotated Extended Scaffer's F6 409 | function f=E_ScafferF6_func(x) 410 | global initial_flag 411 | persistent o M 412 | fhd=str2func('ScafferF6'); 413 | [ps,D]=size(x); 414 | if initial_flag==0 415 | load E_ScafferF6_func_data 416 | if length(o)>=D 417 | o=o(1:D); 418 | else 419 | o=-100+200*rand(1,D); 420 | end 421 | initial_flag=1; 422 | c=3; 423 | if D==2,load E_ScafferF6_M_D2,, 424 | elseif D==10,load E_ScafferF6_M_D10, 425 | elseif D==30,load E_ScafferF6_M_D30, 426 | elseif D==50,load E_ScafferF6_M_D50, 427 | else 428 | M=rot_matrix(D,c); 429 | end 430 | end 431 | x=x-repmat(o,ps,1); 432 | x=x*M; 433 | f=0; 434 | for i=1:(D-1) 435 | f=f+feval(fhd,(x(:,i:i+1))); 436 | end 437 | f=f+feval(fhd,x(:,[D,1])); 438 | 439 | function f=ScafferF6(x) 440 | f=0.5+(sin(sqrt(x(:,1).^2+x(:,2).^2)).^2-0.5)./(1+0.001*(x(:,1).^2+x(:,2).^2)).^2; 441 | %--------------------------------------------------- 442 | % 15.Hybrid Composition Function 1 443 | function fit=hybrid_func1(x) 444 | global initial_flag 445 | persistent fun_num func o sigma lamda bias M 446 | if initial_flag==0 447 | [ps,D]=size(x); 448 | initial_flag=1; 449 | fun_num=10; 450 | load hybrid_func1_data % saved the predefined optima 451 | if length(o(1,:))>=D 452 | o=o(:,1:D); 453 | else 454 | o=-5+10*rand(fun_num,D); 455 | end 456 | func.f1=str2func('frastrigin'); 457 | func.f2=str2func('frastrigin'); 458 | func.f3=str2func('fweierstrass'); 459 | func.f4=str2func('fweierstrass'); 460 | func.f5=str2func('fgriewank'); 461 | func.f6=str2func('fgriewank'); 462 | func.f7=str2func('fackley'); 463 | func.f8=str2func('fackley'); 464 | func.f9=str2func('fsphere'); 465 | func.f10=str2func('fsphere'); 466 | bias=((1:fun_num)-1).*100; 467 | sigma=ones(1,fun_num); 468 | lamda=[1; 1; 10; 10; 5/60; 5/60; 5/32; 5/32; 5/100; 5/100]; 469 | lamda=repmat(lamda,1,D); 470 | for i=1:fun_num 471 | eval(['M.M' int2str(i) '=diag(ones(1,D));']); 472 | end 473 | end 474 | fit=hybrid_composition_func(x,fun_num,func,o,sigma,lamda,bias,M); 475 | %--------------------------------------------------------------------- 476 | % 16.Rotated Hybrid Composition Function 1 477 | function fit=hybrid_rot_func1(x) 478 | global initial_flag 479 | persistent fun_num func o sigma lamda bias M 480 | if initial_flag==0 481 | [ps,D]=size(x); 482 | initial_flag=1; 483 | fun_num=10; 484 | load hybrid_func1_data % saved the predefined optima 485 | if length(o(1,:))>=D 486 | o=o(:,1:D); 487 | else 488 | o=-5+10*rand(fun_num,D); 489 | end 490 | func.f1=str2func('frastrigin'); 491 | func.f2=str2func('frastrigin'); 492 | func.f3=str2func('fweierstrass'); 493 | func.f4=str2func('fweierstrass'); 494 | func.f5=str2func('fgriewank'); 495 | func.f6=str2func('fgriewank'); 496 | func.f7=str2func('fackley'); 497 | func.f8=str2func('fackley'); 498 | func.f9=str2func('fsphere'); 499 | func.f10=str2func('fsphere'); 500 | bias=((1:fun_num)-1).*100; 501 | sigma=ones(1,fun_num); 502 | lamda=[1; 1; 10; 10; 5/60; 5/60; 5/32; 5/32; 5/100; 5/100]; 503 | lamda=repmat(lamda,1,D); 504 | c=[2,2,2,2,2,2,2,2,2,2,2]; 505 | if D==2,load hybrid_func1_M_D2, 506 | elseif D==10,load hybrid_func1_M_D10, 507 | elseif D==30,load hybrid_func1_M_D30, 508 | elseif D==50,load hybrid_func1_M_D50, 509 | else 510 | for i=1:fun_num 511 | eval(['M.M' int2str(i) '=rot_matrix(D,c(i));']); 512 | end 513 | end 514 | end 515 | fit=hybrid_composition_func(x,fun_num,func,o,sigma,lamda,bias,M); 516 | %---------------------------------------------------------------- 517 | % 17. Rotated Hybrid Composition Function 1 with Noise in Fitness 518 | function fit=hybrid_rot_func1_noise(x) 519 | [ps,D]=size(x); 520 | fit=hybrid_rot_func1(x).*(1+0.0.*abs(normrnd(0,1,ps,1))); 521 | %---------------------------------------------------------------- 522 | % 18. Rotated Hybrid Composition Function 2 523 | function fit=hybrid_rot_func2(x) 524 | global initial_flag 525 | persistent fun_num func o sigma lamda bias M 526 | if initial_flag==0 527 | [ps,D]=size(x); 528 | initial_flag=1; 529 | fun_num=10; 530 | load hybrid_func2_data % saved the predefined optima 531 | if length(o(1,:))>=D 532 | o=o(:,1:D); 533 | else 534 | o=-5+10*rand(fun_num,D); 535 | end 536 | o(10,:)=0; 537 | func.f1=str2func('fackley'); 538 | func.f2=str2func('fackley'); 539 | func.f3=str2func('frastrigin'); 540 | func.f4=str2func('frastrigin'); 541 | func.f5=str2func('fsphere'); 542 | func.f6=str2func('fsphere'); 543 | func.f7=str2func('fweierstrass'); 544 | func.f8=str2func('fweierstrass'); 545 | func.f9=str2func('fgriewank'); 546 | func.f10=str2func('fgriewank'); 547 | bias=((1:fun_num)-1).*100; 548 | sigma=[1 2 1.5 1.5 1 1 1.5 1.5 2 2]; 549 | lamda=[2*5/32; 5/32; 2*1; 1; 2*5/100; 5/100; 2*10; 10; 2*5/60; 5/60]; 550 | lamda=repmat(lamda,1,D); 551 | c=[2 3 2 3 2 3 20 30 200 300]; 552 | if D==2,load hybrid_func2_M_D2, 553 | elseif D==10,load hybrid_func2_M_D10, 554 | elseif D==30,load hybrid_func2_M_D30, 555 | elseif D==50,load hybrid_func2_M_D50, 556 | else 557 | for i=1:fun_num 558 | eval(['M.M' int2str(i) '=rot_matrix(D,c(i));']); 559 | end 560 | end 561 | end 562 | fit=hybrid_composition_func(x,fun_num,func,o,sigma,lamda,bias,M); 563 | %---------------------------------------------------------------- 564 | % 19. Rotated Hybrid Composition Function 2 with a Narrow Basin for the Global Optimum 565 | function fit=hybrid_rot_func2_narrow(x) 566 | global initial_flag 567 | persistent fun_num func o sigma lamda bias M 568 | if initial_flag==0 569 | [ps,D]=size(x); 570 | initial_flag=1; 571 | fun_num=10; 572 | load hybrid_func2_data % saved the predefined optima 573 | if length(o(1,:))>=D 574 | o=o(:,1:D); 575 | else 576 | o=-5+10*rand(fun_num,D); 577 | end 578 | o(10,:)=0; 579 | func.f1=str2func('fackley'); 580 | func.f2=str2func('fackley'); 581 | func.f3=str2func('frastrigin'); 582 | func.f4=str2func('frastrigin'); 583 | func.f5=str2func('fsphere'); 584 | func.f6=str2func('fsphere'); 585 | func.f7=str2func('fweierstrass'); 586 | func.f8=str2func('fweierstrass'); 587 | func.f9=str2func('fgriewank'); 588 | func.f10=str2func('fgriewank'); 589 | bias=((1:fun_num)-1).*100; 590 | sigma=[0.1 2 1.5 1.5 1 1 1.5 1.5 2 2]; 591 | lamda=[0.1*5/32; 5/32; 2*1; 1; 2*5/100; 5/100; 2*10; 10; 2*5/60; 5/60]; 592 | lamda=repmat(lamda,1,D); 593 | c=[2 3 2 3 2 3 20 30 200 300]; 594 | if D==2,load hybrid_func2_M_D2, 595 | elseif D==10,load hybrid_func2_M_D10, 596 | elseif D==30,load hybrid_func2_M_D30, 597 | elseif D==50,load hybrid_func2_M_D50, 598 | else 599 | for i=1:fun_num 600 | eval(['M.M' int2str(i) '=rot_matrix(D,c(i));']); 601 | end 602 | end 603 | end 604 | fit=hybrid_composition_func(x,fun_num,func,o,sigma,lamda,bias,M); 605 | %---------------------------------------------------------------- 606 | % 20. Rotated Hybrid Composition Function 2 with the Global Optimum on the Bounds 607 | function fit=hybrid_rot_func2_onbound(x) 608 | global initial_flag 609 | persistent fun_num func o sigma lamda bias M 610 | if initial_flag==0 611 | [ps,D]=size(x); 612 | initial_flag=1; 613 | fun_num=10; 614 | load hybrid_func2_data % saved the predefined optima, 615 | if length(o(1,:))>=D 616 | o=o(:,1:D); 617 | else 618 | o=-5+10*rand(fun_num,D); 619 | end 620 | o(10,:)=0; 621 | o(1,2.*[1:floor(D/2)])=5; 622 | func.f1=str2func('fackley'); 623 | func.f2=str2func('fackley'); 624 | func.f3=str2func('frastrigin'); 625 | func.f4=str2func('frastrigin'); 626 | func.f5=str2func('fsphere'); 627 | func.f6=str2func('fsphere'); 628 | func.f7=str2func('fweierstrass'); 629 | func.f8=str2func('fweierstrass'); 630 | func.f9=str2func('fgriewank'); 631 | func.f10=str2func('fgriewank'); 632 | bias=((1:fun_num)-1).*100; 633 | sigma=[1 2 1.5 1.5 1 1 1.5 1.5 2 2]; 634 | lamda=[2*5/32; 5/32; 2*1; 1; 2*5/100; 5/100; 2*10; 10; 2*5/60; 5/60]; 635 | lamda=repmat(lamda,1,D); 636 | c=[2 3 2 3 2 3 20 30 200 300]; 637 | if D==2,load hybrid_func2_M_D2, 638 | elseif D==10,load hybrid_func2_M_D10, 639 | elseif D==30,load hybrid_func2_M_D30, 640 | elseif D==50,load hybrid_func2_M_D50, 641 | else 642 | for i=1:fun_num 643 | eval(['M.M' int2str(i) '=rot_matrix(D,c(i));']); 644 | end 645 | end 646 | end 647 | fit=hybrid_composition_func(x,fun_num,func,o,sigma,lamda,bias,M); 648 | %------------------------------------------------- 649 | % 21.Rotated Hybrid Composition Function 3 650 | function fit=hybrid_rot_func3(x) 651 | global initial_flag 652 | persistent fun_num func o sigma lamda bias M 653 | if initial_flag==0 654 | [ps,D]=size(x); 655 | initial_flag=1; 656 | fun_num=10; 657 | load hybrid_func3_data % saved the predefined optima, a 10*1000 matrix; 658 | if length(o(1,:))>=D 659 | o=o(:,1:D); 660 | else 661 | o=-5+10*rand(fun_num,D); 662 | end 663 | func.f1=str2func('fE_ScafferF6'); 664 | func.f2=str2func('fE_ScafferF6'); 665 | func.f3=str2func('frastrigin'); 666 | func.f4=str2func('frastrigin'); 667 | func.f5=str2func('fEF8F2'); 668 | func.f6=str2func('fEF8F2'); 669 | func.f7=str2func('fweierstrass'); 670 | func.f8=str2func('fweierstrass'); 671 | func.f9=str2func('fgriewank'); 672 | func.f10=str2func('fgriewank'); 673 | bias=((1:fun_num)-1).*100; 674 | sigma=[1,1,1,1,1,2,2,2,2,2]; 675 | lamda=[5*5/100; 5/100; 5*1; 1; 5*1; 1; 5*10; 10; 5*5/200; 5/200]; 676 | lamda=repmat(lamda,1,D); 677 | c=ones(1,D); 678 | if D==2,load hybrid_func3_M_D2, 679 | elseif D==10,load hybrid_func3_M_D10, 680 | elseif D==30,load hybrid_func3_M_D30, 681 | elseif D==50,load hybrid_func3_M_D50, 682 | else 683 | for i=1:fun_num 684 | A=normrnd(0,1,D,D); 685 | eval(['M.M' int2str(i) '=cGram_Schmidt(A);']) 686 | % eval(['M.M' int2str(i) '=rot_matrix(D,c(i));']); 687 | 688 | end 689 | end 690 | end 691 | fit=hybrid_composition_func(x,fun_num,func,o,sigma,lamda,bias,M); 692 | %----------------------------------------- 693 | % 22. Rotated Hybrid Composition Function 3 with High Condition Number Matrix 694 | function fit=hybrid_rot_func3_highcond(x) 695 | global initial_flag 696 | persistent fun_num func o sigma lamda bias M 697 | if initial_flag==0 698 | [ps,D]=size(x); 699 | initial_flag=1; 700 | fun_num=10; 701 | load hybrid_func3_data % saved the predefined optima, a 10*1000 matrix; 702 | if length(o(1,:))>=D 703 | o=o(:,1:D); 704 | else 705 | o=-5+10*rand(fun_num,D); 706 | end 707 | func.f1=str2func('fE_ScafferF6'); 708 | func.f2=str2func('fE_ScafferF6'); 709 | func.f3=str2func('frastrigin'); 710 | func.f4=str2func('frastrigin'); 711 | func.f5=str2func('fEF8F2'); 712 | func.f6=str2func('fEF8F2'); 713 | func.f7=str2func('fweierstrass'); 714 | func.f8=str2func('fweierstrass'); 715 | func.f9=str2func('fgriewank'); 716 | func.f10=str2func('fgriewank'); 717 | bias=((1:fun_num)-1).*100; 718 | sigma=[1,1,1,1,1,2,2,2,2,2]; 719 | lamda=[5*5/100; 5/100; 5*1; 1; 5*1; 1; 5*10; 10; 5*5/200; 5/200]; 720 | lamda=repmat(lamda,1,D); 721 | c=[10 20 50 100 200 1000 2000 3000 4000 5000]; 722 | if D==2,load hybrid_func3_HM_D2, 723 | elseif D==10,load hybrid_func3_HM_D10, 724 | elseif D==30,load hybrid_func3_HM_D30, 725 | elseif D==50,load hybrid_func3_HM_D50, 726 | else 727 | for i=1:fun_num 728 | eval(['M.M' int2str(i) '=rot_matrix(D,c(i));']); 729 | end 730 | end 731 | end 732 | fit=hybrid_composition_func(x,fun_num,func,o,sigma,lamda,bias,M); 733 | %----------------------------------------- 734 | % 23. Non-Continuous Rotated Hybrid Composition Function 3 735 | function fit=hybrid_rot_func3_noncont(x) 736 | global initial_flag 737 | persistent o 738 | [ps,D]=size(x); 739 | if initial_flag==0 740 | load hybrid_func3_data % saved the predefined optima, a 10*1000 matrix; 741 | o=o(1,1:D); 742 | end 743 | o=repmat(o,ps,1); 744 | x=(abs(x-o)<0.5).*x+(abs(x-o)>=0.5).*(round(x.*2)./2); 745 | fit=hybrid_rot_func3(x); 746 | %----------------------------------------- 747 | % 24. Rotated Hybrid Composition Function 4 748 | function fit=hybrid_rot_func4(x) 749 | global initial_flag 750 | persistent fun_num func o sigma lamda bias M 751 | if initial_flag==0 752 | [ps,D]=size(x); 753 | initial_flag=1; 754 | fun_num=10; 755 | load hybrid_func4_data % saved the predefined optima, a 10*1000 matrix; 756 | if length(o(1,:))>=D 757 | o=o(:,1:D); 758 | else 759 | o=-5+10*rand(fun_num,D); 760 | end 761 | func.f1=str2func('fweierstrass'); 762 | func.f2=str2func('fE_ScafferF6'); 763 | func.f3=str2func('fEF8F2'); 764 | func.f4=str2func('fackley'); 765 | func.f5=str2func('frastrigin'); 766 | func.f6=str2func('fgriewank'); 767 | func.f7=str2func('fE_ScafferF6_noncont'); 768 | func.f8=str2func('frastrigin_noncont'); 769 | func.f9=str2func('felliptic'); 770 | func.f10=str2func('fsphere_noise'); 771 | bias=((1:fun_num)-1).*100; 772 | sigma=[2,2,2,2,2,2,2,2,2,2]; 773 | lamda=[10; 5/20; 1; 5/32; 1; 5/100 ; 5/50; 1; 5/100; 5/100; ]; 774 | lamda=repmat(lamda,1,D); 775 | c=[100 50 30 10 5 5 4 3 2 2]; 776 | if D==2,load hybrid_func4_M_D2, 777 | elseif D==10,load hybrid_func4_M_D10, 778 | elseif D==30,load hybrid_func4_M_D30, 779 | elseif D==50,load hybrid_func4_M_D50, 780 | else 781 | for i=1:fun_num 782 | eval(['M.M' int2str(i) '=rot_matrix(D,c(i));']); 783 | end 784 | end 785 | end 786 | fit=hybrid_composition_func(x,fun_num,func,o,sigma,lamda,bias,M); 787 | %---------------------------------- 788 | function fit=hybrid_composition_func(x,fun_num,func,o,sigma,lamda,bias,M) 789 | [ps,D]=size(x); 790 | for i=1:fun_num 791 | oo=repmat(o(i,:),ps,1); 792 | weight(:,i)=exp(-sum((x-oo).^2,2)./2./(D*sigma(i)^2)); 793 | end 794 | 795 | [tmp,tmpid]=sort(weight,2); 796 | for i=1:ps 797 | weight(i,:)=(weight(i,:)==tmp(i,fun_num)).*weight(i,:)+(weight(i,:)~=tmp(i,fun_num)).*(weight(i,:).*(1-tmp(i,fun_num).^10)); 798 | end 799 | weight=weight./repmat(sum(weight,2),1,fun_num); 800 | 801 | fit=0; 802 | for i=1:fun_num 803 | oo=repmat(o(i,:),ps,1); 804 | eval(['f=feval(func.f' int2str(i) ',((x-oo)./repmat(lamda(i,:),ps,1))*M.M' int2str(i) ');']); 805 | x1=5*ones(1,D); 806 | eval(['f1=feval(func.f' int2str(i) ',(x1./lamda(i,:))*M.M' int2str(i) ');']); 807 | fit1=2000.*f./f1; 808 | fit=fit+weight(:,i).*(fit1+bias(i)); 809 | end 810 | %------------------------------------------------- 811 | %basic functions 812 | 813 | function f=fsphere(x) 814 | %Please notice there is no use to rotate a sphere function, with rotation 815 | %here just for a similar structure as other functions and easy programming 816 | [ps,D]=size(x); 817 | f=sum(x.^2,2); 818 | %-------------------------------- 819 | function f=fsphere_noise(x) 820 | [ps,D]=size(x); 821 | f=sum(x.^2,2).*(1+0.0.*normrnd(0,1,ps,1)); 822 | %-------------------------------- 823 | function f=fgriewank(x) 824 | [ps,D]=size(x); 825 | f=1; 826 | for i=1:D 827 | f=f.*cos(x(:,i)./sqrt(i)); 828 | end 829 | f=sum(x.^2,2)./4000-f+1; 830 | %-------------------------------- 831 | function f=fackley(x) 832 | [ps,D]=size(x); 833 | f=sum(x.^2,2); 834 | f=20-20.*exp(-0.2.*sqrt(f./D))-exp(sum(cos(2.*pi.*x),2)./D)+exp(1); 835 | %-------------------------------- 836 | function f=frastrigin(x) 837 | [ps,D]=size(x); 838 | f=sum(x.^2-10.*cos(2.*pi.*x)+10,2); 839 | %-------------------------------- 840 | function f=frastrigin_noncont(x) 841 | [ps,D]=size(x); 842 | x=(abs(x)<0.5).*x+(abs(x)>=0.5).*(round(x.*2)./2); 843 | f=sum(x.^2-10.*cos(2.*pi.*x)+10,2); 844 | %-------------------------------- 845 | function [f]=fweierstrass(x) 846 | [ps,D]=size(x); 847 | x=x+0.5; 848 | a = 0.5; 849 | b = 3; 850 | kmax = 20; 851 | c1(1:kmax+1) = a.^(0:kmax); 852 | c2(1:kmax+1) = 2*pi*b.^(0:kmax); 853 | f=0; 854 | c=-w(0.5,c1,c2); 855 | for i=1:D 856 | f=f+w(x(:,i)',c1,c2); 857 | end 858 | f=f+c*D; 859 | 860 | function y = w(x,c1,c2) 861 | y = zeros(length(x),1); 862 | for k = 1:length(x) 863 | y(k) = sum(c1 .* cos(c2.*x(:,k))); 864 | end 865 | %-------------------------------- 866 | function f=fE_ScafferF6(x) 867 | fhd=str2func('ScafferF6'); 868 | [ps,D]=size(x); 869 | 870 | f=0; 871 | for i=1:(D-1) 872 | f=f+feval(fhd,(x(:,i:i+1))); 873 | end 874 | f=f+feval(fhd,x(:,[D,1])); 875 | %-------------------------------- 876 | function f=fE_ScafferF6_noncont(x) 877 | fhd=str2func('ScafferF6'); 878 | [ps,D]=size(x); 879 | x=(abs(x)<0.5).*x+(abs(x)>=0.5).*(round(x.*2)./2); 880 | f=0; 881 | for i=1:(D-1) 882 | f=f+feval(fhd,(x(:,i:i+1))); 883 | end 884 | f=f+feval(fhd,x(:,[D,1])); 885 | %------------------------------ 886 | function f=fEF8F2(x) 887 | [ps,D]=size(x); 888 | f=0; 889 | for i=1:(D-1) 890 | f=f+F8F2(x(:,[i,i+1])); 891 | end 892 | f=f+F8F2(x(:,[D,1])); 893 | 894 | %-------------------------------- 895 | function f=fschwefel_102(x) 896 | [ps,D]=size(x); 897 | f=0; 898 | for i=1:D 899 | f=f+sum(x(:,1:i),2).^2; 900 | end 901 | %-------------------------------- 902 | function f=felliptic(x) 903 | [ps,D]=size(x); 904 | a=1e+6; 905 | f=0; 906 | for i=1:D 907 | f=f+a.^((i-1)/(D-1)).*x(:,i).^2; 908 | end 909 | %-------------------------------- 910 | % classical Gram Schmid 911 | function [q,r] = cGram_Schmidt (A) 912 | % computes the QR factorization of $A$ via 913 | % classical Gram Schmid 914 | % 915 | [n,m] = size(A); 916 | q = A; 917 | for j=1:m 918 | for i=1:j-1 919 | r(i,j) = q(:,j)'*q(:,i); 920 | end 921 | for i=1:j-1 922 | q(:,j) = q(:,j) - r(i,j)*q(:,i); 923 | end 924 | t = norm(q(:,j),2 ) ; 925 | q(:,j) = q(:,j) / t ; 926 | r(j,j) = t ; 927 | end 928 | 929 | function M=rot_matrix(D,c) 930 | A=normrnd(0,1,D,D); 931 | P=cGram_Schmidt(A); 932 | A=normrnd(0,1,D,D); 933 | Q=cGram_Schmidt(A); 934 | u=rand(1,D); 935 | D=c.^((u-min(u))./(max(u)-min(u))); 936 | D=diag(D); 937 | M=P*D*Q; --------------------------------------------------------------------------------