Skip to main content

fx_durable_ga/models/
encodeable.rs

1use super::GeneBounds;
2use const_fnv1a_hash::fnv1a_hash_str_32;
3
4/// Trait for types that can be encoded as genomes for genetic algorithm optimization.
5/// Provides the interface between domain-specific types and the GA engine.
6pub trait Encodeable {
7    /// Unique name identifier for this type.
8    const NAME: &str;
9    /// Hash derived from the name for efficient type identification.
10    const HASH: i32 = fnv1a_hash_str_32(Self::NAME) as i32;
11
12    /// The decoded phenotype that will be passed to evaluators.
13    type Phenotype;
14
15    /// Returns the gene bounds that define the search space structure.
16    fn morphology() -> Vec<GeneBounds>;
17    /// Encodes an instance of this type into a genome representation.
18    fn encode(&self) -> Vec<i64>;
19    /// Decodes a genome into the phenotype for evaluation.
20    fn decode(genes: &[i64]) -> Self::Phenotype;
21}