Skip to main content

Terminal

Trait Terminal 

Source
pub trait Terminal:
    Clone
    + Send
    + Sync
    + PartialEq
    + Debug
    + Serialize
    + for<'de> Deserialize<'de>
    + 'static {
    // Required methods
    fn random<R: Rng>(rng: &mut R) -> Self;
    fn terminals() -> &'static [Self];
    fn evaluate(&self, variables: &[f64]) -> f64;
    fn to_string(&self) -> String;
    fn encode(&self) -> (f64, f64);
    fn decode(type_code: f64, payload: f64) -> Self;
}
Expand description

Trait for terminal nodes in GP trees

Required Methods§

Source

fn random<R: Rng>(rng: &mut R) -> Self

Generate a random terminal

Source

fn terminals() -> &'static [Self]

Get the set of available terminals

Source

fn evaluate(&self, variables: &[f64]) -> f64

Evaluate this terminal with the given variable bindings

Source

fn to_string(&self) -> String

Convert to string representation

Source

fn encode(&self) -> (f64, f64)

Encode this terminal as a (type_code, payload) pair for lossless trace round-tripping.

type_code identifies the terminal variant (a discriminant) and payload carries its associated value. The pair must satisfy the inverse relationship Self::decode(self.encode()) == *self so that TreeGenome::from_trace reproduces the exact terminal that TreeGenome::to_trace serialized.

Source

fn decode(type_code: f64, payload: f64) -> Self

Decode a terminal previously produced by encode.

This is the inverse of encode and must reconstruct an equal terminal for any (type_code, payload) this type emits.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§