pub enum Op<T> {
Fn(&'static str, Arity, fn(&[T]) -> T),
Var(&'static str, usize),
Const(&'static str, T),
MutableConst {
name: &'static str,
arity: Arity,
value: T,
supplier: fn() -> T,
modifier: fn(&T) -> T,
operation: fn(&[T], &T) -> T,
},
}Expand description
Op is an enumeration that represents the different types of operations that can be performed within the genetic programming framework. Each variant of the enum encapsulates a different kind of operation, allowing for a flexible and extensible way to define the behavior of nodes within trees and graphs.
The Op heavilty depends on it’s Arity to define how many inputs it expects. This is crucial for ensuring that the operations receive the correct number of inputs and that the structures built using these operations are built in ways that respect these input requirements. For example, an addition operation would typically have an arity of 2, while a constant operation would have an arity of 0. This is the base level of the GP system, meaning that everything built on top of it (trees, graphs, etc.) will relies heavily on how these operations are defined and used.
Variants§
Fn(&'static str, Arity, fn(&[T]) -> T)
- A stateless function operation:
§Arguments
- A
&'static strname (e.g., “Add”, “Sigmoid”) - Arity (how many inputs it takes)
- Arc<dyn Fn(&
\[T\]) -> T> for the actual function logic
Var(&'static str, usize)
- A variable-like operation:
§Arguments
String= a name or identifierusize= an index to retrieve from some external context
Const(&'static str, T)
- A compile-time constant: e.g., 1, 2, 3, etc.
§Arguments
&'static strnameTthe actual constant value
MutableConst
- A
mutable constis a constant that can change over time:
§Arguments
-
&'static strname -
Arityof how many inputs it might read -
Current value of type
T -
An
Arc<dyn Fn() -> T>for retrieving (or resetting) the value -
An
Arc<dyn Fn(&[T], &T) -> T>for updating or combining inputs & old value -> new valueThis suggests a node that can mutate its internal state over time, or one that needs a special function to incorporate the inputs into the next state.