oximo-io
Model I/O for oximo: MPS and LP writers.
Converts an oximo [oximo_core::Model] to standard text formats for exchanging models with external solvers and tools. Both formats support LP and MILP only. Nonlinear expressions raise [IoError::Nonlinear].
Support for NL files for nonlinear programming (NLP) and mixed-integer nonlinear programming (MINLP) is planned.
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?;
Errors
All functions return Result<_, IoError>:
| Variant | Cause |
|---|---|
IoError::NoObjective |
Model has no objective set |
IoError::Nonlinear |
Objective or constraint contains nonlinear nodes (Mul with two non-constant children, Pow, Sin, etc.) |
IoError::Io(e) |
Underlying std::io::Error from the writer |
License
MIT OR Apache-2.0