Code covered by the BSD License

SSO (Simplified Swarm Optimization) algorithm

Jiing Deng (view profile)

SSO algorithm simple example

sso_simple()
```% -----------------------------------------------------------------
% Simplified Swarm Optimization (SSO) algorithm by Wei-Chang Yeh  %
% Programmed by Jing-Feng Deng at National Tsing Hua University (ROC) %
% Programming dates: May 2013                                     %
% Last revised: May 2013   (simplified version for demo only)     %
% -----------------------------------------------------------------
% Papers -- Citation Details:
% 1) C. Bae, W. C. Yeh, N. Wahid, Y.Y. Chung and Y. Liu,
% A New Simplified Swarm Optimization (SSO) Using Exchange Local Search Scheme,
% Int. J. Innovative Computing, Information and Control,
% Vol. 8, No. 6, 4391-4406 (2012)
% http://www.ijicic.org/ijicic-11-06072.pdf

function sso_simple()
%initialize basic information
clear all
clc
close all
%nargin

Nvar = 20;
Nsol = 150;
Ngen = 100;
Nrun = 30;

Cg   = 0.55;
Cp   = 0.75;
Cw   = 0.95;

genBest= 1;
gBest  = 1;

%initialize stepint
LB   = -5.12;
UB   =  5.12;

X  = zeros(Nsol,Nvar);
pX = zeros(Nsol,Nvar);
F  = zeros(Nsol);
pF = zeros(Nsol);

for run=1:Nrun
start_time = cputime;
%initialize solution
for sol=1:Nsol
%for var=1:Nvar
%   X(sol,var)=rand*(UB-LB)+LB;
%   pX(sol,var) = X(sol,var);
%end
X(sol,:)=rand(1,Nvar).*(UB-LB)+LB;
pX(sol,:)=X(sol,:);
F(sol)=fitness_funtion(X, sol);
pF(sol)=F(sol);
if F(sol) < F(gBest)
gBest = sol;
end
end

for gen=1:Ngen
%update solution
for sol=1:Nsol
for var=1:Nvar
random_number=rand;
if random_number < Cg
X(sol,var)=pX(gBest,var);
elseif random_number< Cp
X(sol,var)=pX(sol,var);
elseif random_number < Cw
continue;
else
X(sol,var)=rand*(UB-LB)+LB;
end
end

F(sol)=fitness_funtion(X, sol);
if F(sol) < pF(sol)
pF(sol) = F(sol);
%for var=1:Nvar
%	  pX(sol,var)=X(sol,var);
%end
pX(sol,:)=X(sol,:);
if F(sol) < pF(gBest)
gBest=sol;
genBest=gen;
end
end
end
subplot( Nrun/5 ,5, run)
plot(gen, pF(gBest),'r-.');
title({['run=',num2str(run), ', gen=',num2str(gen)]...
, ['pF(gBest)=',num2str(pF(gBest))] })
drawnow
hold on
end %end of gen
end_time = cputime;
fprintf('RunTime=%f ',end_time - start_time);
fprintf('BestSol=%f ',pF(gBest) );
fprintf('genBest=%d ', genBest);
fprintf('gBest=%d\n', gBest);
end

function top=fitness_funtion(X, sol)
top=25;
for var=1:size(X,2)
top=top+round(X(sol,var));
end
return

```