Algorithm

Trait Algorithm 

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

    // Required methods
    fn initialize(
        &mut self,
        problem: &P,
        status: &mut S,
        args: &U,
        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,
        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,
        config: Self::Config,
        callbacks: C,
    ) -> Result<Self::Summary, E>
       where C: Into<Callbacks<Self, P, S, U, E, Self::Config>>,
             Self: Sized { ... }
    fn process_default(
        &mut self,
        problem: &P,
        user_data: &U,
        config: Self::Config,
    ) -> Result<Self::Summary, E>
       where Self: Sized { ... }
    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.

Required Methods§

Source

fn initialize( &mut self, problem: &P, status: &mut S, args: &U, 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, 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, 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_default( &mut self, problem: &P, user_data: &U, config: Self::Config, ) -> Result<Self::Summary, E>
where 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 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. This method is similar to Algorithm::process, except it uses the default callbacks and configuration for the algorithm.

§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§