1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
//! A trait that lets us operate on structures, treating them like a "genome" //! so we can "mutate" and "cross" them with other structures use rand::Rng; /// Interface for randomly mutating, crossing over, and creating a genome used /// in genetic algorithms pub trait Genome { /// Create an entirely random `Genome` fn genesis<R>(rng: &mut R) -> Self where R: Rng; /// Randomly mutate a single "gene" in the genome fn mutate<R>(&self, rate: f32, rng: &mut R) -> Self where R: Rng; /// Cross this orgnanism with another /// /// # Arguments /// * `other`: the "mate" of this organism that will cross genomes fn cross<R>(&self, other: &Self, rng: &mut R) -> Self where R: Rng; /// Get the fitness of the organism fn fitness<T>(&self) -> T where T: Ord; }