pub struct BatchFitnessEvaluator { /* private fields */ }
Expand description
A fitness evaluator that evaluates individuals in batches for improved performance or for when you need access to parts or the whole of an unevaluated population in order to compute fitness.
BatchFitnessEvaluator groups individuals into batches and evaluates them together, which can be more efficient than individual evaluation, especially when the problem supports batch evaluation or when there are significant overhead costs per evaluation.
§Performance Characteristics
- Batch Processing: Multiple individuals evaluated together
- Reduced Overhead: Sometimes lower per-individual evaluation cost
§Use Cases
Use BatchFitnessEvaluator when:
- The problem supports efficient batch evaluation
- You have a large population that benefits from parallelization
- Individual evaluation overhead is significant
- You need access to parts or the whole of an unevaluated population in order to compute fitness.
§Batch Size Calculation
In order to ensure the optimal distribution of work across available threads, batch size is automatically calculated based on the number of workers in the executor and the total number of individuals to evaluate:
batch_size = (total_individuals + num_workers - 1) / num_workers
So, for example, if you have 100 individuals and 4 workers, the batch size would be:
batch_size = (100 + 4 - 1) / 4 = 25
But, if your executor is Executor::Serial, then the batch size will simply be the total number of individuals to evaluate, resulting in a single batch.
Implementations§
Source§impl BatchFitnessEvaluator
impl BatchFitnessEvaluator
Sourcepub fn new(executor: Arc<Executor>) -> Self
pub fn new(executor: Arc<Executor>) -> Self
Creates a new batch fitness evaluator with the specified executor.
§Arguments
executor
- The executor to use for running batch evaluations
§Returns
A new BatchFitnessEvaluator instance
§Note
Batch evaluation works best with parallel executors that have multiple worker threads. The evaluator will automatically divide work into optimal batch sizes based on the number of available workers.
Trait Implementations§
Source§impl<C, T> Evaluator<C, T> for BatchFitnessEvaluatorwhere
C: Chromosome + 'static,
T: 'static,
Implementation of Evaluator for BatchFitnessEvaluator.
impl<C, T> Evaluator<C, T> for BatchFitnessEvaluatorwhere
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
:
- Collect Unevaluated Individuals: Find individuals without fitness scores
- Calculate Batch Size: Determine optimal batch size based on worker count
- Create Batches: Group individuals into batches for parallel processing
- Execute Batches: Run batch evaluations through the executor
- 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