Skip to main content

oximo_highs/
lib.rs

1#![doc = include_str!("../README.md")]
2#![forbid(unsafe_code)]
3
4mod options;
5mod persistent;
6mod translate;
7
8#[cfg(feature = "benchmark-support")]
9#[doc(hidden)]
10pub use translate::benchmark_support;
11
12pub use options::{HighsMethod, HighsOptions, HighsPresolve};
13pub use persistent::HighsPersistent;
14pub use translate::solve;
15
16use oximo_core::{Model, ModelKind};
17use oximo_solver::{PersistentSolver, Solver, SolverError, SolverResult};
18
19/// HiGHS solver handle.
20///
21/// [`Solver::solve`] builds a fresh HiGHS instance for each call, so models can be
22/// re-used or shared freely. For repeated solves of one model (parameter sweeps,
23/// sensitivity studies, rolling horizons), build a resident handle with
24/// [`Highs::persistent`](PersistentSolver::persistent).
25#[derive(Debug, Default, Clone, Copy)]
26pub struct Highs;
27
28/// Display name for this backend; the single source for both [`Solver::name`]
29/// and the `solver_name` stamped on every [`SolverResult`].
30pub(crate) const NAME: &str = "HiGHS";
31
32/// The model kinds HiGHS can solve: linear models and quadratic-objective QP.
33pub(crate) const fn supported(kind: ModelKind) -> bool {
34    matches!(kind, ModelKind::LP | ModelKind::MILP | ModelKind::QP)
35}
36
37impl Solver for Highs {
38    type Options = HighsOptions;
39
40    fn name(&self) -> &str {
41        NAME
42    }
43
44    fn supports(&self, kind: ModelKind) -> bool {
45        supported(kind)
46    }
47
48    fn solve(&mut self, model: &Model, opts: &HighsOptions) -> Result<SolverResult, SolverError> {
49        translate::solve(model, opts)
50    }
51}
52
53impl PersistentSolver for Highs {
54    type Handle = HighsPersistent;
55
56    fn persistent(&self) -> HighsPersistent {
57        HighsPersistent::new()
58    }
59}