Skip to main content

Problem

Trait Problem 

Source
pub trait Problem<T, Q = f64>
where T: Clone, Q: Clone,
{ // Required methods fn new() -> Self where Self: Sized; fn evaluate(&self, solution: &mut Solution<T, Q>); fn create_solution(&self, _rng: &mut Random) -> Solution<T, Q>; fn set_problem_description(&mut self, description: String); fn get_problem_description(&self) -> String; fn dominates( &self, solution_a: &Solution<T, Q>, solution_b: &Solution<T, Q>, ) -> bool; fn better_fitness_fn(&self) -> fn(f64, f64) -> bool; // Provided methods fn is_better_fitness(&self, candidate: f64, reference: f64) -> bool { ... } fn non_improving_fitness_loss(&self, current: f64, candidate: f64) -> f64 { ... } fn get_problem_parameters_payload(&self) -> String { ... } fn format_solution(&self, solution: &Solution<T, Q>) -> String where T: Display, Q: Display { ... } }
Expand description

Trait that defines the basic interface for optimization problems.

§Type Parameters

  • T: decision variable type.
  • Q: quality payload type (defaults to f64).

§Responsibilities

Implementors provide:

  • random solution creation,
  • evaluation of candidate solutions,
  • problem-owned comparison semantics for ranking solutions,
  • optional domain-specific formatting used by observers/reports.

Required Methods§

Source

fn new() -> Self
where Self: Sized,

Source

fn evaluate(&self, solution: &mut Solution<T, Q>)

Evaluates a solution and updates its quality/fitness

Source

fn create_solution(&self, _rng: &mut Random) -> Solution<T, Q>

Creates a new random solution for this problem that serves as a starting point for the algorithm

Source

fn set_problem_description(&mut self, description: String)

Source

fn get_problem_description(&self) -> String

Source

fn dominates( &self, solution_a: &Solution<T, Q>, solution_b: &Solution<T, Q>, ) -> bool

Source

fn better_fitness_fn(&self) -> fn(f64, f64) -> bool

Provided Methods§

Source

fn is_better_fitness(&self, candidate: f64, reference: f64) -> bool

Source

fn non_improving_fitness_loss(&self, current: f64, candidate: f64) -> f64

Source

fn get_problem_parameters_payload(&self) -> String

Source

fn format_solution(&self, solution: &Solution<T, Q>) -> String
where T: Display, Q: Display,

Returns a human-friendly representation for one solution.

Observers use this string to present best snapshots in CLI/HTML outputs. Problem implementations can override this to provide domain-specific formatting (for example routes, selected items, or compact objective summaries).

Implementors§