pub struct Executor<O, S, I> { /* private fields */ }
Expand description
Solves an optimization problem with a solver
Implementations
sourceimpl<O, S, I> Executor<O, S, I> where
S: Solver<O, I>,
I: State + SerializeAlias + DeserializeOwnedAlias,
impl<O, S, I> Executor<O, S, I> where
S: Solver<O, I>,
I: State + SerializeAlias + DeserializeOwnedAlias,
sourcepub fn new(problem: O, solver: S) -> Self
pub fn new(problem: O, solver: S) -> Self
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);
sourcepub fn configure<F: FnOnce(I) -> I>(self, init: F) -> Self
pub fn configure<F: FnOnce(I) -> I>(self, init: F) -> Self
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));
sourcepub fn run(self) -> Result<OptimizationResult<O, S, I>, Error>
pub fn run(self) -> Result<OptimizationResult<O, S, I>, Error>
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()?;
sourcepub fn add_observer<OBS: Observe<I> + 'static>(
self,
observer: OBS,
mode: ObserverMode
) -> Self
pub fn add_observer<OBS: Observe<I> + 'static>(
self,
observer: OBS,
mode: ObserverMode
) -> Self
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);
sourcepub fn checkpointing<C: 'static + Checkpoint<S, I>>(self, checkpoint: C) -> Self
pub fn checkpointing<C: 'static + Checkpoint<S, I>>(self, checkpoint: C) -> Self
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);
sourcepub fn ctrlc(self, ctrlc: bool) -> Self
pub fn ctrlc(self, ctrlc: bool) -> Self
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 Executor
s. 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);
Auto Trait Implementations
impl<O, S, I> !RefUnwindSafe for Executor<O, S, I>
impl<O, S, I> !Send for Executor<O, S, I>
impl<O, S, I> !Sync for Executor<O, S, I>
impl<O, S, I> Unpin for Executor<O, S, I> where
I: Unpin,
O: Unpin,
S: Unpin,
impl<O, S, I> !UnwindSafe for Executor<O, S, I>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more