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.

psocalculatepenalties(state)

function state = psocalculatepenalties(state)
% Calculates the penalty to apply for outofbounds particles when using
% the "penalize" constraint handling method.
% nx1 vector of penalties to apply to each particle
g = state.ConstrViolations ;
k = zeros(size(g));
n = size(state.Score,1);
% penalties = zeros(size(g,1),1) ;
if sum(state.OutOfBounds)
idx = logical(state.OutOfBounds) ;
k(idx,:) = (mean(state.Score).*g(idx,:))./sum(mean(g(idx,:),1).^2) ;
% penalties = sum(k(idx,:).*g(idx,:),2) ;
penalties = sum(k(idx,:).*g(idx,:),2) + max(state.Score(setdiff(1:n,idx))) ;
% Apply the penalties to each particle's score
state.Score(idx) = state.Score(idx) + penalties ;
end


Contact us