Struct metaheuristics_nature::Solver
source · [−]pub struct Solver<F: ObjFunc, R> { /* private fields */ }
Expand description
A public API for using optimization methods.
Users can simply obtain their solution and see the result.
- The method is a type that implemented
Algorithm
. - The objective function is a type that implement
ObjFunc
. - A basic algorithm data is hold by
Context
.
The builder of this type can infer the algorithm by Setting::Algorithm
.
use metaheuristics_nature::{Rga, Solver};
// Build and run the solver
let s = Solver::build(Rga::default())
.task(|ctx| ctx.gen == 20)
.solve(MyFunc::new());
// Get the result from objective function
let ans = s.result();
// Get the optimized XY value of your function
let xs = s.best_parameters();
let y = s.best_fitness();
// Get the history reports
let report = s.report();
Implementations
sourceimpl<F: ObjFunc, R> Solver<F, R>
impl<F: ObjFunc, R> Solver<F, R>
sourcepub fn func(&self) -> &F
pub fn func(&self) -> &F
Get the reference of the objective function.
It’s useful when you need to get the preprocessed data from the initialization process, which is stored in the objective function.
sourcepub fn report(&self) -> &[R]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub fn report(&self) -> &[R]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Get the history report returned by record function.
sourcepub fn best_parameters(&self) -> &[f64]
pub fn best_parameters(&self) -> &[f64]
Get the best parameters.
sourcepub fn best_fitness(&self) -> F::Fitness
pub fn best_fitness(&self) -> F::Fitness
Get the best fitness.
sourceimpl<F: ObjFunc> Solver<F, ()>
impl<F: ObjFunc> Solver<F, ()>
sourcepub fn build<S>(setting: S) -> SolverBuilder<'static, S, F, ()> where
S: Setting,
pub fn build<S>(setting: S) -> SolverBuilder<'static, S, F, ()> where
S: Setting,
Start to build a solver. Take a setting and setup the configurations.
Please check SolverBuilder
type, it will help you choose your configuration.
If all things are well-setup, call SolverBuilder::solve
.
The default value of each option can be found in their document.
Auto Trait Implementations
impl<F, R> RefUnwindSafe for Solver<F, R> where
F: RefUnwindSafe,
R: RefUnwindSafe,
<F as ObjFunc>::Fitness: RefUnwindSafe,
impl<F, R> Send for Solver<F, R> where
R: Send,
impl<F, R> Sync for Solver<F, R> where
R: Sync,
impl<F, R> Unpin for Solver<F, R> where
F: Unpin,
R: Unpin,
<F as ObjFunc>::Fitness: Unpin,
impl<F, R> UnwindSafe for Solver<F, R> where
F: UnwindSafe,
R: UnwindSafe,
<F as ObjFunc>::Fitness: UnwindSafe,
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