pub struct Executor<O, S, I> { /* private fields */ }
Expand description
Solves an optimization problem with a solver
Implementations§
source§impl<O, S, I> Executor<O, S, I>
impl<O, S, I> Executor<O, S, I>
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 canceled 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);
sourcepub fn timer(self, timer: bool) -> Self
pub fn timer(self, timer: bool) -> Self
Enables or disables timing of individual iterations (default: false).
In case a timeout is set, this will automatically be set to true.
§Example
// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver).timer(false);
sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Sets a timeout for the run.
The optimization run is stopped once the timeout is exceeded. Note that the check is performed after each iteration, therefore the actual runtime can exceed the the set duration. This also enables time measurements.
§Example
// Create instance of `Executor` with `problem` and `solver`
let executor = Executor::new(problem, solver).timeout(std::time::Duration::from_secs(30));
Auto Trait Implementations§
impl<O, S, I> Freeze for Executor<O, S, I>
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>
impl<O, S, I> !UnwindSafe for Executor<O, S, I>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.