Skip to main content

Algorithm

Trait Algorithm 

Source
pub trait Algorithm<P, S: Status, U = (), E = Infallible>: Send + Sync {
    type Summary;
    type Config;
    type Init;

    // Required methods
    fn initialize(
        &mut self,
        problem: &P,
        status: &mut S,
        args: &U,
        init: &Self::Init,
        config: &Self::Config,
    ) -> Result<(), E>;
    fn step(
        &mut self,
        current_step: usize,
        problem: &P,
        status: &mut S,
        args: &U,
        config: &Self::Config,
    ) -> Result<(), E>;
    fn summarize(
        &self,
        current_step: usize,
        problem: &P,
        status: &S,
        args: &U,
        init: &Self::Init,
        config: &Self::Config,
    ) -> Result<Self::Summary, E>;

    // Provided methods
    fn postprocessing(
        &mut self,
        problem: &P,
        status: &mut S,
        args: &U,
        config: &Self::Config,
    ) -> Result<(), E> { ... }
    fn reset(&mut self) { ... }
    fn process<C>(
        &mut self,
        problem: &P,
        args: &U,
        init: Self::Init,
        config: Self::Config,
        callbacks: C,
    ) -> Result<Self::Summary, E>
       where C: Into<Callbacks<Self, P, S, U, E, Self::Config>>,
             Self: Sized { ... }
    fn process_with_default_callbacks(
        &mut self,
        problem: &P,
        user_data: &U,
        init: Self::Init,
        config: Self::Config,
    ) -> Result<Self::Summary, E>
       where Self: Sized { ... }
    fn process_default(
        &mut self,
        problem: &P,
        user_data: &U,
        init: Self::Init,
    ) -> Result<Self::Summary, E>
       where Self: Sized,
             Self::Config: Default { ... }
    fn default_callbacks() -> Callbacks<Self, P, S, U, E, Self::Config>
       where Self: Sized { ... }
}
Expand description

A trait representing an Algorithm which can be used to solve a problem P.

This trait is implemented for the algorithms found in the algorithms module and contains all the methods needed to process a problem.

Required Associated Types§

Source

type Summary

A type which holds a summary of the algorithm’s ending state.

Source

type Config

The configuration struct for the algorithm.

Source

type Init

The initialization payload for a single run.

Required Methods§

Source

fn initialize( &mut self, problem: &P, status: &mut S, args: &U, init: &Self::Init, config: &Self::Config, ) -> Result<(), E>

Any setup work done before the main steps of the algorithm should be done here.

§Errors

Returns an Err(E) if any internal evaluation of the problem P fails.

Source

fn step( &mut self, current_step: usize, problem: &P, status: &mut S, args: &U, config: &Self::Config, ) -> Result<(), E>

The main “step” of an algorithm, which is repeated until termination conditions are met or the max number of steps have been taken.

§Errors

Returns an Err(E) if any internal evaluation of the problem P fails.

Source

fn summarize( &self, current_step: usize, problem: &P, status: &S, args: &U, init: &Self::Init, config: &Self::Config, ) -> Result<Self::Summary, E>

Generates a new Algorithm::Summary from the current state of the Algorithm, which can be displayed or used elsewhere.

§Errors

Returns an Err(E) if any internal evaluation of the problem P fails.

Provided Methods§

Source

fn postprocessing( &mut self, problem: &P, status: &mut S, args: &U, config: &Self::Config, ) -> Result<(), E>

Runs any steps needed by the Algorithm after termination or convergence. This will run regardless of whether the Algorithm converged.

§Errors

Returns an Err(E) if any internal evaluation of the problem P fails.

Source

fn reset(&mut self)

Reset the algorithm to its initial state.

Source

fn process<C>( &mut self, problem: &P, args: &U, init: Self::Init, config: Self::Config, callbacks: C, ) -> Result<Self::Summary, E>
where C: Into<Callbacks<Self, P, S, U, E, Self::Config>>, Self: Sized,

Process the given problem using this Algorithm.

This method first runs Algorithm::initialize, then runs Algorithm::step in a loop, terminating if any supplied [Terminator]s return ControlFlow::Break. Finally, regardless of convergence, Algorithm::postprocessing is called. Algorithm::summarize is called to create a summary of the Algorithm’s state.

§Errors

Returns an Err(E) if any internal evaluation of the problem P fails.

Source

fn process_with_default_callbacks( &mut self, problem: &P, user_data: &U, init: Self::Init, config: Self::Config, ) -> Result<Self::Summary, E>
where Self: Sized,

Process the given problem using this Algorithm and the algorithm’s default callbacks.

This method first runs Algorithm::initialize, then runs Algorithm::step in a loop, terminating if any of the Algorithm::default_callbacks return ControlFlow::Break. Finally, regardless of convergence, Algorithm::postprocessing is called. Algorithm::summarize is called to create a summary of the Algorithm’s state.

§Errors

Returns an Err(E) if any internal evaluation of the problem P fails.

Source

fn process_default( &mut self, problem: &P, user_data: &U, init: Self::Init, ) -> Result<Self::Summary, E>
where Self: Sized, Self::Config: Default,

Process the given problem using this Algorithm with default config and default callbacks.

This method is similar to Algorithm::process, except it uses Default::default for the algorithm configuration and Algorithm::default_callbacks for the callback set.

§Errors

Returns an Err(E) if any internal evaluation of the problem P fails.

Source

fn default_callbacks() -> Callbacks<Self, P, S, U, E, Self::Config>
where Self: Sized,

Provides a set of reasonable default callbacks specific to this Algorithm.

Implementors§

Source§

impl<P, U, E> Algorithm<P, GradientStatus, U, E> for Adam
where P: Gradient<U, E>,

Source§

impl<P, U, E> Algorithm<P, GradientStatus, U, E> for ConjugateGradient
where P: Gradient<U, E>,

Source§

impl<P, U, E> Algorithm<P, GradientStatus, U, E> for LBFGSB
where P: Gradient<U, E>,

Source§

impl<P, U, E> Algorithm<P, GradientStatus, U, E> for TrustRegion
where P: Gradient<U, E>,

Source§

impl<P, U, E> Algorithm<P, GradientFreeStatus, U, E> for CMAES
where P: CostFunction<U, E>,

Source§

impl<P, U, E> Algorithm<P, GradientFreeStatus, U, E> for DifferentialEvolution
where P: CostFunction<U, E>,

Source§

impl<P, U, E> Algorithm<P, GradientFreeStatus, U, E> for NelderMead
where P: CostFunction<U, E>,

Source§

impl<P, U, E> Algorithm<P, EnsembleStatus, U, E> for AIES
where P: LogDensity<U, E>,

Source§

impl<P, U, E> Algorithm<P, EnsembleStatus, U, E> for ESS
where P: LogDensity<U, E>,

Source§

impl<P, U, E> Algorithm<P, SwarmStatus, U, E> for PSO
where P: CostFunction<U, E>,

Source§

impl<P, U, E, I> Algorithm<P, SimulatedAnnealingStatus<I>, U, E> for SimulatedAnnealing
where P: SimulatedAnnealingGenerator<U, E, Input = I>, I: Serialize + for<'a> Deserialize<'a> + Clone + Default,