Skip to main content

Crate lp_ip_craft

Crate lp_ip_craft 

Source
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§

BackendReport
Provenance and timings of one backend invocation.
Bounds
Elementwise bounds lower[i] <= v[i] <= upper[i].
CancellationToken
A cooperative cancellation flag that can be shared across threads.
CsrMatrix
A sparse matrix: a CsrPattern plus one value per stored entry.
CsrPattern
Structure of a sparse matrix in zero-based compressed sparse row (CSR) form.
Duals
LP dual values.
DummySolver
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.
ModelData
The parts of a model, before validation. Turn it into a Model with Model::new.
Options
Settings accepted by the solvers in this crate.
PreparedDualBound
Reusable conservative Lagrangian bound for fixed matrix, objective, rows and multipliers, with independently mutable variable intervals.
SafeDualBound
Result of safe_dual_bound. An unavailable bound is never an assertion that the optimization problem is unbounded or infeasible.
SolveResult
Outcome of a solve that was not aborted by an error.
Tolerances
Tolerances of the candidate check, absolute and in original, unscaled units.
WarmStart
Information a solve may start from.

Enums§

Error
Why a call was aborted.
SafeBoundStatus
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.
StartStatus
What happened to a WarmStart.
Status
How a solve ended: the termination reason, independent of candidate quality.
VariableKind
Domain of a variable within its bounds.

Traits§

LpIpSolver
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::Duals original-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.