Skip to main content

GaProblem

Trait GaProblem 

Source
pub trait GaProblem: Send + Sync {
    type Individual: Individual;

    // Required method
    fn evaluate(&self, individual: &mut Self::Individual);

    // Provided methods
    fn evaluate_parallel(&self, individuals: &mut [Self::Individual]) { ... }
    fn initialize_population<R: Rng>(
        &self,
        size: usize,
        rng: &mut R,
    ) -> Vec<Self::Individual> { ... }
    fn on_generation(
        &self,
        _generation: u32,
        _best: &Self::Individual,
        _population: &[Self::Individual],
    ) { ... }
}
Expand description

Trait for problem-specific GA operations.

Uses mutable evaluation: evaluate(&mut Individual) can set both fitness and auxiliary state on the individual.

Required Associated Types§

Source

type Individual: Individual

The individual type for this problem.

Required Methods§

Source

fn evaluate(&self, individual: &mut Self::Individual)

Evaluates the fitness of an individual (mutable — can set auxiliary state).

Provided Methods§

Source

fn evaluate_parallel(&self, individuals: &mut [Self::Individual])

Evaluates multiple individuals in parallel. Default implementation uses rayon when the parallel feature is enabled.

Source

fn initialize_population<R: Rng>( &self, size: usize, rng: &mut R, ) -> Vec<Self::Individual>

Creates an initial population.

Source

fn on_generation( &self, _generation: u32, _best: &Self::Individual, _population: &[Self::Individual], )

Called after each generation (for progress reporting).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§