Skip to main content

Module memetic

Module memetic 

Source
Expand description

Memetic-algorithm strategy adapter.

A memetic algorithm (MA) interleaves a population-level evolutionary Strategy with a per-individual LocalSearch that polishes promising genomes between an inner strategy’s ask and tell. MemeticWrapper makes that interleaving a zero-cost-to-adopt upgrade: wrap any existing Strategy<B, Genome = Tensor<B, 2>> together with any LocalSearch<B> and the wrapper itself implements Strategy<B>, so it drops straight into EvolutionaryHarness.

§Lamarckian / Baldwinian / Partial refinement

After the inner strategy proposes a population, the wrapper refines a subset of individuals (the CoveragePolicy) and then decides — per the WritebackPolicy — whether each refined genome is written back into the population handed to the inner tell:

  • Lamarckian — refined genome and refined fitness flow to tell. The inherited traits (the genome) change.
  • Baldwinian — the original genome flows to tell but carries the refined fitness. The phenotype’s learned advantage shows up as fitness pressure without altering the inherited genome.
  • Partial(p) — each refined individual is written back Lamarckian-style with probability p (drawn per refined individual), Baldwinian otherwise.

Regardless of policy, the refined fitness always replaces the original fitness for covered rows — Baldwinian differs only in that the genome is left untouched.

§Intentional break of the Strategy purity convention

Strategy documents itself as pure: ask/tell take &self and carry no interior mutability so many instances can run in parallel without locks. This wrapper deliberately breaks that convention. It holds a parking_lot::Mutex around its fitness function because local search needs &mut F (an FitnessFn is &mut self) while tell only has &self. The lock is wrapper-private and uncontended in the single-harness driving model (one tell in flight at a time), so it costs an uncontended lock/unlock per generation and never blocks. A reader writing code generic over S: Strategy<B> should be aware that MemeticWrapper is not a pure, lock-free strategy like the others in this crate.

§RNG discipline

All refinement randomness flows through seed_stream; the wrapper never touches the process-wide backend RNG. See the tell flow for the two-stream scheme that makes Partial(1.0) bit-identical to Lamarckian and Partial(0.0) to Baldwinian.

Structs§

MemeticParams
Static parameters for a MemeticWrapper run.
MemeticState
Generation-to-generation state for a MemeticWrapper.
MemeticWrapper
Wraps an inner Strategy with per-individual LocalSearch refinement.

Enums§

CoveragePolicy
Determines which population members are refined each generation.
WritebackPolicy
Controls how a refined genome’s gains are written back into the population.