oximo_solver/solver.rs
1use oximo_core::{Model, ModelKind};
2
3use crate::result::SolverResult;
4use crate::status::SolverError;
5
6/// Concrete solver backend.
7///
8/// Backends live in their own crates and the umbrella `oximo` crate
9/// gates them behind cargo features. Implementors translate the
10/// `Model` into their internal representation, solve, and return
11/// a populated [`SolverResult`].
12///
13/// Each backend defines its own [`Options`](Solver::Options) type so users get
14/// LSP autocomplete and compile-time validation on the options that actually
15/// apply. The `oximo_solver` crate ships shared building blocks
16/// ([`UniversalOptions`](crate::UniversalOptions),
17/// [`UniversalOptionsExt`](crate::UniversalOptionsExt))
18/// for backends to compose into their own structs.
19pub trait Solver {
20 /// Backend-specific options struct. Use `()` for solvers without any
21 /// tunables.
22 type Options;
23
24 fn name(&self) -> &str;
25
26 fn supports(&self, kind: ModelKind) -> bool;
27
28 /// Solves the given `Model` using this solver.
29 ///
30 /// # Errors
31 ///
32 /// Returns a [`SolverError`] if the model is unsupported or if the solver backend fails.
33 fn solve(&mut self, model: &Model, opts: &Self::Options) -> Result<SolverResult, SolverError>;
34}