Skip to main content

lp_ip_craft/
lib.rs

1//! Contracts for LP and mixed-integer LP solvers: a validated model, a solver
2//! trait, typed results with explicit bound/gap and dual conventions, and
3//! solver-independent checks.
4//!
5//! This crate has no dependencies. Real optimization is in the sibling crate
6//! `lp-ip-craft-native`, our pure-Rust simplex/branch-and-bound
7//! implementation of [`LpIpSolver`]. [`DummySolver`] remains a contract fixture:
8//! it evaluates
9//! one candidate and returns it with [`Status::Stub`].
10//!
11//! ```
12//! use lp_ip_craft::{
13//!     Bounds, CancellationToken, CsrMatrix, DummySolver, LpIpSolver, Model, ModelData,
14//!     Options, Sense, Status, VariableKind, WarmStart,
15//! };
16//!
17//! // minimize 2 x0 + 3 x1 + 5  subject to  x0 + x1 = 1,  x binary
18//! let model = Model::new(ModelData {
19//!     sense: Sense::Minimize,
20//!     objective: vec![2.0, 3.0],
21//!     objective_offset: 5.0,
22//!     variables: Bounds::new(vec![0.0, 0.0], vec![1.0, 1.0]),
23//!     kinds: vec![VariableKind::Binary; 2],
24//!     matrix: CsrMatrix::from_dense(1, 2, &[1.0, 1.0])?,
25//!     rows: Bounds::fixed(vec![1.0]),
26//! })?;
27//! let start = WarmStart::from_primal(vec![1.0, 0.0]);
28//! let result = DummySolver.solve(
29//!     &model, &Options::default(), Some(&start), &CancellationToken::default(),
30//! )?;
31//! assert_eq!(result.status, Status::Stub); // never an optimality claim
32//! let evaluation = result.evaluation.as_ref().unwrap();
33//! assert_eq!(evaluation.objective, 7.0);
34//! assert!(evaluation.feasible_candidate);
35//! assert!(result.best_bound.is_none() && result.gap(model.sense())?.is_none());
36//! # Ok::<(), lp_ip_craft::Error>(())
37//! ```
38#![forbid(unsafe_code)]
39#![warn(missing_docs)]
40
41mod bound;
42pub mod check;
43mod dummy;
44mod error;
45mod model;
46mod solver;
47mod sparse;
48
49pub use bound::{
50    PreparedDualBound, SafeBoundStatus, SafeDualBound, safe_dual_bound, safe_dual_bound_with_bounds,
51};
52pub use check::evaluate;
53pub use dummy::DummySolver;
54pub use error::{Error, Result};
55pub use model::{Model, ModelData, Sense, VariableKind};
56pub use solver::{
57    BackendReport, CancellationToken, Duals, Evaluation, Gap, LpIpSolver, Options, SolveResult,
58    StartStatus, Status, Tolerances, WarmStart,
59};
60pub use sparse::{Bounds, CsrMatrix, CsrPattern};