moonlander_gp

Struct Population

Source
pub struct Population<P: Clone + Sync, F: Fitness + Sized + Send> {
    pub population: Vec<P>,
    pub generation: u32,
    pub scores: Vec<F>,
}
Expand description

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

Implementations§

Source§

impl<P: Clone + Sync, F: Fitness + Sized + Send> Population<P, F>

Source

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

Source

pub fn add(&mut self, program: P)

Add a single program to the population.

Source

pub fn n(&self) -> usize

Source

pub fn score<S>(&mut self, scoring_fn: S, _: &mut dyn Rng)
where S: Fn(&P, &mut dyn Rng) -> F + Sync,

Apply a scoring function to the entire population.

Source

pub fn avg_score(&self) -> Number

Source

pub fn best_score(&self) -> Number

Source

pub fn champion<'a>(&'a self) -> CreatureScore<'a, P, F>
where P: Encodable, F: Encodable,

Return the best program from the population.

Source

pub fn best_n<'a>(&self, n: usize) -> Vec<P>

Return the best N programs from the population.

Auto Trait Implementations§

§

impl<P, F> Freeze for Population<P, F>

§

impl<P, F> RefUnwindSafe for Population<P, F>

§

impl<P, F> Send for Population<P, F>
where P: Send,

§

impl<P, F> Sync for Population<P, F>
where F: Sync,

§

impl<P, F> Unpin for Population<P, F>
where P: Unpin, F: Unpin,

§

impl<P, F> UnwindSafe for Population<P, F>
where P: UnwindSafe, F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Any for T
where T: Any + ?Sized,