pub trait Problem<T, Q = f64>{
// 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 tof64).
§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§
fn new() -> Selfwhere
Self: Sized,
Sourcefn evaluate(&self, solution: &mut Solution<T, Q>)
fn evaluate(&self, solution: &mut Solution<T, Q>)
Evaluates a solution and updates its quality/fitness
Sourcefn create_solution(&self, _rng: &mut Random) -> Solution<T, Q>
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
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
Sourcefn format_solution(&self, solution: &Solution<T, Q>) -> String
fn format_solution(&self, solution: &Solution<T, Q>) -> String
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).