oximo
oximo is a Rust algebraic modeling library for mathematical optimization. Build LP and MILP models with a clean builder API, then solve them with bundled or commercial solvers.
Support for nonlinear programming (NLP) and mixed-integer nonlinear programming (MINLP) is planned.
use *;
use Highs;
let m = new;
let x = m.var.lb.build;
let y = m.var.lb.ub.build;
m.constraint;
m.constraint;
m.constraint;
m.maximize;
let result = Highs.solve?;
println!; // 34.0
println!; // 6.0
println!; // 4.0
# Ok::
Features
| Feature | What it adds | Default |
|---|---|---|
highs |
HiGHS LP/MILP solver (bundled, no install) | yes |
io |
MPS and LP file writers | yes |
gurobi |
Gurobi LP/MILP solver (requires licensed install) | no |
gams |
GAMS solver bridge (requires GAMS on PATH) | no |
[]
= "0.1" # HiGHS + MPS/LP writers
= { = "0.1", = ["gurobi"] } # add Gurobi
= { = "0.1", = ["gams"] } # add GAMS backend
Building models
Variables
let m = new;
let x = m.var.lb.build; // continuous, x >= 0
let y = m.var.lb.ub.build; // continuous, 0 <= y <= 10
let z = m.var.lb.build; // free variable
let b = m.var.binary.build; // binary {0, 1}
let n = m.var.lb.integer.build; // general integer
Constraints and objectives
Expressions are built with standard Rust operators. Scalar multiplication, addition, and subtraction all work out of the box:
m.constraint;
m.constraint;
m.constraint;
m.minimize;
// or
m.maximize;
Index sets
Set is the modeling-layer container for an ordered, finite index set. Build
one over integers, strings, or arbitrary tuples. You can combine sets with the
Cartesian product operator &a * &b, and filter sparsely.
use *;
let items = range;
let n_items = range;
let plants = strings;
// Cartesian product -> tuple keys, flattens automatically across nesting.
let routes = &plants * &strings;
assert_eq!;
// Sparse subsets via filter without self-loops
let arcs = .filter;
Indexed variables
Model::indexed_var(name, &set) registers one scalar per key with auto-named
entries like x[seattle,nyc]. Bounds apply uniformly by default, you can use
lb_by / ub_by for per-key bounds.
let m = new;
let x = m.indexed_var.lb.build;
// Scalar lookup: any type that converts to IndexKey works.
let e1 = x;
let e2 = x;
// Per-key upper bound (e.g. capacity per arc).
let _y = m.indexed_var
.lb
.ub_by
.build;
Rule-style constraints
Model::add_constraints_over is a closure that receives the index as a typed
value via FromIndexKey.
Built-in impls cover i64, i32, usize, String, raw IndexKey, and tuples up to
arity 4. State the shape in the closure-arg annotation.
// Scalar set: one constraint per period.
let periods = range;
m.add_constraints_over;
// Tuple set: destructure inline.
m.add_constraints_over;
// Want the raw key? Annotate as IndexKey (clones once per iteration).
m.add_constraints_over;
Summing over sets
// Linear-fastpath aware: `sum` collapses to a single Linear arena node.
let total_weight = sum;
m.constraint;
Solving
All backends implement the Solver trait:
HiGHS (default)
No install required, HiGHS is compiled from source via the highs crate.
use *;
use Highs;
let result = Highs.solve?;
Gurobi
Requires a licensed Gurobi install and GUROBI_HOME set. See crates/oximo-gurobi/README.md.
use *;
use Gurobi;
let result = Gurobi.solve?;
GAMS
Requires GAMS on PATH. Supports solving models via GAMS solvers (CPLEX, BARON, etc.). See crates/oximo-gams/README.md.
use *;
use Gams;
let result = Gams.solve?;
Reading results
let result = Highs.solve?;
match result.status
// Variable values
let x_val = result.value_of; // Option<f64>
// Constraint duals (LP only)
let dual = result.dual.get;
// Reduced costs
let rc = result.reduced_costs.get;
Model export
With the io feature (default):
use io;
let mps = to_mps_string?;
let lp = to_lp_string?;
write_mps?;
write_lp?;
Workspace layout
| Crate | Role |
|---|---|
oximo |
Umbrella crate |
oximo-expr |
Arena-allocated expression tree |
oximo-core |
Model, Variable, Constraint, Objective, Set |
oximo-solver |
Solver trait, SolverResult, SolverOptions |
oximo-io |
MPS and LP writers |
oximo-highs |
HiGHS backend |
oximo-gurobi |
Gurobi backend |
oximo-gams |
GAMS writer and backend |
Requirements
- Gurobi feature: Gurobi,
GUROBI_HOMEset, valid license - GAMS feature: GAMS on
PATH, valid license
License
MIT OR Apache-2.0