Skip to main content

SimpleGA

Struct SimpleGA 

Source
pub struct SimpleGA<G, F, S, C, M, Fit, Term>{ /* private fields */ }
Expand description

Simple Genetic Algorithm

A standard generational GA with configurable operators.

Implementations§

Source§

impl<G, F, S, C, M, Fit, Term> SimpleGA<G, F, S, C, M, Fit, Term>
where G: EvolutionaryGenome, F: FitnessValue, S: SelectionOperator<G>, C: CrossoverOperator<G>, M: MutationOperator<G> + TunableMutation + Clone, Fit: Fitness<Genome = G, Value = F>, Term: TerminationCriterion<G, F>,

Source

pub fn tuner(&self) -> Option<&ThompsonSamplingTuner>

Access the online tuner.

Populated once run_adaptive has run, or immediately if the builder opted in via SimpleGABuilder::adaptive_operators.

Source

pub fn run_adaptive<R: Rng>( &mut self, rng: &mut R, ) -> Result<EvolutionResult<G, F>, EvolutionError>

Run the GA with online Thompson-sampling tuning of operator parameters.

Each generation the tuner Thompson-samples a per-gene mutation probability and a whole-genome crossover probability; those values drive that generation’s operators, and each offspring’s improvement over its parents is credited back to the arm that produced it. If the builder did not opt in via SimpleGABuilder::adaptive_operators, a default ThompsonConfig tuner is created on first use.

Source§

impl<G, F, S, C, M, Fit, Term> SimpleGA<G, F, S, C, M, Fit, Term>
where G: EvolutionaryGenome + Send + Sync, F: FitnessValue + Send, S: SelectionOperator<G>, C: CrossoverOperator<G>, M: MutationOperator<G>, Fit: Fitness<Genome = G, Value = F> + Sync, Term: TerminationCriterion<G, F>,

Source

pub fn builder() -> SimpleGABuilder<G, F, (), (), (), (), ()>

Create a builder for SimpleGA

Source

pub fn run<R: Rng>( &self, rng: &mut R, ) -> Result<EvolutionResult<G, F>, EvolutionError>

Run the genetic algorithm

Source§

impl<G, F, S, C, M, Fit, Term> SimpleGA<G, F, S, C, M, Fit, Term>
where G: EvolutionaryGenome + Send + Sync, F: FitnessValue + Send, S: SelectionOperator<G>, C: BoundedCrossoverOperator<G>, M: BoundedMutationOperator<G>, Fit: Fitness<Genome = G, Value = F> + Sync, Term: TerminationCriterion<G, F>,

Source

pub fn run_bounded<R: Rng>( &self, rng: &mut R, ) -> Result<EvolutionResult<G, F>, EvolutionError>

Run the genetic algorithm with bounded operators

Source§

impl<G, F, S, C, M, Fit, Term> SimpleGA<G, F, S, C, M, Fit, Term>
where G: EvolutionaryGenome, F: FitnessValue, S: SelectionOperator<G>, C: CrossoverOperator<G>, M: MutationOperator<G>, Fit: Fitness<Genome = G, Value = F>, Term: TerminationCriterion<G, F>,

Source

pub fn init_run<R: Rng>( &self, rng: &mut R, ) -> Result<SimpleGaRun<G, F>, EvolutionError>

Initialize an incremental run: build and evaluate the initial population and record generation-0 statistics.

The returned SimpleGaRun can then be advanced one generation at a time with SimpleGA::step_generation and consumed with SimpleGA::finish_run. This is the incremental counterpart to SimpleGA::run, letting callers (e.g. the WASM bindings) report progress and cancel early (AUDIT EV-34).

Source

pub fn step_generation<R: Rng>( &self, state: &mut SimpleGaRun<G, F>, rng: &mut R, ) -> Result<bool, EvolutionError>

Advance an incremental run by a single generation.

Returns Ok(true) if a generation was executed, or Ok(false) if the termination criterion fired (in which case state is left otherwise unchanged and marked terminated). This mirrors exactly one iteration of SimpleGA::run’s main loop, including the termination check performed before the generation body.

Source

pub fn finish_run(&self, state: SimpleGaRun<G, F>) -> EvolutionResult<G, F>

Consume an incremental run and produce the final EvolutionResult, mirroring the tail of SimpleGA::run.

Source

pub fn inject_migrants(&self, state: &mut SimpleGaRun<G, F>, migrants: Vec<G>)

Inject migrant genomes into an in-progress run, replacing the current worst individuals.

