Calculation

Trait Calculation 

Source
pub trait Calculation<P, S> {
    type Error: Error + 'static;
    type Output;

    const NAME: &'static str;

    // Required methods
    fn next(
        &mut self,
        problem: &mut Problem<P>,
        state: S,
    ) -> Result<S, Self::Error>;
    fn finalise(
        &mut self,
        problem: &mut Problem<P>,
        state: S,
    ) -> Result<Self::Output, Self::Error>;

    // Provided method
    fn initialise(
        &mut self,
        _problem: &mut Problem<P>,
        state: S,
    ) -> Result<S, Self::Error> { ... }
}
Expand description

Trait implemented by all problems solveable by Trellis

A calculation defines the core loop of the solver. Typically we would write a for loop, consisting of an initialisation step where the calculation is arranged, a procedure carried out on each loop iteration, and a finalisation step prior to return. This trait separates these methods so they can be called by the [Runner]

Required Associated Constants§

Source

const NAME: &'static str

An identifier for the calculation.

This identifier is printed in tracing logs

Required Associated Types§

Source

type Error: Error + 'static

The error associated with the problem

Source

type Output

The type returned to the caller.

Trellis defines a data-rich [Output], which can be constructed from the calculation, and internal state. In some circumstances it may be appropriate to return this type to the caller. In other circumstances it may be preferential to bury this complexity, returning the caller a custom datatype.

Required Methods§

Source

fn next(&mut self, problem: &mut Problem<P>, state: S) -> Result<S, Self::Error>

One iteration of the core algorithm

Source

fn finalise( &mut self, problem: &mut Problem<P>, state: S, ) -> Result<Self::Output, Self::Error>

Converts the internal state to the user-facing return datatype

Provided Methods§

Source

fn initialise( &mut self, _problem: &mut Problem<P>, state: S, ) -> Result<S, Self::Error>

Initialisation.

This step prepares the state object for the main calculation loop.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§