pub struct ParticleSwarm<P, F> { /* private fields */ }
Expand description

Particle Swarm Optimization (PSO)

Canonical implementation of the particle swarm optimization method as outlined in [0] in chapter II, section A.

The rayon feature enables parallel computation of the cost function. This can be beneficial for expensive cost functions, but may cause a drop in performance for cheap cost functions. Be sure to benchmark both parallel and sequential computation.

Requirements on the optimization problem

The optimization problem is required to implement CostFunction.

References

[0] Zambrano-Bigiarini, M. et.al. (2013): Standard Particle Swarm Optimisation 2011 at CEC-2013: A baseline for future PSO improvements. 2013 IEEE Congress on Evolutionary Computation. https://doi.org/10.1109/CEC.2013.6557848

[1] https://en.wikipedia.org/wiki/Particle_swarm_optimization

Implementations

Construct a new instance of ParticleSwarm

Takes the number of particles and bounds on the search space as inputs. bounds is a tuple (lower_bound, upper_bound), where lower_bound and upper_bound are of the same type as the position of a particle (P) and of the same length as the problem as dimensions.

The inertia weight on velocity and the social and cognitive acceleration factors can be adapted with with_inertia_factor, with_cognitive_factor and with_social_factor, respectively.

The weights and acceleration factors default to:

  • inertia: 1/(2 * ln(2))
  • cognitive: 0.5 + ln(2)
  • social: 0.5 + ln(2)
Example
let pso: ParticleSwarm<_, f64> = ParticleSwarm::new((lower_bound, upper_bound), 40);

Set inertia factor on particle velocity

Defaults to 1/(2 * ln(2)).

Example
let pso: ParticleSwarm<_, f64> =
    ParticleSwarm::new((lower_bound, upper_bound), 40).with_inertia_factor(0.5)?;

Set cognitive acceleration factor

Defaults to 0.5 + ln(2).

Example
let pso: ParticleSwarm<_, f64> =
    ParticleSwarm::new((lower_bound, upper_bound), 40).with_cognitive_factor(1.1)?;

Set social acceleration factor

Defaults to 0.5 + ln(2).

Example
let pso: ParticleSwarm<_, f64> =
    ParticleSwarm::new((lower_bound, upper_bound), 40).with_social_factor(1.1)?;

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Deserialize this value from the given Serde deserializer. Read more

Serialize this value into the given Serde serializer. Read more

Perform one iteration of algorithm

Name of the solver. Mainly used in Observers.

Initializes the algorithm. Read more

Checks whether basic termination reasons apply. Read more

Used to implement stopping criteria, in particular criteria which are not covered by (terminate_internal. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.