pub struct Executor<O, S, I> { /* private fields */ }
Expand description

Solves an optimization problem with a solver

Implementations

Constructs an Executor from a user defined problem and a solver.

Example
// Construct an instance of the desired solver
let solver = Newton::new();

// `Rosenbrock` implements `CostFunction` and `Gradient` as required by the
// `SteepestDescent` solver
let problem = Rosenbrock {};

// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver);

This method gives mutable access to the internal state of the solver. This allows for initializing the state before running the Executor. The options for initialization depend on the type of state used by the chosen solver. Common types of state are IterState, PopulationState, and LinearProgramState. Please see the documentation of the desired solver for information about which state is used.

Example
// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver)
    // Configure and initialize internal state.
    .configure(|state| state.param(init_param).max_iters(10));

Runs the executor by applying the solver to the optimization problem.

Example
// Create instance of `Executor` with `problem` and `solver`
let result = Executor::new(problem, solver)
    // Configure and initialize internal state.
    .configure(|state| state.param(init_param).max_iters(100))
    // Execute solver
    .run()?;

Adds an observer to the executor. Observers are required to implement the Observe trait. The parameter mode defines the conditions under which the observer will be called. See ObserverMode for details.

It is possible to add multiple observers.

Example
// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver)
    .add_observer(SlogLogger::term(), ObserverMode::Always);

Configures checkpointing

Example
let checkpoint = FileCheckpoint::new(
    // Directory where checkpoints are saved to
    ".checkpoints",
    // Filename of checkpoint
    "rosenbrock_optim",
    // How often checkpoints should be saved
    CheckpointingFrequency::Every(20)
);

// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver)
    // Add checkpointing
    .checkpointing(checkpoint);

Enables or disables CTRL-C handling (default: enabled). The CTRL-C handling gracefully stops the solver if it is cancelled via CTRL-C (SIGINT). Requires the optional ctrlc feature to be set.

Note that this does not work with nested Executors. If a solver executes another solver internally, the inner solver needs to disable CTRL-C handling.

Example
// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver).ctrlc(false);

Enables or disables timing of individual iterations (default: enabled).

Example
// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver).timer(false);

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.