Struct metaheuristics_nature::Solver
source · pub struct Solver<F: ObjFunc> { /* 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
Ctx
.
The builder of this type can infer the algorithm by AlgCfg::Algorithm
.
Please use Solver::build()
method to start a task.
The settings are defined in the SolverBuilder
type.
Implementations§
source§impl<F: ObjFunc> Solver<F>
impl<F: ObjFunc> Solver<F>
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 as_best_set(&self) -> &<F::Ys as Fitness>::Best<F::Ys>
pub fn as_best_set(&self) -> &<F::Ys as Fitness>::Best<F::Ys>
Get the reference of the best set.
Use Solver::as_best()
to get the best parameters and the fitness
value directly.
sourcepub fn as_best(&self) -> (&[f64], &F::Ys)
pub fn as_best(&self) -> (&[f64], &F::Ys)
Get the reference of the best parameters and the fitness value.
sourcepub fn as_best_xs(&self) -> &[f64]
pub fn as_best_xs(&self) -> &[f64]
Get the reference of the best fitness value.
sourcepub fn as_best_fit(&self) -> &F::Ys
pub fn as_best_fit(&self) -> &F::Ys
Get the reference of the best fitness value.
sourcepub fn get_best_eval(&self) -> <F::Ys as Fitness>::Eval
pub fn get_best_eval(&self) -> <F::Ys as Fitness>::Eval
Get the final best fitness value.
sourcepub fn into_result<P, Fit: Fitness>(self) -> P
pub fn into_result<P, Fit: Fitness>(self) -> P
Get the final best element.
sourcepub fn into_err_result<P, Fit: Fitness>(self) -> (Fit::Eval, P)
pub fn into_err_result<P, Fit: Fitness>(self) -> (Fit::Eval, P)
Get the fitness value and the final result.
sourcepub fn into_err_result_func<P, Fit: Fitness>(self) -> (Fit::Eval, P, F)
pub fn into_err_result_func<P, Fit: Fitness>(self) -> (Fit::Eval, P, F)
Get the fitness value, final result and the objective function.
source§impl<F: ObjFunc> Solver<F>
impl<F: ObjFunc> Solver<F>
sourcepub fn build<A: AlgCfg>(
cfg: A,
func: F
) -> SolverBuilder<'static, A::Algorithm<F>, F>
pub fn build<A: AlgCfg>( cfg: A, func: F ) -> SolverBuilder<'static, A::Algorithm<F>, F>
Start to build a solver. Take a setting and setup the configurations.
The signature is something like Solver::build(Rga::default(), MyFunc::new())
. Please check the 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.
Use Solver::build_boxed()
for dynamic dispatching.
sourcepub fn build_boxed<A: AlgCfg>(cfg: A, func: F) -> SolverBox<'static, F>
pub fn build_boxed<A: AlgCfg>(cfg: A, func: F) -> SolverBox<'static, F>
Start to build a solver with a boxed algorithm, the dynamic dispatching.
This method allows you to choose the algorithm at runtime and mix them with the same type.
use metaheuristics_nature as mh;
let s = if use_ga {
mh::Solver::build_boxed(mh::Rga::default(), MyFunc::new())
} else {
mh::Solver::build_boxed(mh::De::default(), MyFunc::new())
};
Use Solver::build()
for optimized memory allocation and access.
Auto Trait Implementations§
impl<F> Freeze for Solver<F>
impl<F> RefUnwindSafe for Solver<F>where
<<F as ObjFunc>::Ys as Fitness>::Best<<F as ObjFunc>::Ys>: RefUnwindSafe,
F: RefUnwindSafe,
<F as ObjFunc>::Ys: RefUnwindSafe,
impl<F> Send for Solver<F>
impl<F> Sync for Solver<F>
impl<F> Unpin for Solver<F>
impl<F> UnwindSafe for Solver<F>where
<<F as ObjFunc>::Ys as Fitness>::Best<<F as ObjFunc>::Ys>: UnwindSafe,
F: UnwindSafe,
<F as ObjFunc>::Ys: UnwindSafe,
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
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more