Engine

Trait Engine 

Source
pub trait Engine {
    type Epoch;

    // Required method
    fn next(&mut self) -> Self::Epoch;
}
Expand description

A trait representing an evolutionary computation engine. The Engine trait defines the fundamental interface for evolutionary algorithms. Implementors define how the algorithm progresses from one generation/epoch to the next, encapsulating the core evolutionary logic.

It is intentially esentially an iterator.

§Generic Parameters

  • Epoch: The type representing a single step or generation in the evolutionary process

§Examples

use radiate_core::engine::{Engine, EngineExt};

#[derive(Default)]
struct MyEngine {
    generation: usize,
    population: Vec<i32>,
}

#[derive(Debug, Clone)]
struct MyEpoch {
    generation: usize,
    population_size: usize,
}

impl Engine for MyEngine {
    type Epoch = MyEpoch;
     
    fn next(&mut self) -> Self::Epoch {
        // Perform one generation of evolution
        // ... evolve population ...
        self.generation += 1;
         
        MyEpoch {
            generation: self.generation,
            population_size: self.population.len()
        }
    }
}

// Use the engine with a termination condition
let mut engine = MyEngine::default();
let final_epoch = engine.run(|epoch| epoch.generation >= 10);
println!("Final generation: {}", final_epoch.generation);

§Design Philosophy

The Engine trait is intentionally minimal, focusing on the core concept of progression through evolutionary time. This allows for maximum flexibility in implementing different evolutionary algorithms while maintaining a consistent interface for execution control.

Required Associated Types§

Source

type Epoch

The type representing a single epoch or generation in the evolutionary process.

The epoch type should contain all relevant information about the current state of the evolutionary algorithm, such as:

  • Generation number
  • Population statistics
  • Best fitness values
  • Convergence metrics
  • Any other state information needed for monitoring or decision making

Required Methods§

Source

fn next(&mut self) -> Self::Epoch

Advances the engine to the next epoch or generation.

This method encapsulates one complete iteration of the evolutionary algorithm. It should perform all necessary operations to progress the population from the current state to the next generation, including:

  • Fitness evaluation
  • Selection
  • Reproduction (crossover and mutation)
  • Population replacement
  • Any other evolutionary operators
§Returns

An instance of Self::Epoch representing the new state after the evolution step

§Side Effects

This method is mutable for allowance of modification of the internal state of the engine, advancing the evolutionary process. The engine should maintain its state between calls to allow for continuous evolution over multiple generations.

§Performance

This method is called repeatedly during execution, so it should be optimized for performance.

Implementors§