Skip to main content

oximo_clarabel/
lib.rs

1#![doc = include_str!("../README.md")]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4mod options;
5mod persistent;
6mod translate;
7
8pub use options::{ClarabelDirectSolve, ClarabelOptions};
9pub use persistent::ClarabelPersistent;
10pub use translate::solve;
11
12use oximo_core::{Model, ModelKind};
13use oximo_solver::{PersistentSolver, Solver, SolverError, SolverResult};
14
15/// Clarabel solver handle.
16///
17/// Clarabel is a pure-Rust interior-point solver for convex conic programs:
18/// linear programs, convex quadratic objectives, and second-order cone
19/// constraints.
20#[derive(Debug, Default, Clone, Copy)]
21pub struct Clarabel;
22
23/// Display name for this backend; the single source for both [`Solver::name`]
24/// and the `solver_name` stamped on every [`SolverResult`].
25pub(crate) const NAME: &str = "Clarabel";
26
27/// The model kinds Clarabel can solve: continuous LP, quadratic-objective QP,
28/// and SOCP.
29/// QCP is out until convex quadratic constraints are reformulated to SOC.
30pub(crate) const fn supported(kind: ModelKind) -> bool {
31    matches!(kind, ModelKind::LP | ModelKind::QP | ModelKind::SOCP)
32}
33
34impl Solver for Clarabel {
35    type Options = ClarabelOptions;
36
37    fn name(&self) -> &str {
38        NAME
39    }
40
41    fn supports(&self, kind: ModelKind) -> bool {
42        supported(kind)
43    }
44
45    fn solve(
46        &mut self,
47        model: &Model,
48        opts: &ClarabelOptions,
49    ) -> Result<SolverResult, SolverError> {
50        translate::solve(model, opts)
51    }
52}
53
54impl PersistentSolver for Clarabel {
55    type Handle = ClarabelPersistent;
56
57    fn persistent(&self) -> ClarabelPersistent {
58        ClarabelPersistent::new()
59    }
60}