Struct moonlander_gp::Population
[−]
[src]
pub struct Population<P: Clone + Sync, F: Fitness + Sized + Send> { pub population: Vec<P>, pub generation: u32, pub scores: Vec<F>, }
Collection of programs
The root of each program is of type P
, and fitness structures will be
represented by type F
.
Fields
population: Vec<P>
Collection of algorithms
generation: u32
Generation index of this population
scores: Vec<F>
Collection of fitness scores
Methods
impl<P: Clone + Sync, F: Fitness + Sized + Send> Population<P, F>
[src]
fn new(n: usize, generation: u32) -> Population<P, F>
Create a new population with an estimated size.
This does not create programs yet but simply allocates memory.
fn add(&mut self, program: P)
Add a single program to the population.
fn n(&self) -> usize
fn score<S>(&mut self, scoring_fn: S, _: &mut Rng) where
S: Fn(&P, &mut Rng) -> F + Sync,
S: Fn(&P, &mut Rng) -> F + Sync,
Apply a scoring function to the entire population.
fn avg_score(&self) -> Number
fn best_score(&self) -> Number
fn champion<'a>(&'a self) -> CreatureScore<'a, P, F> where
P: Encodable,
F: Encodable,
P: Encodable,
F: Encodable,
Return the best program from the population.
fn best_n<'a>(&self, n: usize) -> Vec<P>
Return the best N programs from the population.