This is a small library implementing a particle swarm optimization algorithm in C89. This library can either be installed and linked with, or simply be copied into another project's source tree since it consists of only two files. The particle swarm simulation functions provided can be used in a program to heuristically minimize functions.

Usage and Configuration

First include the cpso header, configure the swarm, then call the cpso initialization function. Then either cpso_step or cpso_run can be called to run the particle swarm simulation either step-wise or until a set number of iterations respectively.

The details for the swarm configuration struct are shortly described in the "cpso.h" header file.


Within the distribution tarball, there is a file "demo.c" that displays usage of the library with a randomizing fitness function. This demo showcases use of all provided library functions (as of the 1.0.0 release), can be built with 'make demo', and run by executing the 'demo' binary created.


No external dependencies are required for this library other than a C89 compliant libc, make, compiler. A config.mk file is provided which allows for easy editing of compilation flags, linking options, and installation directories. The library can be built with 'make all', installed with 'make install', and uninstalled with 'make uninstall'. Note that any build configuration changes made to config.mk must be the same for both the install and uninstall targets, otherwise they may not work as desired.

Download Links

2019-01-14: cpso-v1.0.0.tar.gz

-Todd Gaunt
• return •