pub trait Observe<I> {
    // Provided methods
    fn observe_init(
        &mut self,
        _name: &str,
        _state: &I,
        _kv: &KV
    ) -> Result<(), Error> { ... }
    fn observe_iter(&mut self, _state: &I, _kv: &KV) -> Result<(), Error> { ... }
    fn observe_final(&mut self, _state: &I) -> Result<(), Error> { ... }
}
Expand description

An interface which every observer is required to implement

§Example

use argmin::core::{Error, KV, State};
use argmin::core::observers::Observe;

struct MyObserver {}

impl<I> Observe<I> for MyObserver
where
    // Optional constraint on `I`. The `State` trait, which every state used in argmin needs to
    // implement, offers a range of methods which can be useful.
    I: State,
{
    fn observe_init(&mut self, name: &str, state: &I, kv: &KV) -> Result<(), Error> {
        // Do something with `name` and/or `kv`
        // Is executed after initialization of a solver
        Ok(())
    }

    fn observe_iter(&mut self, state: &I, kv: &KV) -> Result<(), Error> {
        // Do something with `state` and/or `kv`
        // Is executed after each iteration of a solver
        Ok(())
    }
}

Provided Methods§

source

fn observe_init( &mut self, _name: &str, _state: &I, _kv: &KV ) -> Result<(), Error>

Called once after initialization of the solver.

Has access to the name of the solver via name, the initial state and to a key-value store kv with settings of the solver.

source

fn observe_iter(&mut self, _state: &I, _kv: &KV) -> Result<(), Error>

Called at every iteration of the solver

Has access to the current state of the solver (which always implements State) and to a key-value store kv with entries specific for each solver.

source

fn observe_final(&mut self, _state: &I) -> Result<(), Error>

Called at the end of a solver run

Has access to the final state of the solver (which always implements State).

Implementors§

source§

impl<I: State> Observe<I> for Observers<I>

Implementing Observe for Observers allows to use it like a single observer. In its implementation it will loop over all stored observers, checks if the conditions for observing are met and calls the actual observers if required.