Struct metaheuristics_nature::Fx

source ·
pub struct Fx<'b, 'f, Y: Fitness, const DIM: usize> { /* private fields */ }
Expand description

A quick interface help to create objective function from a callable object.

See also ObjFunc for implementing the full definitions.

use metaheuristics_nature::{Fx, Rga, Solver};

let bound = [[-50., 50.]; 4];
let f = Fx::new(&bound, |&[a, b, c, d]| a * a + 8. * b * b + c * c + d * d);
let s = Solver::build(Rga::default(), f)
    .seed(0)
    .task(|ctx| ctx.gen == 20)
    .solve();

Implementations§

source§

impl<'b, 'f, Y: Fitness, const DIM: usize> Fx<'b, 'f, Y, DIM>

source

pub fn new<F>(bound: &'b [[f64; 2]; DIM], func: F) -> Self
where F: Fn(&[f64; DIM]) -> Y + Sync + Send + 'f,

Create objective function from a callable object.

Trait Implementations§

source§

impl<Y: Fitness, const DIM: usize> Bounded for Fx<'_, '_, Y, DIM>

source§

fn bound(&self) -> &[[f64; 2]]

The upper bound and lower bound in [[lower, upper]; number_of_vars] form. Read more
source§

fn dim(&self) -> usize

Get the number of variables (dimension) of the problem.
source§

fn bound_of(&self, s: usize) -> [f64; 2]

Get the upper bound and the lower bound values.
source§

fn bound_width(&self, s: usize) -> f64

Get the width of the upper bound and the lower bound.
source§

fn bound_range(&self, s: usize) -> RangeInclusive<f64>

Get the upper bound and the lower bound as a range. Read more
source§

fn lb(&self, s: usize) -> f64

Get the lower bound.
source§

fn ub(&self, s: usize) -> f64

Get the upper bound.
source§

fn clamp(&self, s: usize, v: f64) -> f64

Check the bounds of the index s with the value v, and set the value to max and min if out of bound.
source§

impl<Y: Fitness, const DIM: usize> ObjFunc for Fx<'_, '_, Y, DIM>

§

type Ys = Y

Type of the fitness value. Read more
source§

fn fitness(&self, xs: &[f64]) -> Self::Ys

Return fitness, the smaller value represents a good result. Read more

Auto Trait Implementations§

§

impl<'b, 'f, Y, const DIM: usize> Freeze for Fx<'b, 'f, Y, DIM>

§

impl<'b, 'f, Y, const DIM: usize> !RefUnwindSafe for Fx<'b, 'f, Y, DIM>

§

impl<'b, 'f, Y, const DIM: usize> Send for Fx<'b, 'f, Y, DIM>

§

impl<'b, 'f, Y, const DIM: usize> Sync for Fx<'b, 'f, Y, DIM>

§

impl<'b, 'f, Y, const DIM: usize> Unpin for Fx<'b, 'f, Y, DIM>

§

impl<'b, 'f, Y, const DIM: usize> !UnwindSafe for Fx<'b, 'f, Y, DIM>

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,