Struct metaheuristics_nature::SolverBuilder

source ·
pub struct SolverBuilder<'a, A: Algorithm<F>, F: ObjFunc> { /* private fields */ }
Expand description

Collect configuration and build the solver.

This type is created by Solver::build() method.

Implementations§

source§

impl<'a, A: Algorithm<F>, F: ObjFunc> SolverBuilder<'a, A, F>

source

pub fn pop_num(self, pop_num: usize) -> Self

Population number.

§Default

If not changed by the algorithm setting, the default number is 200.

source

pub fn pareto_limit(self, pareto_limit: usize) -> Self
where F::Ys: Fitness<Best<F::Ys> = Pareto<F::Ys>>,

Pareto front limit.

It is not working for single-objective optimization.

use metaheuristics_nature::{Rga, Solver};

let s = Solver::build(Rga::default(), MyFunc::new())
    .seed(0)
    .task(|ctx| ctx.gen == 20)
    .pareto_limit(10)
    .solve();
§Default

By default, there is no limit. The limit is set to usize::MAX.

source

pub fn seed(self, seed: impl Into<SeedOpt>) -> Self

Set a fixed random seed to get a determined result.

§Default

By default, the random seed is auto-decided so you cannot reproduce the result. Please print the seed via Solver::seed() method to get the seed that used in the algorithm.

source

pub fn init_pool(self, pool: Pool<'a, F>) -> Self

Initialize the pool with the pool option.

§Default

By default, the pool is generated by the uniform distribution uniform_pool().

source

pub fn task<'b, C>(self, task: C) -> SolverBuilder<'b, A, F>
where C: FnMut(&Ctx<F>) -> bool + Send + 'b, 'a: 'b,

Termination condition.

The task function will be check each iteration, breaks if the return is true.

use metaheuristics_nature::{Rga, Solver};

let s = Solver::build(Rga::default(), MyFunc::new())
    .seed(0)
    .task(|ctx| ctx.gen == 20)
    .solve();
§Default

By default, the algorithm will iterate 200 generation.

source

pub fn callback<'b, C>(self, callback: C) -> SolverBuilder<'b, A, F>
where C: FnMut(&Ctx<F>) + Send + 'b, 'a: 'b,

Set callback function.

Callback function allows to change an outer mutable variable in each iteration.

use metaheuristics_nature::{Rga, Solver};

let mut report = Vec::with_capacity(20);
let s = Solver::build(Rga::default(), MyFunc::new())
    .seed(0)
    .task(|ctx| ctx.gen == 20)
    .callback(|ctx| report.push(ctx.best.get_eval()))
    .solve();
§Default

By default, this function does nothing.

source

pub fn solve(self) -> Solver<F>

Create the task and run the algorithm, which may takes a lot of time.

Generation ctx.gen is start from 1, initialized at 0.

§Panics

Panics before starting the algorithm if the following conditions are met:

  • The dimension size is zero.
  • The lower bound is greater than the upper bound.
  • Using the Pool::Ready option and the pool size or dimension size is not consistent.

Auto Trait Implementations§

§

impl<'a, A, F> Freeze for SolverBuilder<'a, A, F>
where F: Freeze, A: Freeze,

§

impl<'a, A, F> !RefUnwindSafe for SolverBuilder<'a, A, F>

§

impl<'a, A, F> Send for SolverBuilder<'a, A, F>

§

impl<'a, A, F> !Sync for SolverBuilder<'a, A, F>

§

impl<'a, A, F> Unpin for SolverBuilder<'a, A, F>
where F: Unpin, A: Unpin, <F as ObjFunc>::Ys: Unpin,

§

impl<'a, A, F> !UnwindSafe for SolverBuilder<'a, A, F>

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