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§
Required Methods§
Sourcefn initialize(
&mut self,
problem: &P,
status: &mut S,
args: &U,
config: &Self::Config,
) -> Result<(), E>
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.
Sourcefn step(
&mut self,
current_step: usize,
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>
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.
Sourcefn summarize(
&self,
current_step: usize,
problem: &P,
status: &S,
args: &U,
config: &Self::Config,
) -> Result<Self::Summary, E>
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§
Sourcefn postprocessing(
&mut self,
problem: &P,
status: &mut S,
args: &U,
config: &Self::Config,
) -> Result<(), E>
fn postprocessing( &mut self, problem: &P, status: &mut S, args: &U, config: &Self::Config, ) -> Result<(), E>
Sourcefn process<C>(
&mut self,
problem: &P,
args: &U,
config: Self::Config,
callbacks: C,
) -> Result<Self::Summary, E>
fn process<C>( &mut self, problem: &P, args: &U, config: Self::Config, callbacks: C, ) -> Result<Self::Summary, E>
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.
Sourcefn process_default(
&mut self,
problem: &P,
user_data: &U,
config: Self::Config,
) -> Result<Self::Summary, E>where
Self: Sized,
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.