Code covered by the BSD License
 ...
 ...
Find the minimum of a function using Particle Swarm Optimization.
 ...
Particle swarm optimization for binary genomes.
 ...
Penaltybased constraint enforcement method.
 ...
Internal toolbox function.
 ...
Checks initial population with respect to linear constraints. Requires
 ...
Check the the swarm population against all constraints.
 ackleysfcn(x)
Ackley's Function.
 binarytestfcn(x)
 dejongsfcn(x)
 dropwavefcn(x)
 evolutioncomplete(options...Plays a notification when genetic algorithm finishes. Requires a
 griewangksfcn(x)
Griewangk's function.
 heart(x)
For nonlinear constraint demonstration.
 initstate(nvars,options,n...Initialize swarm condition. Called by PSO.
 langermannsfcn(x)
 nonlinearconstrdemo(x)
Nonlinear constraints demo with Rosenbrock's function. Select this
 overlaycontour(fitnessfcn...Overlays contour and marks known minimum for demo cases of pso.
 overlaysurface(fitnessfcn...Overlays surface and marks known minimum for demo cases of pso. Called by
 psoboundsabsorb(state,Ain...
 psocalculatepenalties(sta...Calculates the penalty to apply for outofbounds particles when using
 psocheckpopulationinitran...Automatically adjust PopInitRange according to provided LB and UB.
 psocreationbinary(options...Generates uniformly distributed swarm consisting of binary bitstrings.
 psocreationuniform(option...Generates uniformly distributed swarm based on options.PopInitRange.
 psodemo(DemoMode)
Runs the PSO on a few demonstration functions, which should be located
 psogenerateoutputmessage(...Generates output message after PSO is done.
 psogetinitialpopulation(o...Gets the initial population (if any) defined by the options structure.
 psoiterate(options,state,...Updates swarm positions and velocities. Called to iterate the swarm from
 psooptimset(varargin)
Creates an options structure for pso.
 psoplotbestf(options,stat...Plots the best, mean, and worst scores of particle swarm.
 psoplotscorediversity(opt...Plots a histogram containing the best and mean scores of particle swarm.
 psoplotswarm(options,stat...Plots the positions of particle swarm.
 psoplotswarmsurf(options,...Shows the evolution of a 2variable population over a known surface. This
 psorunhybridfcn(fitnessfc...Calls the hybrid function defined in options.HybridFcn, from PSO.
 quadrifolium(x)
For demonstrating nonlinear constraints. This produces a 2dimensional
 rastriginsfcn(x)
Takes row inputs. If not row, will attempt to correct it.
 rosenbrocksfcn(x)
Takes row inputs. If input is not row, will attempt to correct it.
 schwefelsfcn(x)
Schwefel's function.
 templatefcn(x)
Template for writing custom test/demonstration functions for psodemo.
 testfcn1(x)
 unitcircle(x)
Unit disk. The vector x should be a row vector. This is to test the
 unitdisk(x)
Unit disk. The vector x should be a row vector. This is to test the
 void(varargin)

View all files
Another Particle Swarm Toolbox
by
Sam
01 Dec 2009
(Updated
01 Apr 2014)
Implementation of a PSO algorithm with the same syntax as the Genetic Algorithm Toolbox.

nonlinearconstrdemo(x)

function f = nonlinearconstrdemo(x)
% Nonlinear constraints demo with Rosenbrock's function. Select this
% function by running PSODEMO and choosing it as the demo function.
%
% This demonstration shows an example of the pso working over Rosenbrock's
% banana function, with an additional nonlinear constraint confining the
% swarm to search within a four leaf clovershaped area (quadrifolium)
% superimposed on top of the twodimensional design space. The true global
% optimum is marked by the red flag, and lies right on the border of the
% feasible design space.
if strcmp(x,'init')
% f.Aineq = [1 1;1 0] ;
% f.bineq = [0;0] ;
f.Aineq = [] ;
f.bineq = [] ;
f.Aeq = [] ;
f.beq = [] ;
f.LB = [] ; f.UB = [] ;
f.nonlcon = 'quadrifolium' ; % Could also use 'heart' or 'unitdisk'
f.options.PopInitRange = [2, 2; 2, 2] ;
f.options.KnownMin = [1,1] ;
f.options.PopulationSize = 100 ;
f.options.ConstrBoundary = 'penalize' ;
f.options.UseParallel = 'never' ;
else
x = reshape(x,1,[]) ;
if size(x,2) >= 2
% x1 = x(1:end1) ; x2 = x(end) ;
f = 0 ;
for i = 1:size(x,2)1
f = f + (1x(i))^2 + 100*(x(i+1)  x(i)^2)^2 ;
end
else
error('Rosenbrock''s function requires at least two inputs')
end
end


Contact us