Struct metaheuristics_nature::Ctx
source · #[non_exhaustive]pub struct Ctx<F: ObjFunc> {
pub best: <F::Ys as Fitness>::Best<F::Ys>,
pub pool: Vec<Vec<f64>>,
pub pool_y: Vec<F::Ys>,
pub func: F,
pub gen: u64,
}
Expand description
A basic context type of the algorithms.
This type provides a shared dataset if you want to implement a new method. The fields maybe expanded in the future, so it marked as non-exhaustive.
§View the Progress
You can view the progress from the SolverBuilder::task()
and
SolverBuilder::callback()
.
ctx.gen
- Get generation number.ctx.pop_num()
- Get population number.ctx.best.get_eval()
- Get the current best evaluation value.ctx.best.get_xs()
- Get the current best variables.
§Implement an Algorithm
Do everything you want to do with the context. Please see Algorithm
for
the implementation.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.best: <F::Ys as Fitness>::Best<F::Ys>
Best container
pool: Vec<Vec<f64>>
Current variables of all individuals
pool_y: Vec<F::Ys>
Current fitness values of all individuals
func: F
Objective function object
gen: u64
Generation (iteration) number
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<F> Freeze for Ctx<F>
impl<F> RefUnwindSafe for Ctx<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 Ctx<F>
impl<F> Sync for Ctx<F>
impl<F> Unpin for Ctx<F>
impl<F> UnwindSafe for Ctx<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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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