pso-rs
An easy-to-use, simple Particle Swarm Optimization (PSO) implementation in Rust
It uses the rand crate for random initialization, and the rayon crate for parallel objective function computation.
The example below can get you started.
In order to use it on your own optimization problem, you will need to define an objective function as it is defined in the run function, and a Config object. See the Notes section for more tips.
Examples
use *;
// define objective function (Rosenbrock)
// define a termination condition
let config = Config ;
// define maximum number of objective function computations
let t_max = 10000;
match run
Notes
Even though you can have particles of any shape and size, as long as each item is f64, pso_rs represents each particle as a flat vector: Vec<f64>.
This means that, for example, in order to find clusters of 20 molecules in 3D space that minimize the Lennard-Jones potential energy, you can define dimensions as (20, 3):
let config = Config ;
If you want, you can also create a custom reshape function, like this one for molecule clusters below:
Then you can use that to reshape the particle at any point, for example to print the minimizer or to use in the objective function you have defined:
// somewhere in main(), after running PSO as in the example:
println!;
// used in the objective function
License: MIT