1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! Batch fitness evaluation trait for evaluating entire populations at once.
//!
//! [`BatchFitnessEvaluator`] is an alternative to the standard per-chromosome
//! fitness function. It allows the engine to pass a full slice of chromosomes
//! to a single evaluation call, which is useful for:
//!
//! - **Vectorised computation** (e.g. GPU shaders, SIMD, matrix math)
//! - **External simulators** that amortise setup cost over a batch
//! - **Multi-threaded external calls** where the user manages parallelism
//!
//! # Contract
//!
//! Implementors **must** return a `Vec<f64>` whose length equals
//! `chromosomes.len()`, with fitness values in the same positional order as
//! the input slice. Violating this contract will cause a panic in the engine
//! (enforced by `debug_assert_eq!` in Wave 2/3 caller).
use crateChromosomeT;
/// Trait for evaluating an entire population of chromosomes in a single call.
///
/// # Required implementation
///
/// ```text
/// fn evaluate_batch(&self, chromosomes: &[U]) -> Vec<f64>
/// ```
///
/// **Positional contract:** `result[i]` must be the fitness of `chromosomes[i]`.
/// The returned `Vec` must have the same length as the input slice.
///
/// # Thread safety
///
/// Implementors must be `Send + Sync` so that the evaluator can be stored in
/// an `Arc<dyn BatchFitnessEvaluator<U>>` and shared across engine threads.
///
/// # Example
///
/// ```rust,no_run
/// // no_run: stub implementation — not a runnable example
/// use genetic_algorithms::BatchFitnessEvaluator;
/// use genetic_algorithms::chromosomes::Range as RangeChromosome;
///
/// struct MyBatchEval;
///
/// impl BatchFitnessEvaluator<RangeChromosome<f64>> for MyBatchEval {
/// fn evaluate_batch(&self, chromosomes: &[RangeChromosome<f64>]) -> Vec<f64> {
/// // chromosomes.iter().map(|c| c.fitness).collect()
/// todo!()
/// }
/// }
/// ```