pub struct SimpleGA<G, F, S, C, M, Fit, Term>where
G: EvolutionaryGenome,
F: FitnessValue,{ /* 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>,
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>,
Sourcepub fn tuner(&self) -> Option<&ThompsonSamplingTuner>
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.
Sourcepub fn run_adaptive<R: Rng>(
&mut self,
rng: &mut R,
) -> Result<EvolutionResult<G, F>, EvolutionError>
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>,
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>,
Sourcepub fn run<R: Rng>(
&self,
rng: &mut R,
) -> Result<EvolutionResult<G, F>, EvolutionError>
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>,
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>,
Sourcepub fn run_bounded<R: Rng>(
&self,
rng: &mut R,
) -> Result<EvolutionResult<G, F>, EvolutionError>
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>,
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>,
Sourcepub fn init_run<R: Rng>(
&self,
rng: &mut R,
) -> Result<SimpleGaRun<G, F>, EvolutionError>
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).
Sourcepub fn step_generation<R: Rng>(
&self,
state: &mut SimpleGaRun<G, F>,
rng: &mut R,
) -> Result<bool, EvolutionError>
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.
Sourcepub fn finish_run(&self, state: SimpleGaRun<G, F>) -> EvolutionResult<G, F>
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.
Sourcepub fn inject_migrants(&self, state: &mut SimpleGaRun<G, F>, migrants: Vec<G>)
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).
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).
Sourcepub fn checkpoint_run<R>(
&self,
state: &SimpleGaRun<G, f64>,
rng: &R,
) -> Result<Checkpoint<G>, CheckpointError>where
R: SnapshotRng,
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.
Sourcepub fn resume<R>(
&self,
checkpoint: &Checkpoint<G>,
) -> Result<(SimpleGaRun<G, f64>, R), CheckpointError>where
R: SnapshotRng,
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.
Sourcepub fn run_from_checkpoint<R>(
&self,
checkpoint: &Checkpoint<G>,
) -> Result<EvolutionResult<G, f64>, EvolutionError>where
R: SnapshotRng + Rng,
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>
impl<G, F, S, C, M, Fit, Term> RefUnwindSafe for SimpleGA<G, F, S, C, M, Fit, Term>where
S: RefUnwindSafe,
C: RefUnwindSafe,
M: RefUnwindSafe,
Fit: RefUnwindSafe,
Term: RefUnwindSafe,
G: RefUnwindSafe,
F: RefUnwindSafe,
impl<G, F, S, C, M, Fit, Term> Send for SimpleGA<G, F, S, C, M, Fit, Term>
impl<G, F, S, C, M, Fit, Term> Sync for SimpleGA<G, F, S, C, M, Fit, Term>
impl<G, F, S, C, M, Fit, Term> Unpin for SimpleGA<G, F, S, C, M, Fit, Term>
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>where
S: UnwindSafe,
C: UnwindSafe,
M: UnwindSafe,
Fit: UnwindSafe,
Term: UnwindSafe,
G: UnwindSafe,
F: UnwindSafe,
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
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.