Trait metaheuristics_nature::ObjFunc [−][src]
The base of the objective function.
For example:
use metaheuristics_nature::ObjFunc; struct MyFunc(Vec<f64>, Vec<f64>); impl MyFunc { fn new() -> Self { Self(vec![0.; 3], vec![50.; 3]) } } impl ObjFunc for MyFunc { type Result = f64; fn fitness(&self, _gen: u32, v: &Vec<f64>) -> f64 { v[0] * v[0] + v[1] * v[1] + v[2] * v[2] } fn result(&self, v: &Vec<f64>) -> f64 { self.fitness(0, v) } fn ub(&self) -> &Vec<f64> { &self.1 } fn lb(&self) -> &Vec<f64> { &self.0 } }
The objective function returns fitness value that used to evaluate the objective.
The lower bound and upper bound represents the number of variables at the same time.
This trait is designed as immutable.
Associated Types
Loading content...Required methods
fn fitness(&self, gen: u32, v: &Vec<f64>) -> f64
[src]
Return fitness, the smaller value represents good.
fn result(&self, v: &Vec<f64>) -> Self::Result
[src]
Return the final result of the problem.
fn ub(&self) -> &Vec<f64>
[src]
Get upper bound.
fn lb(&self) -> &Vec<f64>
[src]
Get lower bound.