Struct cobyla::CobylaSolver
source · pub struct CobylaSolver { /* private fields */ }
Expand description
Argmin Solver which implements COBYLA method.
use argmin::core::{CostFunction, Error, Executor};
use argmin::core::observers::{ObserverMode};
use argmin_observer_slog::SlogLogger;
use cobyla::CobylaSolver;
struct ParaboloidProblem;
impl CostFunction for ParaboloidProblem {
type Param = Vec<f64>;
type Output = Vec<f64>;
// Minimize 10*(x0+1)^2 + x1^2 subject to x0 >= 0
fn cost(&self, x: &Self::Param) -> Result<Self::Output, Error> {
Ok(vec![10. * (x[0] + 1.).powf(2.) + x[1].powf(2.), x[0]])
}
}
let pb = ParaboloidProblem;
let solver = CobylaSolver::new(vec![1., 1.]);
let res = Executor::new(pb, solver)
.configure(|state| state.max_iters(100))
.add_observer(SlogLogger::term(), ObserverMode::Always)
.run()
.unwrap();
// Wait a second (lets the logger flush everything before printing again)
std::thread::sleep(std::time::Duration::from_secs(1));
println!("Result of COBYLA:\n{}", res);
Implementations§
Trait Implementations§
source§impl<O> Solver<O, CobylaState> for CobylaSolver
impl<O> Solver<O, CobylaState> for CobylaSolver
source§fn init(
&mut self,
problem: &mut Problem<O>,
state: CobylaState
) -> Result<(CobylaState, Option<KV>), Error>
fn init( &mut self, problem: &mut Problem<O>, state: CobylaState ) -> Result<(CobylaState, Option<KV>), Error>
Initializes the algorithm.
Executed before any iterations are performed and has access to the optimization problem
definition and the internal state of the solver.
Returns an updated state
and optionally a KV
which holds key-value pairs used in
Observers.
The default implementation returns the unaltered state
and no KV
.
source§fn next_iter(
&mut self,
problem: &mut Problem<O>,
state: CobylaState
) -> Result<(CobylaState, Option<KV>), Error>
fn next_iter( &mut self, problem: &mut Problem<O>, state: CobylaState ) -> Result<(CobylaState, Option<KV>), Error>
Computes a single iteration of the algorithm and has access to the optimization problem
definition and the internal state of the solver.
Returns an updated state
and optionally a KV
which holds key-value pairs used in
Observers.
source§fn terminate(&mut self, state: &CobylaState) -> TerminationStatus
fn terminate(&mut self, state: &CobylaState) -> TerminationStatus
Used to implement stopping criteria, in particular criteria which are not covered by
(terminate_internal
.
This method has access to the internal state and returns an TerminationReason
.