This repository contains the standard Particle Swarm Optimization code (Matlab M-file) for optimizing the benchmark function.
DOI: 10.13140/RG.2.2.16986.88000
This repository contains the standard Particle Swarm Optimization code (matlab M-file) for optimizing the benchmark function:
.
├── img
| ├── benchmark.gif
| ├── convergence-2d.png
| ├── convergence-30d.png
| ├── logo.jpg
| └── trajectory.png
├── _config.yml
├── LICENSE
├── pso.m —— [function of particle swarm optimization]
├── README.md
└── test.m —— [a test for 'pso.m']
[f_best, x_best] = pso ( J, d, xlmt, n, T )
where
J
is the function handle of the objective functiond
is the dimension of the design variablexlmt
is the limit of the design variable; is a matrix with d
rows and 2 column, and the first column contains lower limits of all dimension while the second upper ones.n
is the population size of the particle swarmT
is the maximum iteration times.f_best
is the fitness of the optimal solutiong_best
is the optimal solutionFor instance, a benchmark Rastrigin is chosen for a test:
Here, this benchmark is coded as a function handle
J = @(X) sum( X.^2 - 10*cos(2*pi*X) + 10 );
where X
is a d
-by-n
matrix.
To run the test by executing
test.m
The test including two runs:
30-d
benchmark
The results includes an optimal solution, its fitness and an execution time. Also, a plot of the convergence curve of fitness is shown.
2-d
benchmark
The results includes an optimal solution, its fitness and an execution time. Also, a plot of the convergence curve of fitness, a plot of the trajectory of global optimal are shown.
[1] Article: Particle swarm optimization (PSO). A tutorial
[2] Author’s post (Chinese simplified): 粒子群优化及其Matlab实现
[3] Repo: BenchmarkFcns