radiate_rust/engines/codexes/
mod.rs1use super::genome::genes::gene::Gene;
2use super::genome::genotype::Genotype;
3use super::genome::population::Population;
4use super::genome::phenotype::Phenotype;
5
6pub mod char_codex;
7pub mod int_codex;
8pub mod float_codex;
9pub mod bit_codex;
10pub mod subset_codex;
11
12pub use char_codex::*;
13pub use int_codex::*;
14pub use float_codex::*;
15pub use bit_codex::*;
16pub use subset_codex::*;
17
18
19pub trait Codex<G, A, T>
20where
21 G: Gene<G, A>
22{
23 fn encode(&self) -> Genotype<G, A>;
24
25 fn decode(&self, genotype: &Genotype<G, A>) -> T;
26
27 fn spawn(&self, num: i32) -> Vec<T> {
28 (0..num)
29 .into_iter()
30 .map(|_| self.decode(&self.encode()))
31 .collect::<Vec<T>>()
32 }
33
34 fn spawn_genotypes(&self, num: i32) -> Vec<Genotype<G, A>> {
35 (0..num)
36 .into_iter()
37 .map(|_| self.encode())
38 .collect::<Vec<Genotype<G, A>>>()
39 }
40
41 fn spawn_population(&self, num: i32) -> Population<G, A> {
42 (0..num)
43 .into_iter()
44 .map(|_| Phenotype::from_genotype(self.encode(), 0))
45 .collect::<Population<G, A>>()
46 }
47}
48