Académique Documents
Professionnel Documents
Culture Documents
ver 0.1-7
S. SALMON, Research engineer and PhD. student at M3M - UTBM
Abstract
This document introduces the Particle Swarm Optimization (PSO) in Scilab. The PSO
is a meta-heuristic optimization process created by Kennedy and Eberhart in 1995. Three
PSO are implanted in this toolbox : the "Inertia Weight Model" by Shi & Eberhart in 1998,
the "Radius" and the "BSG-Starcraft" by the author.
Source code is released under CC-BY-NC-SA.
1 Introduction
In order to treat optimization cases, two main optimization families are available (excepted
hybrids methods):
Gradient based methods are non-linear sensitive and so may not converge to a good solution
due to the need of derivative evaluation. Meta-heuristic methods are design to such problem
thanks to only required the direct evaluation of the objective function. In the objective to treat
non-linear problem with a simple optimization process, the Particle Swarm Optimization appears
to be well adapted.
1
vt+1 = vt + R1 .C1 .(g xt ) + R2 .C2 .(p xt )
(1)
xt+1 = xt + vt+1
where C1 and C2 are learning parameters, R1 and R2 are random numbers, g is the location
of the leader and p the personal best location.
This equation reveals the particle leader location to each particle.
the particle leader (the carrier) has the ability to send randomly some new particles to fast
explore the space (raptors);
if one raptor nd a best position than the global best then the swarm jump (FTL jump),
conserving the swarm geometry, to this new location. The carrier location is now the raptor
one.
This improvement is in evaluation stage and could be useful when the swarm is initially long
away from the objective function minimum.
2
6 How to use and comparison on test case
6.1 How to use
The toolbox is available via Atoms in Scilab or from the Scilab forge. Those PSO methods are
designed to be mono-objective. So in order take into account multi-objective systems, the user
has to reduce the size of the objective function output using for example a L2 norm.
First step :
An objective function has to be created in a script.sce le for example:
function f=script(x)
f=60+sum((x.^2)-10*cos(2*%pi.*x)); // Rastrigins function R6
endfunction;
Second step :
Create a command le to step up the PSO chosen and execute the le:
clear
lines(0)
//executing PSO
3
6.2.1 Rastrigins function:
The Rastrigins function is dened by (Eq. 3):
n
[ ]
f (x) = 10n + x2i 10cos (2xi ) (3)
i=1
The solution is located in zero of n and the function value is also zero. The test case is a
20 dimension problem, PSO parameters are dened in Table 1 and results in Table 2:
The solution is located in zero of n and the function value is also zero. The test case is a
20 dimension problem, PSO parameters are dened in Table 3 and results in Table 4:
4
Inertial Radius BSG-Starcraft BSG-Starcraft radius
Mean Final value 5.97 9.14 1.56 1.39
Mean Iteration 800 493.6 800 527.3
a = 30
b = 0.2
c = 2
v (5)
u n ( n )
u1 1
f (x) = a. exp bt x2 exp cos(cxi ) + a + exp(1)
n i=1 i n i=1
The solution is located in zero of n and the function value is also zero. The test case is a
20 dimension problem, PSO parameters are dened in Table 5 and results in Table 6:
The solution is located in zero of 2 and the function value is 1. The test case is a 20
dimension problem, PSO parameters are dened in Table 7 and results in Table 8:
5
Parameter limits Value
location inf. 2 -5.12
location sup. 2 5.12
speed inf. 2 -0.512
speed sup. 2 0.512
radius 1e-3
max. iteration 800
particle number 20
6
Mean Final value Inertia weight Model BSG-Starcraft
Case 1 12.92 13.39
Case 2 4462.29 1458.38
We can notice that the BSG-Starcraft model is at least as eective as the inertial PSO for
small range swarms and really eective in case of high range swarms (Table 11).
7 Conclusion
The Particle Swarm Optimization as been used in many optimization cases both in linear and
non-linear problems. This optimization process appears to be eective and simple to use. Both
proposed improvements are also eective and may be combined to create a new PSO model.
Appendix
Inertial PSO
function PSO_inertial(objective,wmax,wmin,itmax,c1,c2,N,D,borne_sup,borne_inf,vitesse_min,vitesse_max)
lines(0)
//---------------------------------------------------
// Setting up graphics axis
//---------------------------------------------------
scf(1)
gcf()
xtitle("Objective function value vs Iteration")
axe_prop=gca()
axe_prop.x_label.text="Iteration number"
axe_prop.y_label.text="Objective function value"
//---------------------------------------------------
// Declaring objective function
//---------------------------------------------------
var=objective+.sce;
exec(var)
//---------------------------------------------------
// PSO parameters definition
//---------------------------------------------------
7
// max iteration allowed
//itmax=800; //Maximum iteration number
// knowledge factors
//c1=2; // for personnal best
//c2=2; // for global best
// problem dimensions
//N=20; // number of particles
//D=6; // problem dimension
//---------------------------------------------------
// Allocation of memory ans first computations
//---------------------------------------------------
for i=1:D
//borne_sup(i)= 1;
//borne_inf(i)= 0;
x(1:N,i) =borne_inf(i) +rand(N,1) * ( borne_sup(i) - borne_inf(i) ); // location
//vitesse_min(i)=-0.3;
//vitesse_max(i)=0.3;
v(1:N,i)=vitesse_min(i)+(vitesse_max(i)-vitesse_min(i))*rand(N,1); // speed
end
//---------------------------------------------------
// First evaluation of the objective function
//---------------------------------------------------
for i=1:N
y=x(i,:,j);
F(i,1,j)=script(y); // mono-objective result
end
//---------------------------------------------------
// Search for the minimum of the swarm
//---------------------------------------------------
[C,I]=min((F(:,1,j)));
//---------------------------------------------------
// The first minimun is the global minimum cause first
// iteration
//---------------------------------------------------
gbest(1,:,j)=x(I,:,j);
for p=1:N
G(p,:,j)=gbest(1,:,j); // creating a matrix of gbest, used for speed computation
end
//---------------------------------------------------
// The first minimun is the best result cause first
8
// iteration
//---------------------------------------------------
Fbest(1,1,j)=F(I,1,j); // global best
Fb(1,1,j)=F(I,1,j); // iteration best, used for comparison with global best
//---------------------------------------------------
// Each particle is her personnal best cause first
// first iteration
//---------------------------------------------------
for i=1:N
pbest(i,:,j)=x(i,:,j);
end
//---------------------------------------------------
// Speed and location computation for next iteration
//---------------------------------------------------
v(:,:,j+1)=W(j)*v(:,:,j)+c1*rand()*(pbest(:,:,j)-x(:,:,j))+c2*rand()*(G(:,:,j)-x(:,:,j)); // speed
x(:,:,j+1)=x(:,:,j)+v(:,:,j+1); // location
//---------------------------------------------------
// Entering to the optimization loop
//---------------------------------------------------
while (j<itmax-1)
j=j+1
//---------------------------------------------------
// First evaluation of the objective function
//---------------------------------------------------
for i=1:N
y=x(i,:,j);
F(i,1,j)=script(y);
end
//---------------------------------------------------
// Search for the minimum of the swarm
//---------------------------------------------------
[C,I]=min((F(:,:,j)));
//---------------------------------------------------
// Searching for global minimum
//---------------------------------------------------
gbest(1,:,j)=x(I,:,j); // hypothesis : this iteration is better than last one
Fb(1,1,j)=F(I,1,j); // looking for the iteration best result
Fbest(1,:,j)=Fb(1,:,j); // Fbest is the iteration best result
for p=1:N
G(p,:,j)=gbest(1,:,j); // creating a matrix of gbest, used for speed computation
end
//---------------------------------------------------
// Computation of the new personnal best
//---------------------------------------------------
for i=1:N
[C,I]=min(F(i,1,:));
9
if F(i,1,j)<C
pbest(i,:,j)=x(i,:,j);
else
pbest(i,:,j)=x(i,:,I(3));
end
end
//---------------------------------------------------
// Re-computation of Fbest for reliability test
//---------------------------------------------------
y=gbest(1,:,j);
Fbest(:,:,j)=script(y);
//---------------------------------------------------
// Speed and location computation for next iteration
//---------------------------------------------------
v(:,:,j+1)=W(j)*v(:,:,j)+c1*rand()*(pbest(:,:,j)-x(:,:,j))+c2*rand()*(G(:,:,j)-x(:,:,j)); // speed
x(:,:,j+1)=x(:,:,j)+v(:,:,j+1); // location
//---------------------------------------------------
// Plotting the Fbest curve to monitor optimization
//---------------------------------------------------
for count=1:j
Fbest_draw(count)=Fbest(1,1,count);
end
clf(1)
scf(1)
gcf()
xtitle("Objective function value vs Iteration")
axe_prop=gca()
axe_prop.x_label.text="Iteration number"
axe_prop.y_label.text="Objective function value"
else
scf(1)
end
plot(Fbest_draw)
drawnow()
//---------------------------------------------------
// Temporary save in case of crash, very usefull for long time optimization
//---------------------------------------------------
save (PSO_temp)
//---------------------------------------------------
// Out of the optimization loop
//---------------------------------------------------
end
disp(Fbest : + string(Fbest(:,:,j)))
disp(Gbest : + string(gbest(:,:,j)))
10
save(results_PSO)
endfunction
Radius PSO
function PSO_inertial_radius(objective,wmax,wmin,itmax,c1,c2,N,D,borne_sup,borne_inf,vitesse_min,vitesse_max,radius)
lines(0)
//---------------------------------------------------
// Setting up graphics axis
//---------------------------------------------------
scf(1)
gcf()
xtitle("Objective function value vs Iteration")
axe_prop=gca()
axe_prop.x_label.text="Iteration number"
axe_prop.y_label.text="Objective function value"
scf(2)
gcf()
xtitle("Swarm radius vs Iteration")
axe_prop=gca()
axe_prop.x_label.text="Iteration number"
axe_prop.y_label.text="Swarm radius (log10)"
//---------------------------------------------------
// Declaring objective function
//---------------------------------------------------
var=objective+.sce;
exec(var)
//---------------------------------------------------
// PSO parameters definition
//---------------------------------------------------
// knowledge factors
11
//c1=2; // for personnal best
//c2=2; // for global best
// problem dimensions
//N=20; // number of particles
//D=6; // problem dimension
//---------------------------------------------------
// Allocation of memory ans first computations
//---------------------------------------------------
for i=1:D
//borne_sup(i)= 1;
//borne_inf(i)= 0;
x(1:N,i) =borne_inf(i) +rand(N,1) * ( borne_sup(i) - borne_inf(i) ); // location
//vitesse_min(i)=-0.3;
//vitesse_max(i)=0.3;
v(1:N,i)=vitesse_min(i)+(vitesse_max(i)-vitesse_min(i))*rand(N,1); // speed
end
//---------------------------------------------------
// First evaluation of the objective function
//---------------------------------------------------
for i=1:N
y=x(i,:,j);
F(i,1,j)=script(y); // mono-objective result
end
//---------------------------------------------------
// Search for the minimum of the swarm
//---------------------------------------------------
[C,I]=min((F(:,1,j)));
//---------------------------------------------------
// The first minimun is the global minimum cause first
// iteration
//---------------------------------------------------
gbest(1,:,j)=x(I,:,j);
for p=1:N
G(p,:,j)=gbest(1,:,j); // creating a matrix of gbest, used for speed computation
end
//---------------------------------------------------
// The first minimun is the best result cause first
12
// iteration
//---------------------------------------------------
Fbest(1,1,j)=F(I,1,j); // global best
Fb(1,1,j)=F(I,1,j); // iteration best, used for comparison with global best
//---------------------------------------------------
// Each particle is her personnal best cause first
// first iteration
//---------------------------------------------------
for i=1:N
pbest(i,:,j)=x(i,:,j);
end
//---------------------------------------------------
// Speed and location computation for next iteration
//---------------------------------------------------
v(:,:,j+1)=W(j)*v(:,:,j)+c1*rand()*(pbest(:,:,j)-x(:,:,j))+c2*rand()*(G(:,:,j)-x(:,:,j)); // speed
x(:,:,j+1)=x(:,:,j)+v(:,:,j+1); // location
//---------------------------------------------------
// Entering to the optimization loop
//---------------------------------------------------
while (j<itmax-1 & mesurability==1)
j=j+1
//---------------------------------------------------
// First evaluation of the objective function
//---------------------------------------------------
for i=1:N
y=x(i,:,j);
F(i,1,j)=script(y);
end
//---------------------------------------------------
// Search for the minimum of the swarm
//---------------------------------------------------
[C,I]=min((F(:,:,j)));
//---------------------------------------------------
// Searching for global minimum
//---------------------------------------------------
gbest(1,:,j)=x(I,:,j); // hypothesis : this iteration is better than last one
Fb(1,1,j)=F(I,1,j); // looking for the iteration best result
Fbest(1,:,j)=Fb(1,:,j); // hypothesis : Fbest is the iteration best result
else
gbest(1,:,j)=gbest(1,:,j-1); // if not then replacing with the good gbest
Fbest(1,:,j)=Fbest(1,:,j-1); // A new Fbest has not be found this time
end
for p=1:N
G(p,:,j)=gbest(1,:,j); // creating a matrix of gbest, used for speed computation
end
//---------------------------------------------------
// Computation of the new personnal best
//---------------------------------------------------
for i=1:N
[C,I]=min(F(i,1,:));
13
if F(i,1,j)<C
pbest(i,:,j)=x(i,:,j);
else
pbest(i,:,j)=x(i,:,I(3));
end
end
//---------------------------------------------------
// Re-computation of Fbest for reliability test
//---------------------------------------------------
y=gbest(1,:,j);
Fbest(:,:,j)=script(y);
//---------------------------------------------------
// Speed and location computation for next iteration
//---------------------------------------------------
v(:,:,j+1)=W(j)*v(:,:,j)+c1*rand()*(pbest(:,:,j)-x(:,:,j))+c2*rand()*(G(:,:,j)-x(:,:,j)); // speed
x(:,:,j+1)=x(:,:,j)+v(:,:,j+1); // location
//---------------------------------------------------
// Computing measurability - generating capacity
//---------------------------------------------------
[C,I]=min((F(:,:,j)));
leader_temp(1,:,j)=x(I,:,j); // getting swarm leader
for t=1:N
dist_temp(:,t,j) = abs((x(t,:,j)-leader_temp(:,:,j))); // computing L1 norm to leader
end
for t=1:N
dist(t,j)=max(dist_temp(:,t,j));
end
max_dist(j)=max(dist(:,j));
counter=counter+1;
end
if counter==10
mesurability=0;
end
rad_plot(j)=radius;
14
scf(2)
end
plot(log10(max_dist(2:j)) )
plot(log10(rad_plot(2:j)),r)
drawnow()
//---------------------------------------------------
// Plotting the Fbest curve to monitor optimization
//---------------------------------------------------
for count=1:j
Fbest_draw(count)=Fbest(1,1,count);
end
clf(1)
scf(1)
gcf()
xtitle("Objective function value vs Iteration")
axe_prop=gca()
axe_prop.x_label.text="Iteration number"
axe_prop.y_label.text="Objective function value"
else
scf(1)
end
plot(Fbest_draw)
drawnow()
//---------------------------------------------------
// Temporary save in case of crash, very usefull for long time optimization
//---------------------------------------------------
save (PSO_temp)
//---------------------------------------------------
// Out of the optimization loop
//---------------------------------------------------
end
disp(Fbest : + string(Fbest(:,:,j)))
disp(Gbest : + string(gbest(:,:,j)))
save(results_PSO_radius)
endfunction
save(results_PSO_radius)
endfunction
BSG-Starcraft PSO
15
// Created by Sebastien Salmon
// M3M - UTBM
// sebastien[.]salmon[@]utbm[.]fr
// 2010
// released under CC-BY-NC-SA
function PSO_bsg_starcraft(objective,wmax,wmin,itmax,c1,c2,N,D,borne_sup,borne_inf,vitesse_min,vitesse_max)
lines(0)
//---------------------------------------------------
// Setting up graphics axis
//---------------------------------------------------
scf(1)
gcf()
xtitle("Objective function value vs Iteration")
axe_prop=gca()
axe_prop.x_label.text="Iteration number"
axe_prop.y_label.text="Objective function value"
//---------------------------------------------------
// Declaring objective function
//---------------------------------------------------
var=objective+.sce;
disp(var)
exec(var)
//---------------------------------------------------
// PSO parameters definition
//---------------------------------------------------
// knowledge factors
//c1=2; // for personnal best
//c2=2; // for global best
// problem dimensions
//N=20; // number of particles
//D=6; // problem dimension
//---------------------------------------------------
// Allocation of memory ans first computations
//---------------------------------------------------
for i=1:D
16
//borne_sup(i)= 1;
//borne_inf(i)= 0;
x(1:N,i) =borne_inf(i) +rand(N,1) * ( borne_sup(i) - borne_inf(i) ); // location
//vitesse_min(i)=-0.3;
//vitesse_max(i)=0.3;
v(1:N,i)=vitesse_min(i)+(vitesse_max(i)-vitesse_min(i))*rand(N,1); // speed
end
//---------------------------------------------------
// First evaluation of the objective function
//---------------------------------------------------
for i=1:N
y=x(i,:,j);
F(i,1,j)=script(y); // mono-objective result
end
//---------------------------------------------------
// Search for the minimum of the swarm
//---------------------------------------------------
[C,I]=min((F(:,1,j)));
//---------------------------------------------------
// The first minimun is the global minimum cause first
// iteration
//---------------------------------------------------
gbest(1,:,j)=x(I,:,j);
gbestc(1,:,j)=x(I,:,j);
v_gbestc(1,:,j)=v(I,:,j);
for p=1:N
G(p,:,j)=gbest(1,:,j); // creating a matrix of gbest, used for speed computation
end
//---------------------------------------------------
// The first minimun is the best result cause first
// iteration
//---------------------------------------------------
Fbest(1,1,j)=F(I,1,j); // global best
Fbestc(1,1,j)=F(I,1,j);
Fb(1,1,j)=F(I,1,j); // iteration best, used for comparison with global best
//---------------------------------------------------
// Each particle is her personnal best cause first
// first iteration
//---------------------------------------------------
for i=1:N
pbest(i,:,j)=x(i,:,j);
end
//---------------------------------------------------
// Speed and location computation for next iteration
//---------------------------------------------------
v(:,:,j+1)=W(j)*v(:,:,j)+c1*rand()*(pbest(:,:,j)-x(:,:,j))+c2*rand()*(G(:,:,j)-x(:,:,j)); // speed
x(:,:,j+1)=x(:,:,j)+v(:,:,j+1); // location
//---------------------------------------------------
// Entering to the optimization loop
17
//---------------------------------------------------
while (j<itmax-1)
j=j+1
//---------------------------------------------------
// BSG Starcraft ability of the swarm - 1/10 chance
// to enable capacity
//---------------------------------------------------
aleat=rand()
if aleat>=0.9 | j==2
for i=1:number_raptor
v_raptor=speed_multiplicator*norm(v_carrier);
x_raptor(i,:)=x_carrier+(-1+2*rand(1,D))*v_raptor;
end
disp(Sending Raptors)
for i=1:number_raptor
F_raptor(i)=script(x_raptor(i,:));
end
for i=1:N
x(i,:,j)=x(i,:,j-1)+jump_vector;
end
else
18
y=x(i,:,j);
F(i,1,j)=script(y);
end
else
//---------------------------------------------------
// Evaluation of the objective function
//---------------------------------------------------
for i=1:N
y=x(i,:,j);
F(i,1,j)=script(y);
end
//---------------------------------------------------
// Search for the minimum of the swarm
//---------------------------------------------------
[C,I]=min((F(:,:,j)));
//---------------------------------------------------
// Searching for global minimum
//---------------------------------------------------
gbest(1,:,j)=x(I,:,j); // hypothesis : this iteration is better than last one
gbestc(1,:,j)=x(I,:,j);
v_gbestc(1,:,j)=v(I,:,j);
Fb(1,1,j)=F(I,1,j); // looking for the iteration best result
Fbestc(1,1,j)=F(I,1,j);
Fbest(1,:,j)=Fb(1,:,j); // Fbest is the iteration best result
for p=1:N
G(p,:,j)=gbest(1,:,j); // creating a matrix of gbest, used for speed computation
end
//---------------------------------------------------
// Computation of the new personnal best
//---------------------------------------------------
for i=1:N
[C,I]=min(F(i,1,:));
if F(i,1,j)<C
pbest(i,:,j)=x(i,:,j);
else
pbest(i,:,j)=x(i,:,I(3));
end
end
//---------------------------------------------------
// Re-computation of Fbest for reliability test
//---------------------------------------------------
y=gbest(1,:,j);
Fbest(:,:,j)=script(y);
//---------------------------------------------------
// Speed and location computation for next iteration
19
//---------------------------------------------------
v(:,:,j+1)=W(j)*v(:,:,j)+c1*rand()*(pbest(:,:,j)-x(:,:,j))+c2*rand()*(G(:,:,j)-x(:,:,j)); // speed
x(:,:,j+1)=x(:,:,j)+v(:,:,j+1); // location
//---------------------------------------------------
// Plotting the Fbest curve to monitor optimization
//---------------------------------------------------
for count=1:j
Fbest_draw(count)=Fbest(1,1,count);
end
clf(1)
scf(1)
gcf()
xtitle("Objective function value vs Iteration")
axe_prop=gca()
axe_prop.x_label.text="Iteration number"
axe_prop.y_label.text="Objective function value"
else
scf(1)
end
plot(Fbest_draw)
drawnow()
//---------------------------------------------------
// Temporary save in case of crash, very usefull for long time optimization
//---------------------------------------------------
save (PSO_temp)
//---------------------------------------------------
// Out of the optimization loop
//---------------------------------------------------
end
disp(Fbest : + string(Fbest(:,:,j)))
disp(Gbest : + string(gbest(:,:,j)))
save(results_PSO_BSG-Starcraft)
endfunction
function PSO_bsg_starcraft_radius(objective,wmax,wmin,itmax,c1,c2,N,D,borne_sup,borne_inf,vitesse_min,vitesse_max,radius
20
lines(0)
//---------------------------------------------------
// Setting up graphics axis
//---------------------------------------------------
scf(1)
gcf()
xtitle("Objective function value vs Iteration")
axe_prop=gca()
axe_prop.x_label.text="Iteration number"
axe_prop.y_label.text="Objective function value"
scf(2)
gcf()
xtitle("Swarm radius vs Iteration")
axe_prop=gca()
axe_prop.x_label.text="Iteration number"
axe_prop.y_label.text="Swarm radius (log10)"
//---------------------------------------------------
// Declaring objective function
//---------------------------------------------------
var=objective+.sce;
exec(var)
//---------------------------------------------------
// PSO parameters definition
//---------------------------------------------------
// knowledge factors
//c1=2; // for personnal best
//c2=2; // for global best
// problem dimensions
//N=20; // number of particles
//D=6; // problem dimension
//---------------------------------------------------
// Allocation of memory ans first computations
//---------------------------------------------------
for i=1:D
//borne_sup(i)= 1;
//borne_inf(i)= 0;
21
x(1:N,i) =borne_inf(i) +rand(N,1) * ( borne_sup(i) - borne_inf(i) ); // location
//vitesse_min(i)=-0.3;
//vitesse_max(i)=0.3;
v(1:N,i)=vitesse_min(i)+(vitesse_max(i)-vitesse_min(i))*rand(N,1); // speed
end
//---------------------------------------------------
// First evaluation of the objective function
//---------------------------------------------------
for i=1:N
y=x(i,:,j);
F(i,1,j)=script(y); // mono-objective result
end
//---------------------------------------------------
// Search for the minimum of the swarm
//---------------------------------------------------
[C,I]=min((F(:,1,j)));
//---------------------------------------------------
// The first minimun is the global minimum cause first
// iteration
//---------------------------------------------------
gbest(1,:,j)=x(I,:,j);
gbestc(1,:,j)=x(I,:,j);
v_gbestc(1,:,j)=v(I,:,j);
for p=1:N
G(p,:,j)=gbest(1,:,j); // creating a matrix of gbest, used for speed computation
end
//---------------------------------------------------
// The first minimun is the best result cause first
// iteration
//---------------------------------------------------
Fbest(1,1,j)=F(I,1,j); // global best
Fbestc(1,1,j)=F(I,1,j);
Fb(1,1,j)=F(I,1,j); // iteration best, used for comparison with global best
//---------------------------------------------------
// Each particle is her personnal best cause first
// first iteration
//---------------------------------------------------
for i=1:N
pbest(i,:,j)=x(i,:,j);
end
//---------------------------------------------------
// Speed and location computation for next iteration
//---------------------------------------------------
v(:,:,j+1)=W(j)*v(:,:,j)+c1*rand()*(pbest(:,:,j)-x(:,:,j))+c2*rand()*(G(:,:,j)-x(:,:,j)); // speed
x(:,:,j+1)=x(:,:,j)+v(:,:,j+1); // location
22
//---------------------------------------------------
// Entering to the optimization loop
//---------------------------------------------------
while (j<itmax-1 & mesurability==1)
j=j+1
//---------------------------------------------------
// BSG Starcraft ability of the swarm - 1/10 chance
// to enable capacity
//---------------------------------------------------
aleat=rand()
if aleat>=0.9
for i=1:number_raptor
v_raptor=speed_multiplicator*norm(v_carrier);
x_raptor(i,:)=x_carrier+(-1+2*rand(1,D))*v_raptor;
end
disp(Sending Raptors)
for i=1:number_raptor
F_raptor(i)=script(x_raptor(i,:));
end
for i=1:N
x(i,:,j)=x(i,:,j-1)+jump_vector;
end
end
23
y=x(i,:,j);
F(i,1,j)=script(y);
end
else
//---------------------------------------------------
// Evaluation of the objective function
//---------------------------------------------------
for i=1:N
y=x(i,:,j);
F(i,1,j)=script(y);
end
//---------------------------------------------------
// Search for the minimum of the swarm
//---------------------------------------------------
[C,I]=min((F(:,:,j)));
//---------------------------------------------------
// Searching for global minimum
//---------------------------------------------------
gbest(1,:,j)=x(I,:,j); // hypothesis : this iteration is better than last one
gbestc(1,:,j)=x(I,:,j);
v_gbestc(1,:,j)=v(I,:,j);
Fb(1,1,j)=F(I,1,j); // looking for the iteration best result
Fbestc(1,1,j)=F(I,1,j);
Fbest(1,:,j)=Fb(1,:,j); // Fbest is the iteration best result
for p=1:N
G(p,:,j)=gbest(1,:,j); // creating a matrix of gbest, used for speed computation
end
//---------------------------------------------------
// Computation of the new personnal best
//---------------------------------------------------
for i=1:N
[C,I]=min(F(i,1,:));
if F(i,1,j)<C
pbest(i,:,j)=x(i,:,j);
else
pbest(i,:,j)=x(i,:,I(3));
end
end
//---------------------------------------------------
// Re-computation of Fbest for reliability test
//---------------------------------------------------
y=gbest(1,:,j);
Fbest(:,:,j)=script(y);
//---------------------------------------------------
// Speed and location computation for next iteration
24
//---------------------------------------------------
v(:,:,j+1)=W(j)*v(:,:,j)+c1*rand()*(pbest(:,:,j)-x(:,:,j))+c2*rand()*(G(:,:,j)-x(:,:,j)); // speed
x(:,:,j+1)=x(:,:,j)+v(:,:,j+1); // location
//---------------------------------------------------
// Computing measurability - generating capacity
//---------------------------------------------------
[C,I]=min((F(:,:,j)));
leader_temp(1,:,j)=x(I,:,j); // getting swarm leader
for t=1:N
dist_temp(:,t,j) = abs((x(t,:,j)-leader_temp(:,:,j))); // computing L1 norm to leader
end
for t=1:N
dist(t,j)=max(dist_temp(:,t,j));
end
max_dist(j)=max(dist(:,j));
counter=counter+1;
end
if counter==10
mesurability=0;
end
rad_plot(j)=radius;
//---------------------------------------------------
// Plotting the Fbest curve to monitor optimization
//---------------------------------------------------
for count=1:j
Fbest_draw(count)=Fbest(1,1,count);
end
clf(1)
scf(1)
25
gcf()
xtitle("Objective function value vs Iteration")
axe_prop=gca()
axe_prop.x_label.text="Iteration number"
axe_prop.y_label.text="Objective function value"
else
scf(1)
end
plot(Fbest_draw)
drawnow()
//---------------------------------------------------
// Temporary save in case of crash, very usefull for long time optimization
//---------------------------------------------------
save (PSO_temp)
//---------------------------------------------------
// Out of the optimization loop
//---------------------------------------------------
end
disp(Fbest : + string(Fbest(:,:,j)))
disp(Gbest : + string(gbest(:,:,j)))
save(results_PSO_BSG_Starcraft_radius)
endfunction
References
[1] Van den Bergh F and Engelbrecht A.P. A study of particle swarm optimization particle
trajectories. Information Sciences, 2006.
[2] Trelea I.C. The particle swarm optimization algorithm: convergence analysis and parameter
selection. Information Processing Letters, vol. 85, 2003.
[3] S. Janson and M. Middendorf. On trajectories of particles in pso. In Proceedings of the 2007
IEEE Swarm Intelligence Symposium, 2007.
[4] J. Kennedy and R.C. Eberhart. Particle swarm optimisation. In Proceedings of the IEEE
International Conference on Neural Networks, 1995.
[5] M. Molga and C. Smutnicki. Test functions for optimization needs.
http://www.zsd.ict.pwr.wroc.pl/les/docs/functions.pdf, 2005.
[6] Engelbrecht A.P Van der Bergh F. A study of particle swarm optimization particle trajecto-
ries. Information Sciences, 176:937971, 2006.
[7] Shi Y. and Eberhart RC. Parameter selection in particle swarm optimization. In Annual
Conference on. Evolutionary Programming, 1998.
26