Expand description
Contracts for LP and mixed-integer LP solvers: a validated model, a solver trait, typed results with explicit bound/gap and dual conventions, and solver-independent checks.
This crate has no dependencies. Real optimization is in the sibling crate
lp-ip-craft-native, our pure-Rust simplex/branch-and-bound
implementation of LpIpSolver. DummySolver remains a contract fixture:
it evaluates
one candidate and returns it with Status::Stub.
use lp_ip_craft::{
Bounds, CancellationToken, CsrMatrix, DummySolver, LpIpSolver, Model, ModelData,
Options, Sense, Status, VariableKind, WarmStart,
};
// minimize 2 x0 + 3 x1 + 5 subject to x0 + x1 = 1, x binary
let model = Model::new(ModelData {
sense: Sense::Minimize,
objective: vec![2.0, 3.0],
objective_offset: 5.0,
variables: Bounds::new(vec![0.0, 0.0], vec![1.0, 1.0]),
kinds: vec![VariableKind::Binary; 2],
matrix: CsrMatrix::from_dense(1, 2, &[1.0, 1.0])?,
rows: Bounds::fixed(vec![1.0]),
})?;
let start = WarmStart::from_primal(vec![1.0, 0.0]);
let result = DummySolver.solve(
&model, &Options::default(), Some(&start), &CancellationToken::default(),
)?;
assert_eq!(result.status, Status::Stub); // never an optimality claim
let evaluation = result.evaluation.as_ref().unwrap();
assert_eq!(evaluation.objective, 7.0);
assert!(evaluation.feasible_candidate);
assert!(result.best_bound.is_none() && result.gap(model.sense())?.is_none());Re-exports§
pub use check::evaluate;
Modules§
- check
- Solver-independent checks of candidate points and LP duals.
Structs§
- Backend
Report - Provenance and timings of one backend invocation.
- Bounds
- Elementwise bounds
lower[i] <= v[i] <= upper[i]. - Cancellation
Token - A cooperative cancellation flag that can be shared across threads.
- CsrMatrix
- A sparse matrix: a
CsrPatternplus one value per stored entry. - CsrPattern
- Structure of a sparse matrix in zero-based compressed sparse row (CSR) form.
- Duals
- LP dual values.
- Dummy
Solver - Evaluates one candidate and stops. It does not optimize.
- Evaluation
- Independently recomputed values at a candidate point (see
evaluate). - Gap
- Optimality gap between a feasible candidate and a bound, both in the original objective sense and including the offset.
- Model
- A validated LP or mixed-integer LP.
- Model
Data - The parts of a model, before validation. Turn it into a
ModelwithModel::new. - Options
- Settings accepted by the solvers in this crate.
- Prepared
Dual Bound - Reusable conservative Lagrangian bound for fixed matrix, objective, rows and multipliers, with independently mutable variable intervals.
- Safe
Dual Bound - Result of
safe_dual_bound. An unavailable bound is never an assertion that the optimization problem is unbounded or infeasible. - Solve
Result - Outcome of a solve that was not aborted by an error.
- Tolerances
- Tolerances of the candidate check, absolute and in original, unscaled units.
- Warm
Start - Information a solve may start from.
Enums§
- Error
- Why a call was aborted.
- Safe
Bound Status - Outcome of an independent dual-bound calculation, not a solver status.
- Sense
- Direction of optimization. Objective values, bounds and duals are always reported in this original sense; there is no hidden sign change.
- Start
Status - What happened to a
WarmStart. - Status
- How a solve ended: the termination reason, independent of candidate quality.
- Variable
Kind - Domain of a variable within its bounds.
Traits§
- LpIp
Solver - An LP / MIP solver: the replacement point for backends (HiGHS, SCIP, a native component).
Functions§
- safe_
dual_ bound - Computes a conservative bound from arbitrary finite row multipliers in
the
crate::Dualsoriginal-sense convention. No primal point, reduced costs, solver status or feasibility tolerance is needed. - safe_
dual_ bound_ with_ bounds - Conservative dual bound using replacement variable bounds. The matrix, objective and rows are borrowed unchanged; bounds are validated first.
Type Aliases§
- Result
- Result alias used throughout the crate.