pub struct ShapeGenotype {
pub rules: HashMap<String, RuleDef>,
}Expand description
Genetic encoding of a CGA shape grammar.
Wraps the rule table of an Interpreter so that the grammar can be
evolved by symbios-genetics algorithms. Parametric floats are mutated
with Gaussian jitter; crossover uses homologous BLX-α blending on rules
that share both name and op-sequence topology, or uniform crossover when
topologies differ.
Fields§
§rules: HashMap<String, RuleDef>Grammar rules: rule name → definition (declared parameters + variants). Parameter lists ride along unmutated so parameterized grammars round-trip through evolution intact.
Implementations§
Source§impl ShapeGenotype
impl ShapeGenotype
Sourcepub fn from_interpreter(interp: &Interpreter) -> Self
pub fn from_interpreter(interp: &Interpreter) -> Self
Snapshot the rule table from a live interpreter.
Sourcepub fn to_interpreter(&self) -> Interpreter
pub fn to_interpreter(&self) -> Interpreter
Build a fresh Interpreter from this genotype.
Does not copy seed, max_depth, max_terminals, or host
attributes — set those on the returned interpreter if your grammar
requires non-default values.
Trait Implementations§
Source§impl Clone for ShapeGenotype
impl Clone for ShapeGenotype
Source§fn clone(&self) -> ShapeGenotype
fn clone(&self) -> ShapeGenotype
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ShapeGenotype
impl Debug for ShapeGenotype
Source§impl<'de> Deserialize<'de> for ShapeGenotype
impl<'de> Deserialize<'de> for ShapeGenotype
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Genotype for ShapeGenotype
impl Genotype for ShapeGenotype
Source§fn mutate<R: Rng>(&mut self, rng: &mut R, rate: f32)
fn mutate<R: Rng>(&mut self, rng: &mut R, rate: f32)
Perturb parametric floats throughout the grammar.
Each mutable float is independently tested against rate. When
selected, Gaussian noise (Box-Muller) is applied and the result is
clamped to keep the grammar structurally valid:
| Op | Parameter | σ | Clamp |
|---|---|---|---|
Extrude(h) | h | 0.5 | > 0.1 |
Taper(t) | t | 0.1 | [0, 1] |
Scale(v) | each component | 0.2 | > 0.1 |
Translate(v) | each component | 0.5 | none |
Split slot sizes | size value | 0.3 | > 0.1 (or [0.01, 1] for Relative) |
Repeat tile_size | tile_size | 0.3 | > 0.1 |
Roof angle | angle (°) | 5.0 | [1, 89] |
Roof overhang | overhang | 0.2 | [0, 2] |
After per-slot jitter, each Split is repaired so that its absolute and
relative slot sums do not exceed their pre-mutation totals — this prevents
independent jitter from producing SplitOverflow errors at interpret time
(issue #27).
Source§fn crossover<R: Rng>(&self, other: &Self, rng: &mut R) -> Self
fn crossover<R: Rng>(&self, other: &Self, rng: &mut R) -> Self
Homologous BLX-α crossover (α = 0.5).
For each rule name shared by both parents:
- If both parents have the same number of variants and each variant pair has the same op-sequence topology (same variant discriminants in the same order), every float parameter is blended using BLX-α, producing offspring that explore slightly beyond the parental range.
- If the variant counts or topologies differ, the whole rule is inherited uniformly at random from one parent (50 / 50).
Rules present in only one parent are passed through to the child unchanged, so the child always has a complete, runnable grammar.
Auto Trait Implementations§
impl Freeze for ShapeGenotype
impl RefUnwindSafe for ShapeGenotype
impl Send for ShapeGenotype
impl Sync for ShapeGenotype
impl Unpin for ShapeGenotype
impl UnsafeUnpin for ShapeGenotype
impl UnwindSafe for ShapeGenotype
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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> ⓘ
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> ⓘ
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