Trait metaheuristics_nature::Algorithm[][src]

pub trait Algorithm<F: ObjFunc> {
    fn base(&self) -> &AlgorithmBase<F>;
fn base_mut(&mut self) -> &mut AlgorithmBase<F>;
fn init(&mut self);
fn generation(&mut self); fn lb(&self, i: usize) -> f64 { ... }
fn ub(&self, i: usize) -> f64 { ... }
fn assign(&mut self, i: usize, j: usize) { ... }
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 { ... }
fn report(&mut self) { ... }
fn history(&self) -> Vec<Report> { ... }
fn result(&self) -> (Vec<f64>, f64) { ... }
fn run(&mut self) -> F::Result { ... } }

The methods of the meta-heuristic algorithms.

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

use meta_heuristics::{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 init(&mut self) { unimplemented!() }
    fn generation(&mut self) { unimplemented!() }
}

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 init(&mut self)[src]

Initialization implementation.

fn generation(&mut self)[src]

Processing implementation of each generation.

Loading content...

Provided methods

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(&mut self, i: usize, j: usize)[src]

Assign i to j.

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.

fn report(&mut self)[src]

Record the performance.

fn history(&self) -> Vec<Report>[src]

Get the history for plotting.

fn result(&self) -> (Vec<f64>, f64)[src]

Return the x and y of function.

fn run(&mut self) -> F::Result[src]

Start the algorithm.

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...