oximo-io
Model I/O for oximo: MPS, LP, and NLP writers.
Converts an oximo [oximo_core::Model] to standard text formats for exchanging models with external solvers and tools.
Usage
Enabled by default via the io feature on the umbrella oximo crate:
[]
= "0.1" # io is on by default
To opt out:
[]
= { = "0.1", = false, = ["highs"] }
To use this crate directly:
[]
= "0.1"
= "0.1"
Quick example
use *;
use ;
let m = new;
let x = m.var.lb.build;
let y = m.var.lb.ub.build;
m.constraint;
m.constraint;
m.maximize;
let mps = to_mps_string?;
let lp = to_lp_string?;
println!;
Formats
MPS
Fixed-format MPS (fixed-column, 10-char field width). Widely supported by commercial and open-source solvers.
| Feature | Behavior |
|---|---|
| Objective row | Named OBJ, maximization models are negated with a * sense: maximize comment so re-importers can recover the original sense |
| Integer variables | Wrapped in INTORG/INTEND markers |
| Bounds | FR (free), MI+UP (lower=-inf), LO/UP as needed. Default lb=0 omitted |
| Constant terms | Objective constant written to RHS OBJ, constraint constants folded into RHS |
use ;
use File;
use BufWriter;
// To string
let s = to_mps_string?;
// To file
let mut f = new;
write_mps?;
LP (CPLEX LP format)
Human-readable CPLEX LP format. Sections emitted: header comment, Minimize/Maximize, Subject To, Bounds (non-default only), General, Binaries, End.
| Feature | Behavior |
|---|---|
| Objective sense | Minimize / Maximize keyword, no negation needed |
| Integer variables | General section (integer/semi-integer), Binaries section |
| Bounds | Free variables declared with free; default lb=0, ub=+inf omitted |
| Objective constant | Written as a comment if non-zero |
use ;
use File;
use BufWriter;
// To string
let s = to_lp_string?;
// To file
let mut f = new;
write_lp?;
NL
The standard format for sharing nonlinear and mixed-integer models. Unlike MPS/LP, it carries full nonlinear expressions, emitted as prefix (Polish) opcode trees.
| Feature | Behavior |
|---|---|
| Nonlinear bodies | Linear part goes to J/G; nonlinear residual to C/O opcode trees |
| Supported operators | + - * /, negation, pow, abs, sin, cos, exp, log (natural) |
| Output encoding | ASCII (default) or binary, via WriteOptions::format |
| Precision / comments | precision and comments knobs tune the ASCII output |
| Variable ordering | Standard ASL order: nonlinear-first (by appearance), then linear |
| Name sidecars | write_nl_files also writes .row / .col name files |
| Optional segments | F/S/V/d/r segments supplied via WriteOptions |
use *;
use ;
use File;
use BufWriter;
use Path;
// Rosenbrock: min (1 - x)^2 + 100 (y - x^2)^2
let m = new;
let x = m.var.bounds.build;
let y = m.var.bounds.build;
m.minimize;
// To string (ASCII only)
let nl = to_nl_string?;
// To <stub>.nl plus sibling .row / .col name files
let opts = WriteOptions ;
write_nl_files?;
// Binary output needs to be written to a byte sink
let mut f = new;
write_nl_with?;
Not yet supported: range constraints, Hollerith (string) constants, and Param nodes.
Errors
All functions return Result<_, IoError>:
| Variant | Cause |
|---|---|
IoError::NoObjective |
Model has no objective set |
IoError::Nonlinear |
Nonlinear node in an MPS/LP model (NL supports nonlinear bodies) |
IoError::UnsupportedNode(n) |
Node not representable in the target format, e.g. Param in NL |
IoError::InvalidNumber |
Non-finite (NaN/Inf) constant while nonfinite_strings is off |
IoError::BinaryToString |
to_nl_string used with binary output; use write_nl_with to a byte sink |
IoError::Io(e) |
Underlying std::io::Error from the writer |
License
MIT OR Apache-2.0