Trait metaheuristics_nature::utility::Algorithm[][src]

pub trait Algorithm: Sized {
    fn generation<F: ObjFunc>(&mut self, ctx: &mut Context<F>);

    fn init<F: ObjFunc>(&mut self, ctx: &mut Context<F>) { ... }
}
Expand description

The methods of the metaheuristic algorithms.

  • First, use setting_builder! macro to build a “setting” type.
  • Second, implement Setting trait then indicate to a “method” type.
  • Last, implement Algorithm trait on the “method” type.

Usually, the “method” type that implements this trait will not leak from the API. All most common dataset is store in the Context type. So the “method” type is used to store the additional data if any.

use metaheuristics_nature::{setting_builder, utility::*, ObjFunc};

setting_builder! {
    pub struct MySetting {
        @base,
    }
}

impl Setting for MySetting {
    type Algorithm = Method;
    fn base(&self) -> &BasicSetting {
        &self.base
    }
    fn create(self) -> Self::Algorithm {
        Method
    }
}

pub struct Method;

impl Algorithm for Method {
    fn generation<F: ObjFunc>(&mut self, ctx: &mut Context<F>) {
        unimplemented!()
    }
}

Your algorithm will be implemented by Solver automatically. All you have to do is implement the “initialization” method and “generation” method, which are corresponded to the Algorithm::init and Algorithm::generation respectively.

Required methods

Processing implementation of each generation.

Provided methods

Initialization implementation.

The information of the Context can be obtained or modified at this phase preliminarily.

The default behavior is do nothing.

Implementors