pub trait SearchAlgorithm:
Send
+ Sync
+ Debug {
// Required methods
fn name(&self) -> &'static str;
fn initialize(
&mut self,
population: Vec<Chromosome>,
gene_pool: &GenePool,
rng: &mut StdRng,
);
fn request_evaluations(
&mut self,
n: usize,
rng: &mut StdRng,
) -> Vec<EvalCandidate>;
fn submit_evaluations(&mut self, results: Vec<(u64, OracleVerdict)>);
fn should_terminate(&self, stats: &SearchStats, budget: &Budget) -> bool;
fn best(&self) -> Option<&Chromosome>;
fn checkpoint(&self) -> Result<Vec<u8>, EvolutionError>;
fn restore(&mut self, bytes: &[u8]) -> Result<(), EvolutionError>;
// Provided methods
fn population_snapshot(&self) -> Vec<Chromosome> { ... }
fn clone_box(&self) -> Box<dyn SearchAlgorithm> { ... }
}Expand description
Core trait implemented by all search algorithms.
Each algorithm manages its own internal state (population, archive,
temperature, tabu list, etc.). The EvolutionEngine
handles caching, budgeting, and batching on top of this trait.
Required Methods§
Sourcefn initialize(
&mut self,
population: Vec<Chromosome>,
gene_pool: &GenePool,
rng: &mut StdRng,
)
fn initialize( &mut self, population: Vec<Chromosome>, gene_pool: &GenePool, rng: &mut StdRng, )
Initialize the algorithm with a seed population.
Sourcefn request_evaluations(
&mut self,
n: usize,
rng: &mut StdRng,
) -> Vec<EvalCandidate>
fn request_evaluations( &mut self, n: usize, rng: &mut StdRng, ) -> Vec<EvalCandidate>
Request up to n candidates for parallel evaluation.
Returns candidates with stable IDs. The caller evaluates them and
later calls submit_evaluations.
Sourcefn submit_evaluations(&mut self, results: Vec<(u64, OracleVerdict)>)
fn submit_evaluations(&mut self, results: Vec<(u64, OracleVerdict)>)
Submit evaluation results.
The ID in each tuple must match an ID previously returned by
request_evaluations.
Sourcefn should_terminate(&self, stats: &SearchStats, budget: &Budget) -> bool
fn should_terminate(&self, stats: &SearchStats, budget: &Budget) -> bool
Check whether the algorithm thinks search should stop.
Sourcefn best(&self) -> Option<&Chromosome>
fn best(&self) -> Option<&Chromosome>
Get the best chromosome found so far.
Sourcefn checkpoint(&self) -> Result<Vec<u8>, EvolutionError>
fn checkpoint(&self) -> Result<Vec<u8>, EvolutionError>
Serialize internal state to bytes.
Provided Methods§
Sourcefn population_snapshot(&self) -> Vec<Chromosome>
fn population_snapshot(&self) -> Vec<Chromosome>
Snapshot the algorithm’s current “live” chromosomes — the set the engine is actively searching from.
Population-based algorithms (NoveltySearch, MapElites)
return their full pool. Single-state algorithms (HillClimbing,
SimulatedAnnealing, TabuSearch) return the singleton
current/best so the engine sees len() == 1 and reports
“no pairwise diversity yet” rather than zero.
Used by EvolutionEngine::diversity_score
to drive adaptive mutation pressure. Cloning is acceptable here
because callers run it at engine-tick rate, not per-evaluation.
Sourcefn clone_box(&self) -> Box<dyn SearchAlgorithm>
fn clone_box(&self) -> Box<dyn SearchAlgorithm>
Deep-clone this algorithm into a fresh trait object.
The default implementation falls back to a checkpoint →
restore round-trip via serde_json — correct for any
algorithm that implements those, but slow on large grids /
archives because every chromosome is JSON-serialised.
Concrete algorithms override this with a direct in-memory
Clone to bypass the serde round-trip — typically 10-100×
faster on populated state. The override is what
EvolutionEngine::clone
uses on the proxy path, where allocation spikes from JSON
were the original blocker.