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§

source§

impl<P, F> ParticleSwarm<P, F>where P: Clone + SyncAlias + ArgminSub<P, P> + ArgminMul<F, P> + ArgminRandom + ArgminZeroLike, F: ArgminFloat,

source

pub fn new(bounds: (P, P), num_particles: usize) -> Self

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);
source

pub fn with_inertia_factor(self, factor: F) -> Result<Self, Error>

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)?;
source

pub fn with_cognitive_factor(self, factor: F) -> Result<Self, Error>

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)?;
source

pub fn with_social_factor(self, factor: F) -> Result<Self, Error>

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§

source§

impl<P: Clone, F: Clone> Clone for ParticleSwarm<P, F>

source§

fn clone(&self) -> ParticleSwarm<P, F>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'de, P, F> Deserialize<'de> for ParticleSwarm<P, F>where P: Deserialize<'de>, F: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<P, F> Serialize for ParticleSwarm<P, F>where P: Serialize, F: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<O, P, F> Solver<O, PopulationState<Particle<P, F>, F>> for ParticleSwarm<P, F>where O: CostFunction<Param = P, Output = F> + SyncAlias, P: SerializeAlias + Clone + SyncAlias + ArgminAdd<P, P> + ArgminSub<P, P> + ArgminMul<F, P> + ArgminZeroLike + ArgminRandom + ArgminMinMax, F: ArgminFloat,

source§

fn next_iter( &mut self, problem: &mut Problem<O>, state: PopulationState<Particle<P, F>, F> ) -> Result<(PopulationState<Particle<P, F>, F>, Option<KV>), Error>

Perform one iteration of algorithm

source§

const NAME: &'static str = "Particle Swarm Optimization"

Name of the solver. Mainly used in Observers.
source§

fn init( &mut self, problem: &mut Problem<O>, state: PopulationState<Particle<P, F>, F> ) -> Result<(PopulationState<Particle<P, F>, F>, Option<KV>), Error>

Initializes the algorithm. Read more
source§

fn terminate_internal(&mut self, state: &I) -> TerminationStatus

Checks whether basic termination reasons apply. Read more
source§

fn terminate(&mut self, _state: &I) -> TerminationStatus

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

Auto Trait Implementations§

§

impl<P, F> RefUnwindSafe for ParticleSwarm<P, F>where F: RefUnwindSafe, P: RefUnwindSafe,

§

impl<P, F> Send for ParticleSwarm<P, F>where F: Send, P: Send,

§

impl<P, F> Sync for ParticleSwarm<P, F>where F: Sync, P: Sync,

§

impl<P, F> Unpin for ParticleSwarm<P, F>where F: Unpin, P: Unpin,

§

impl<P, F> UnwindSafe for ParticleSwarm<P, F>where F: UnwindSafe, P: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

source§

impl<T> SendSyncUnwindSafe for Twhere T: Send + Sync + UnwindSafe + ?Sized,