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:
@@ -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::*;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user