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