Skip to main content

InteractiveFitness

Trait InteractiveFitness 

Source
pub trait InteractiveFitness: Send + Sync {
    type Genome: EvolutionaryGenome;

    // Required methods
    fn evaluation_mode(&self) -> EvaluationMode;
    fn request_evaluation(
        &self,
        candidates: &[Candidate<Self::Genome>],
    ) -> EvaluationRequest<Self::Genome>;
    fn process_response(
        &mut self,
        response: EvaluationResponse,
        aggregator: &mut FitnessAggregator,
    ) -> Vec<(CandidateId, f64)>;

    // Provided methods
    fn on_generation_start(
        &mut self,
        _generation: usize,
        _population_size: usize,
    ) { ... }
    fn on_evaluation_skipped(&mut self) { ... }
}
Expand description

Trait for interactive fitness evaluation

Unlike the synchronous Fitness trait that returns immediate values, InteractiveFitness generates evaluation requests that must be fulfilled by user interaction.

§Design

The trait is designed around a request/response pattern:

  1. Algorithm calls request_evaluation() with candidates needing feedback
  2. UI presents the request to the user and collects their response
  3. Algorithm calls process_response() to update fitness estimates

§Example Implementation

use fugue_evo::interactive::prelude::*;

struct ArtFitness {
    mode: EvaluationMode,
}

impl InteractiveFitness for ArtFitness {
    type Genome = MyArtGenome;

    fn evaluation_mode(&self) -> EvaluationMode {
        self.mode
    }

    fn request_evaluation(
        &self,
        candidates: &[Candidate<Self::Genome>],
    ) -> EvaluationRequest<Self::Genome> {
        match self.mode {
            EvaluationMode::Rating => {
                EvaluationRequest::rate(candidates.to_vec())
            }
            EvaluationMode::BatchSelection => {
                EvaluationRequest::select_from_batch(candidates.to_vec(), 3)
            }
            _ => unimplemented!()
        }
    }

    fn process_response(
        &mut self,
        response: EvaluationResponse,
        aggregator: &mut FitnessAggregator,
    ) -> Vec<(CandidateId, f64)> {
        // Delegate to aggregator for standard processing
        aggregator.process_response(&response)
    }
}

Required Associated Types§

Source

type Genome: EvolutionaryGenome

The genome type being evaluated

Required Methods§

Source

fn evaluation_mode(&self) -> EvaluationMode

Get the preferred evaluation mode for this fitness function

Source

fn request_evaluation( &self, candidates: &[Candidate<Self::Genome>], ) -> EvaluationRequest<Self::Genome>

Generate an evaluation request for the given candidates

The returned request will be presented to the user for feedback. The implementation should select candidates appropriately for the current evaluation mode.

Source

fn process_response( &mut self, response: EvaluationResponse, aggregator: &mut FitnessAggregator, ) -> Vec<(CandidateId, f64)>

Process user response and update fitness estimates

Returns the updated fitness values for affected candidates. The aggregator maintains cumulative statistics and should be used for fitness computation.

Provided Methods§

Source

fn on_generation_start(&mut self, _generation: usize, _population_size: usize)

Optional: Called at the start of each generation

Allows the fitness function to adjust strategy based on population state or user fatigue.

Source

fn on_evaluation_skipped(&mut self)

Optional: Called when an evaluation is skipped

Allows tracking of user fatigue or disengagement.

Implementors§