Crate lpsolve

Crate lpsolve 

Source
Expand description

Wrapper for lpsolve

Build status Crates.io

lpsolve is a free software (LGPL) solver for mixed integer linear programming problems. The documentation here is nonexistent when it comes to understanding how to model systems or precisely what the consequences of various methods are. The upstream documentation for lpsolve is much more comprehensive.

§Quick Start

use lpsolve::prelude::*;  // Import everything you need

// Terse builder API - maximize 30*x1 + 50*x2 subject to constraints
let solution = Problem::builder()
    .cols(2)
    .max(&[30.0, 50.0])           // Shorthand for maximize + objective
    .le(&[2.0, 3.0], 100.0)       // 2*x1 + 3*x2 <= 100
    .le(&[1.0, 2.0], 60.0)        // x1 + 2*x2 <= 60
    .non_negative()               // All variables >= 0
    .solve()?;

println!("Status: {:?}", solution.status());
println!("Objective: {}", solution.objective_value());
println!("Variables: {:?}", solution.variables());

See the prelude module for convenient imports and shorthand methods.

§Indexing Convention

IMPORTANT: This library follows lpsolve’s 1-based indexing convention:

  • Columns (variables): Indexed from 1 to num_cols() inclusive
  • Rows (constraints): Indexed from 1 to num_rows() inclusive
    • Row 0 is reserved for the objective function in some operations

When passing coefficient arrays (like in set_objective_function or add_constraint), the first element (index 0) represents the constant term, and subsequent elements correspond to variables 1, 2, 3, etc.

// Setting objective: 10*x1 + 20*x2 + 5 (constant)
problem.set_objective_function(&[5.0, 10.0, 20.0])?;
//                                 ^    ^     ^
//                            constant x1    x2

§Error Handling

All getters and setters perform bounds checking and return descriptive errors.

The performance of lpsolve is mediocre compared to commercial solvers and some other free software solvers. Performance here is how how long it takes to solve benchmark models.

If you need help choosing a solver, the following is an excellent report:

http://prod.sandia.gov/techlib/access-control.cgi/2013/138847.pdf

§Stability

lpsolve-sys is versioned separately from this wrapper. This wrapper is provisionally unstable, but the functions that are currently wrapped are not likely to change.

§License

This crate and lpsolve-sys are licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option. However, please note that lpsolve itself is LGPL. The default configuration right now builds a bundled copy of lpsolve and links to it statically.

Re-exports§

pub use error::LpSolveError;
pub use error::Result;
pub use builder::ProblemBuilder;
pub use builder::Solution;
pub use builder::SolverConfig;

Modules§

builder
error
prelude
Prelude module - imports everything you need for typical LP/MIP problems

Structs§

AntiDegen
Anti-degeneracy strategies
ImproveMode
Improvement strategies
MPSOptions
PresolveMode
Presolve methods for problem reduction
Problem
A linear programming problem.
ScalingMode
Scaling modes for numerical stability Note: The base scaling method (0-7) and modifiers (8+) are combined

Enums§

BasisCrash
Basis crash modes for initial basis construction
BoundsMode
BranchRule
Branch and bound rules for MIP (Mixed Integer Programming)
ConstraintType
PivotRule
Pivoting rules for simplex algorithm
SOSType
SimplexType
SolveStatus
VarType
Verbosity