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::{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
41impl Solver for Baron {
42    type Options = BaronOptions;
43
44    fn name(&self) -> &str {
45        "baron"
46    }
47
48    fn supports(&self, kind: ModelKind) -> bool {
49        // BARON is a global solver for all of the following model classes.
50        matches!(
51            kind,
52            ModelKind::LP
53                | ModelKind::MILP
54                | ModelKind::QP
55                | ModelKind::MIQP
56                | ModelKind::NLP
57                | ModelKind::MINLP
58        )
59    }
60
61    fn solve(&mut self, model: &Model, opts: &BaronOptions) -> Result<SolverResult, SolverError> {
62        translate::solve(model, opts, self.exec.as_deref())
63    }
64}