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§

source§

impl<F: ObjFunc> Ctx<F>

source

pub fn pop_num(&self) -> usize

Get population number.

source

pub fn set_from(&mut self, i: usize, xs: Vec<f64>, ys: F::Ys)

Assign the index from source.

source

pub fn find_best(&mut self)

Find the best, and set it globally.

Trait Implementations§

source§

impl<F: ObjFunc> Deref for Ctx<F>

§

type Target = F

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<F> Freeze for Ctx<F>
where <<F as ObjFunc>::Ys as Fitness>::Best<<F as ObjFunc>::Ys>: Freeze, F: Freeze,

§

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>
where <<F as ObjFunc>::Ys as Fitness>::Best<<F as ObjFunc>::Ys>: Unpin, F: Unpin, <F as ObjFunc>::Ys: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> MaybeParallel for T
where T: Sync + Send,