Skip to main content

oximo_baron/
lib.rs

1#![doc = include_str!("../README.md")]
2#![forbid(unsafe_code)]
3
4//! References:
5//! N. Sahinidis, BARON User Manual, version 2026.4.12.
6//! The Optimization Firm, LLC, Apr. 12, 2026.
7
8mod options;
9mod translate;
10
11pub use options::BaronOptions;
12pub use translate::solve;
13
14use oximo_core::{Model, ModelKind};
15use oximo_solver::{Iis, InfeasibilityDiagnosis, Solver, SolverError, SolverResult};
16
17/// BARON backend. Writes an oximo [`Model`] to a temporary `.bar` file, invokes
18/// the `baron` executable, and parses the result.
19#[derive(Debug, Default, Clone)]
20pub struct Baron {
21    /// Optional override for the BARON executable path. When `None`, `"baron"`
22    /// is looked up from `PATH`. Overridden per-call by
23    /// [`BaronOptions::baron_path`].
24    pub exec: Option<String>,
25}
26
27impl Baron {
28    /// Create a backend that uses `baron` from `PATH`.
29    #[must_use]
30    pub fn new() -> Self {
31        Self::default()
32    }
33
34    /// Create a backend pointing at an explicit BARON executable path.
35    #[must_use]
36    pub fn with_exec(path: impl Into<String>) -> Self {
37        Self { exec: Some(path.into()) }
38    }
39}
40
41/// Display name for this backend; the single source for both [`Solver::name`]
42/// and the `solver_name` stamped on every [`SolverResult`].
43pub(crate) const NAME: &str = "BARON";
44
45pub(crate) const fn supported(kind: ModelKind) -> bool {
46    matches!(
47        kind,
48        ModelKind::LP
49            | ModelKind::MILP
50            | ModelKind::QP
51            | ModelKind::MIQP
52            | ModelKind::QCP
53            | ModelKind::MIQCP
54            | ModelKind::SOCP
55            | ModelKind::MISOCP
56            | ModelKind::NLP
57            | ModelKind::MINLP
58    )
59}
60
61impl Solver for Baron {
62    type Options = BaronOptions;
63
64    fn name(&self) -> &str {
65        NAME
66    }
67
68    fn supports(&self, kind: ModelKind) -> bool {
69        supported(kind)
70    }
71
72    fn solve(&mut self, model: &Model, opts: &BaronOptions) -> Result<SolverResult, SolverError> {
73        translate::solve(model, opts, self.exec.as_deref())
74    }
75}
76
77impl InfeasibilityDiagnosis for Baron {
78    fn compute_iis(&mut self, model: &Model, opts: &BaronOptions) -> Result<Iis, SolverError> {
79        translate::compute_iis(model, opts, self.exec.as_deref())
80    }
81}