feat(core): add Problem trait

The single trait users implement to describe an optimization problem:
associated `Decision: Clone` plus `objectives()` and `evaluate()`.
Both signatures match spec §8.1; `evaluate` takes `&self`.
This commit is contained in:
2026-05-04 19:18:01 -06:00
parent f6f41eda35
commit d226601a44
2 changed files with 29 additions and 0 deletions
+2
View File
@@ -4,6 +4,7 @@ pub mod candidate;
pub mod evaluation; pub mod evaluation;
pub mod objective; pub mod objective;
pub mod population; pub mod population;
pub mod problem;
pub mod result; pub mod result;
pub mod rng; pub mod rng;
@@ -11,5 +12,6 @@ pub use candidate::*;
pub use evaluation::*; pub use evaluation::*;
pub use objective::*; pub use objective::*;
pub use population::*; pub use population::*;
pub use problem::*;
pub use result::*; pub use result::*;
pub use rng::*; pub use rng::*;
+27
View File
@@ -0,0 +1,27 @@
//! The user-implemented `Problem` trait.
use crate::core::evaluation::Evaluation;
use crate::core::objective::ObjectiveSpace;
/// An optimization problem.
///
/// Implement this trait to describe what the optimizer is allowed to vary
/// (`Decision`), how many objectives it has (`objectives`), and how to score a
/// decision (`evaluate`).
///
/// Example decision types: `Vec<f64>`, `Vec<bool>`, `Vec<i64>`, custom domain
/// structs, or permutations represented as `Vec<usize>`.
pub trait Problem {
/// The thing the optimizer changes. Must be `Clone` because heuristic
/// algorithms routinely clone decisions.
type Decision: Clone;
/// Return the objectives for this problem.
///
/// Returned by value for ergonomics — problems do not need to store an
/// `ObjectiveSpace` field.
fn objectives(&self) -> ObjectiveSpace;
/// Evaluate a decision. Must not mutate `self`.
fn evaluate(&self, decision: &Self::Decision) -> Evaluation;
}