oximo-core
Core modeling types for oximo: Model, Variable, Set, Constraint, Objective, Parameter, IndexedVar, Domain, and ModelKind.
Re-exports oximo-expr types (Expr, ExprArena, ExprId, ExprNode, ParamId, VarId) so downstream code does not need a separate oximo-expr import.
End users typically depend on the umbrella oximo crate rather than this one directly.
Usage
[]
= "0.1"
Or via the umbrella crate (recommended for end users):
[]
= "0.1"
Quick example
use *;
let m = new;
// Scalar variables
let x = m.var.lb.build;
let y = m.var.lb.ub.build;
// Constraints
m.constraint;
m.constraint;
// Objective
m.maximize;
println!; // LP
Model
Model uses interior mutability (RefCell) so the builder API takes &self. This lets you hold a &Model reference, build variables and constraints, and immediately use the returned Expr handles, no &mut threading required.
let m = new;
let x = m.var.lb.build; // returns Expr<'_>
m.constraint; // uses x while holding &m
Names are unique per registry. Registering a duplicate variable or constraint name panics.
Accessors
m.num_variables // usize
m.num_constraints // usize
m.variables // Ref<'_, Vec<Variable>>
m.constraints // Ref<'_, Vec<Constraint>>
m.arena // Ref<'_, ExprArena>
m.kind // ModelKind, cached, invalidated on change
m.try_objective // Result<Objective, Error>
m.variable_id // Option<VarId>
m.constraint_id // Option<ConstraintId>
Fixing and unfixing variables
m.fix_var; // lb = ub = 3.0
m.unfix_var; // restore bounds
Variables
Scalar variable builder
let x = m.var
.lb // lower bound (default: -inf)
.ub // upper bound (default: +inf)
.domain // explicit domain (default: Real)
.build; // returns Expr<'_>
// Shorthand domain setters:
let b = m.var.binary.build; // Domain::Binary, bounds [0, 1]
let n = m.var.integer.lb.build; // Domain::Integer
Indexed variable builder
Creates one scalar variable per key in a Set, named base[key].
let i = range;
let x = m.indexed_var
.lb
.integer
.build; // IndexedVar<'_>
// Access by key (panics on missing key):
let expr = x; // or x["name"], x[(a, b)]
// Per-key bounds:
let x = m.indexed_var
.lb_by
.ub_by
.build;
Domain
| Variant | Description |
|---|---|
Domain::Real |
Any real number (default) |
Domain::Integer |
Any integer |
Domain::Binary |
0 or 1 |
Domain::SemiContinuous { threshold } |
0 or any value >= threshold |
Domain::SemiInteger { threshold } |
0 or any integer >= threshold |
Sets
Set is an ordered finite index set. Three variants:
let i = range; // Range: i64 keys 0..5
let j = strings; // Strings
let k = product; // Tuples: (0,"a"), (0,"b"), ...
let k = &i * &j; // Same via Mul operator
// From sparse ints:
let s = from_ints;
// Filter:
let evens = i.filter;
Constraints
Single constraint
let c_id = m.constraint; // <=
let c_id = m.constraint; // >=
let c_id = m.constraint; // ==
Bulk, rule over a set
m.add_constraints_over;
// Tuple sets, destructure inline:
m.add_constraints_over;
Objectives
m.minimize;
m.maximize;
Model kind
Inferred automatically from variables and expressions, cached and invalidated on change:
| Kind | Conditions |
|---|---|
LP |
All continuous, all linear |
MILP |
Any integer/binary, all linear |
QP |
All continuous, Mul with ≥2 non-const children |
MIQP |
Any integer/binary + quadratic |
NLP |
All continuous, Pow/Sin/Cos/Exp/Log |
MINLP |
Any integer/binary + nonlinear |
For now, we only support linear constraints, so QP and NLP are not possible. But the API is designed to allow nonlinear constraints in the future without breaking changes.
License
MIT OR Apache-2.0