Trait metaheuristics_nature::Algorithm[][src]

pub trait Algorithm<F: ObjFunc> {
    fn base(&self) -> &AlgorithmBase<F>;
fn base_mut(&mut self) -> &mut AlgorithmBase<F>;
fn generation(&mut self); fn init(&mut self) { ... }
fn lb(&self, i: usize) -> f64 { ... }
fn ub(&self, i: usize) -> f64 { ... }
fn assign_from(&mut self, i: usize, f: f64, v: Vec<f64>) { ... }
fn set_best(&mut self, i: usize) { ... }
fn find_best(&mut self) { ... }
fn init_pop(&mut self) { ... }
fn check(&self, s: usize, v: f64) -> f64 { ... } }

The methods of the metaheuristic algorithms.

This trait is extendable. Create a structure and store a AlgorithmBase member to implement it.

use metaheuristics_nature::{AlgorithmBase, Algorithm, ObjFunc, Setting};
struct MyAlgorithm<F: ObjFunc> {
    tmp: Vec<f64>,
    base: AlgorithmBase<F>,
}
impl<F: ObjFunc> MyAlgorithm<F> {
    fn new(func: F, settings: Setting) -> Self {
        let base = AlgorithmBase::new(func, settings);
        Self {
            tmp: vec![],
            base,
        }
    }
}
impl<F: ObjFunc> Algorithm<F> for MyAlgorithm<F> {
    fn base(&self) -> &AlgorithmBase<F> { &self.base }
    fn base_mut(&mut self) -> &mut AlgorithmBase<F> { &mut self.base }
    fn generation(&mut self) { unimplemented!() }
}

Your algorithm will be implemented Solver automatically.

Required methods

fn base(&self) -> &AlgorithmBase<F>[src]

Return a base handle.

fn base_mut(&mut self) -> &mut AlgorithmBase<F>[src]

Return a mutable base handle.

fn generation(&mut self)[src]

Processing implementation of each generation.

Loading content...

Provided methods

fn init(&mut self)[src]

Initialization implementation.

fn lb(&self, i: usize) -> f64[src]

Get lower bound with index.

fn ub(&self, i: usize) -> f64[src]

Get upper bound with index.

fn assign_from(&mut self, i: usize, f: f64, v: Vec<f64>)[src]

Assign from source.

fn set_best(&mut self, i: usize)[src]

Set the index to best.

fn find_best(&mut self)[src]

Find the best, and set it globally.

fn init_pop(&mut self)[src]

Initialize population.

fn check(&self, s: usize, v: f64) -> f64[src]

Check the bounds.

Loading content...

Implementors

impl<F: ObjFunc> Algorithm<F> for DE<F>[src]

impl<F: ObjFunc> Algorithm<F> for FA<F>[src]

impl<F: ObjFunc> Algorithm<F> for PSO<F>[src]

impl<F: ObjFunc> Algorithm<F> for RGA<F>[src]

impl<F: ObjFunc> Algorithm<F> for TLBO<F>[src]

Loading content...