GitHub - rgreen13/PSO-Python: Particle Swarm Optimization in Python

A simple implementation of classic Particle Swarm Optimization in Python.

Usage

  1. Update the fitFunc function to accurately reflect your fitness function
  2. Adjust Np and Nd to reflect your fitness function
  3. Adjust xMin, xMax, vMin, and vMax to reflect your fitness function
  4. Adjust gBestValue and pBestValue initialization to reflect your fitness function
  5. Run the code!

Method Names

fitFunc: User defined fitness function

initPosition: Initializes R with random values

initVelocity: Initializes V with random values

updatePosition: Updates R values based on V

updateVelocity: Updates V values based on gBestPos, pBestPos, w, and chi

udpateFitness: Updates M values based on R

Variable Names

R: Position

V: Velocity

M: Fitness

Np: Number of Probes Nd: Number of Dimensions Nt: Number of Iterations

w: Omega wMin: Omega Minimum Value wMax: Omega Maximum Value

chi: Constriction Factor

xMin: Minimum value for any dimension in R xMax: Maximum value for any dimension in R

vMin: Minimum value for any dimension in V vMax: Maximum value for any dimension in V

gBestValue: Global best fitness value gBestPos: Global best fitness position

pBestValue: Personal best fitness value pBestPos: Personal best fitness position