[][src]Struct jeans::Settings

pub struct Settings {
    pub population_size: u32,
    pub number_of_generations: u32,
    pub crossover_probability: f64,
    pub mutation_probability: f64,
    pub verbose: bool,
    pub elitism: bool,
    pub elitism_fraction: f64,
    pub maximize_fitness: bool,
    pub number_of_dimensions: u32,
    pub upper_bound: Vec<f64>,
    pub lower_bound: Vec<f64>,
    pub fitness_function: Box<dyn FnMut(Vec<f64>) -> f64>,
}

A settings object for storing all of the settings we might care about for a GA.

You should usually instantiate this using the default method. All member variables of this struct are public, which makes editing this easy. In most cases, simply reassign the member variables:

let mut set = jeans::Settings::default();
set.elitism = false;

The most notable exception is for the fitness_function field. To set that, you have to use a special method:

let mut set = jeans::Settings::default();
set.set_fitness_function(| x: Vec<f64> | x[0] + x[1])

Fields

population_size: u32

The size of the population

number_of_generations: u32

The number of generations

crossover_probability: f64

The crossover probability

mutation_probability: f64

The probability of mutation

verbose: bool

A bool indicating whether or not code should run in verbose mode

elitism: bool

A bool indicating whether or not to implement elitism

elitism_fraction: f64

The fraction of each generation that should be carried forward via elitism

maximize_fitness: bool

Whether the package should maximize fitness (true) or minimize fitness (false)

number_of_dimensions: u32

The number of dimensions of the problem space

upper_bound: Vec<f64>

The upper bounds for each dimension of the problem space

lower_bound: Vec<f64>

The lower bounds for each dimension of the problem space

fitness_function: Box<dyn FnMut(Vec<f64>) -> f64>

The fitness function used to evaluate how good solutions are

Implementations

impl Settings[src]

pub fn set_fitness_function<F: 'static + FnMut(Vec<f64>) -> f64>(
    &mut self,
    f: F
)
[src]

This functions allows you to set the fitness function

For instance, you can use one of hte built-in function found here:

let mut set = jeans::Settings::default();
set.set_fitness_function(jeans::functions::sphere);

Or you can use a lambda to implement your own:

let mut set = jeans::Settings::default();
set.set_fitness_function(| x | x[0] + x[1]);

Or you can define and use a completely new function

fn fitness_whole_pizza(x: Vec<f64>) -> f64 {
    let mut fx = 0f64;
    for i in 0..x.len() {
        fx *= x[i]
    }
    fx
}
let mut set = jeans::Settings::default();
set.set_fitness_function(fitness_whole_pizza);

Trait Implementations

impl Default for Settings[src]

Default values for all settings

Auto Trait Implementations

impl !RefUnwindSafe for Settings

impl !Send for Settings

impl !Sync for Settings

impl Unpin for Settings

impl !UnwindSafe for Settings

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,