pub struct GepDecoder;Expand description
The canonical Ferreira (2001) decoder: open-reading-frame scan, then level-order (breadth-first) tree construction.
§Algorithm
- ORF-length pass. A single left-to-right scan tracks the number of
still-unfilled child slots, starting at 1 (the root). Each symbol fills
one slot and opens
aritynew ones; the coding region ends when no slots remain. The tail-length constraint guarantees this terminates within the chromosome. - BFS child assignment. Because the coding prefix is already in level
order, a node’s children are simply the next unread symbols. A running
read cursor assigns each node
aritycontiguous children — no explicit queue is needed, since array order is BFS order.
§Examples
use rlevo_evolution::algorithms::gep::{Alphabet, GenotypePhenotypeMap, GepDecoder};
use rlevo_evolution::function_set::ArithmeticFunctionSet;
use rlevo_evolution::rng::{seed_stream, SeedPurpose};
// A one-variable arithmetic alphabet (functions over a single `x`).
let alphabet = Alphabet::new(ArithmeticFunctionSet, 1, vec![]);
// Sample a valid head/tail genome: head loci draw any symbol, tail loci
// draw terminals only, with the tail sized per Ferreira (2001) eq. 3.4.
let mut rng = seed_stream(42, 0, SeedPurpose::Mutation);
let head_len = 3;
let tail_len = head_len * (alphabet.max_arity() - 1) + 1;
let mut genome = Vec::with_capacity(head_len + tail_len);
for _ in 0..head_len {
genome.push(alphabet.sample_head_symbol(&mut rng));
}
for _ in 0..tail_len {
genome.push(alphabet.sample_tail_symbol(&mut rng));
}
// Decode the linear chromosome into its expression-tree phenotype.
let tree = GepDecoder.decode(&alphabet, &genome);
assert!(tree.node_count() >= 1);Trait Implementations§
Source§impl Clone for GepDecoder
impl Clone for GepDecoder
Source§fn clone(&self) -> GepDecoder
fn clone(&self) -> GepDecoder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for GepDecoder
Source§impl Debug for GepDecoder
impl Debug for GepDecoder
Source§impl Default for GepDecoder
impl Default for GepDecoder
Source§fn default() -> GepDecoder
fn default() -> GepDecoder
Returns the “default value” for a type. Read more
Source§impl<F: FunctionSet> GenotypePhenotypeMap<F> for GepDecoder
impl<F: FunctionSet> GenotypePhenotypeMap<F> for GepDecoder
Auto Trait Implementations§
impl Freeze for GepDecoder
impl RefUnwindSafe for GepDecoder
impl Send for GepDecoder
impl Sync for GepDecoder
impl Unpin for GepDecoder
impl UnsafeUnpin for GepDecoder
impl UnwindSafe for GepDecoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<C> CloneExpand for Cwhere
C: Clone,
impl<C> CloneExpand for Cwhere
C: Clone,
fn __expand_clone_method(&self, _scope: &mut Scope) -> C
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more