Each migrant is evaluated with this GA’s own fitness function (so a genome that emigrated from another island is scored under the receiving island’s objective) and overwrites one of the worst individuals in the population. The best-so-far individual is refreshed and the evaluation counter is advanced by the number of migrants accepted. Used to build island-model migration on top of the incremental stepping API (AUDIT EV-77).

Source§

impl<G, S, C, M, Fit, Term> SimpleGA<G, f64, S, C, M, Fit, Term>
where G: EvolutionaryGenome, S: SelectionOperator<G>, C: CrossoverOperator<G>, M: MutationOperator<G>, Fit: Fitness<Genome = G, Value = f64>, Term: TerminationCriterion<G, f64>,

Algorithm-level checkpoint/resume for bit-identical continuation (EV-02).

These build the library-provided resume path the checkpoint primitives were missing: instead of hand-rolling the generation loop (as the example and integration test previously had to), a caller drives an incremental run with SimpleGA::init_run/SimpleGA::step_generation, snapshots it with SimpleGA::checkpoint_run (capturing a SnapshotRng), and later restores it with SimpleGA::resume / SimpleGA::run_from_checkpoint. Because the ChaCha RNG state is captured and restored, resuming is bit-identical to an uninterrupted run.

Constrained to f64 fitness because Checkpoint serializes Individual<G> (fitness value f64).

Source

pub fn checkpoint_run<R>( &self, state: &SimpleGaRun<G, f64>, rng: &R, ) -> Result<Checkpoint<G>, CheckpointError>
where R: SnapshotRng,

Capture an in-progress incremental run into a Checkpoint for bit-identical resume (EV-02).

Serializes the population (with its generation counter), the tracked best individual, the evaluation count and the per-generation statistics, and captures the complete state of a SnapshotRng (the ChaCha family). Restoring the checkpoint via SimpleGA::resume and continuing with SimpleGA::step_generation reproduces the exact trajectory an uninterrupted run would have taken.

Source

pub fn resume<R>( &self, checkpoint: &Checkpoint<G>, ) -> Result<(SimpleGaRun<G, f64>, R), CheckpointError>
where R: SnapshotRng,

Resume an incremental run from a Checkpoint, restoring the population, best individual, evaluation count, statistics AND the captured SnapshotRng (EV-02).

Returns the reconstructed SimpleGaRun and the restored RNG; drive it forward with SimpleGA::step_generation/SimpleGA::finish_run (or use SimpleGA::run_from_checkpoint to continue straight to termination). The checkpoint MUST have been created with a captured RNG (via SimpleGA::checkpoint_run / Checkpoint::with_rng); otherwise this returns CheckpointError::Corrupted, because bit-identical resume is impossible without the RNG state.

Source

pub fn run_from_checkpoint<R>( &self, checkpoint: &Checkpoint<G>, ) -> Result<EvolutionResult<G, f64>, EvolutionError>
where R: SnapshotRng + Rng,

Resume from a Checkpoint and run to termination, returning the final EvolutionResult (EV-02).

A convenience over SimpleGA::resume followed by repeated SimpleGA::step_generation and SimpleGA::finish_run. Because the captured SnapshotRng is restored, this yields the bit-identical result of an uninterrupted run for the same seed and configuration.

Auto Trait Implementations§

§

impl<G, F, S, C, M, Fit, Term> Freeze for SimpleGA<G, F, S, C, M, Fit, Term>
where S: Freeze, C: Freeze, M: Freeze, Fit: Freeze, Term: Freeze,

§

impl<G, F, S, C, M, Fit, Term> RefUnwindSafe for SimpleGA<G, F, S, C, M, Fit, Term>

§

impl<G, F, S, C, M, Fit, Term> Send for SimpleGA<G, F, S, C, M, Fit, Term>
where S: Send, C: Send, M: Send, Fit: Send, Term: Send,

§

impl<G, F, S, C, M, Fit, Term> Sync for SimpleGA<G, F, S, C, M, Fit, Term>
where S: Sync, C: Sync, M: Sync, Fit: Sync, Term: Sync,

§

impl<G, F, S, C, M, Fit, Term> Unpin for SimpleGA<G, F, S, C, M, Fit, Term>
where S: Unpin, C: Unpin, M: Unpin, Fit: Unpin, Term: Unpin, G: Unpin, F: Unpin,

§

impl<G, F, S, C, M, Fit, Term> UnsafeUnpin for SimpleGA<G, F, S, C, M, Fit, Term>

§

impl<G, F, S, C, M, Fit, Term> UnwindSafe for SimpleGA<G, F, S, C, M, Fit, Term>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V