BatchFitnessEvaluator

Struct BatchFitnessEvaluator 

Source
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

Source

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

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

Evaluates the fitness of unevaluated individuals in the ecosystem. Read more

Auto Trait Implementations§

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, 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.
Source§

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

Source§

fn vzip(self) -> V