Evaluator

Trait Evaluator 

Source
pub trait Evaluator<C, T>: Send + Sync
where C: Chromosome,
{ // Required method fn eval( &self, ecosystem: &mut Ecosystem<C>, problem: Arc<dyn Problem<C, T>>, ) -> Result<usize, RadiateError>; }
Expand description

A trait for evaluating fitness of individuals in the ecosystem.

The Evaluator trait defines the interface for fitness evaluation strategies. Implementors can define different approaches to computing fitness scores, such as individual evaluation, batch evaluation, or specialized evaluation strategies for specific problem domains.

The two main implementations provided are:

  • FitnessEvaluator: Evaluates individuals one at a time
  • BatchFitnessEvaluator: Evaluates individuals in batches Custom evaluators can be created and used, however, take special note on how the members of the ecosystem are accessed and modified, (taken out of the phenotype then restored). This is important to ensure memory safety and avoid unnecessary cloning of genotypes.

§Generic Parameters

  • C: The chromosome type that represents the genetic material
  • T: The target type that the problem operates on

Required Methods§

Source

fn eval( &self, ecosystem: &mut Ecosystem<C>, problem: Arc<dyn Problem<C, T>>, ) -> Result<usize, RadiateError>

Evaluates the fitness of unevaluated individuals in the ecosystem.

This method processes individuals that don’t have fitness scores yet, evaluates them using the provided problem, and updates the ecosystem with the computed scores.

§Arguments
  • ecosystem - The ecosystem containing the population
  • problem - The problem instance used to evaluate fitness
§Returns

The number of individuals that were evaluated during this call

Implementors§

Source§

impl<C, T> Evaluator<C, T> for BatchFitnessEvaluator
where C: Chromosome + 'static, T: 'static,

Implementation of Evaluator for BatchFitnessEvaluator.

This implementation groups individuals into batches and evaluates them together, which can significantly improve performance for large populations or when the problem supports efficient batch evaluation.

§Algorithm

The algorithm largely follows the same steps as FitnessEvaluator:

  1. Collect Unevaluated Individuals: Find individuals without fitness scores
  2. Calculate Batch Size: Determine optimal batch size based on worker count
  3. Create Batches: Group individuals into batches for parallel processing
  4. Execute Batches: Run batch evaluations through the executor
  5. Update Ecosystem: Store computed scores and restore genotypes

§Batch Size Optimization

The batch size is calculated to ensure optimal work distribution:

  • Small Batches: Ensure all workers have work to do
  • Large Batches: Minimize overhead from job creation and distribution
  • Balanced Distribution: Work is evenly distributed across available threads

§Performance Optimizations

  • Efficient Batching: Batches are created with minimal memory allocation
  • Parallel Execution: Multiple batches are processed simultaneously
  • Memory Management: Genotypes are efficiently restored after evaluation
Source§

impl<C, T> Evaluator<C, T> for FitnessEvaluator
where C: Chromosome + 'static, T: 'static,

Implementation of Evaluator for FitnessEvaluator.

This implementation evaluates individuals one at a time, collecting unevaluated individuals and processing them through the executor system.

§Algorithm

  1. Collect Unevaluated Individuals: Find individuals without fitness scores
  2. Create Evaluation Jobs: Package genotypes and indices into jobs
  3. Execute Jobs: Run evaluations through the executor
  4. Update Ecosystem: Store computed scores and restore genotypes

§Performance Optimizations

  • Efficient Job Creation: Jobs are created with minimal allocation
  • Batch Execution: Multiple jobs are submitted to the executor at once
  • Memory Reuse: Genotypes are restored to avoid unnecessary cloning