neat_rs/
traits.rs

1
2/// Trait required for a genome to be used by neat
3pub trait Gene {
4    /// returns an empty genome with only input and output nodes and no connections
5    fn empty(inputs: usize, outputs: usize) -> Self;
6    /// checks if the other genome is same species as self
7    fn is_same_species_as(&self, other: &Self) -> bool;
8    /// method for cross over of two genomes
9    fn cross(&self, other: &Self) -> Self;
10    /// method for mutation of the genome
11    fn mutate<T: GlobalNeatCounter>(&mut self, neat: &mut T);
12    /// constructs the neural network and returns the output as a vec of floats
13    fn predict(&self, input: &[f64], activate: fn(f64) -> f64) -> Vec<f64>;
14}
15
16
17/// Trait required by neat struct
18pub trait GlobalNeatCounter {
19    /// returns the innovation number of new connection if a connection can be added, otherwise returns None
20    fn try_adding_connection(&mut self, from: usize, to: usize) -> Option<usize>;
21    /// returns the index of new node
22    fn get_new_node(&mut self) -> usize;
23}