7 releases

0.2.9 Jan 9, 2025
0.2.8 Jan 5, 2025
0.2.7 Dec 21, 2024
0.2.6 Nov 23, 2024
0.2.4 Oct 30, 2024

#74 in Math

Download history 199/week @ 2024-10-26 2606/week @ 2024-11-02 3958/week @ 2024-11-09 3670/week @ 2024-11-16 5207/week @ 2024-11-23 5994/week @ 2024-11-30 10389/week @ 2024-12-07 8339/week @ 2024-12-14 6419/week @ 2024-12-21 7566/week @ 2024-12-28 8401/week @ 2025-01-04 12710/week @ 2025-01-11

35,815 downloads per month
Used in 55 crates (2 directly)

Apache-2.0

165KB
4K SLoC

microlp

This is a fork of the archived minilp crate, which was made to fix some bugs, add features and allow the community to make issues and PRs.

Crates.io Documentation

A fast linear programming solver library.

Linear programming is a technique for finding the minimum (or maximum) of a linear function of a set of variables subject to linear equality and inequality constraints.

Features

  • Pure Rust implementation.
  • Able to solve problems with hundreds of thousands of variables and constraints.
  • Incremental: add constraints to an existing solution without solving it from scratch.
  • Problems can be defined via an API or parsed from an MPS file.
  • Allows for continuous, integer and boolean variables

Warning: this is an early-stage project. Although the library is already quite powerful and fast, it will probably cycle, lose precision or panic on some harder problems. Please report bugs and contribute code! Models with integer or binary variables are solved using a simple branch & bound method.

Examples

Basic usage

use microlp::{Problem, OptimizationDirection, ComparisonOp};

// Maximize an objective function x + 2 * y of two continuous variables x >= 0 and 0 <= y <= 3
let mut problem = Problem::new(OptimizationDirection::Maximize);
let x = problem.add_var(1.0, (0.0, f64::INFINITY));
let y = problem.add_var(2.0, (0.0, 3.0));

// subject to constraints: x + y <= 4 and 2 * x + y >= 2.
problem.add_constraint(&[(x, 1.0), (y, 1.0)], ComparisonOp::Le, 4.0);
problem.add_constraint(&[(x, 2.0), (y, 1.0)], ComparisonOp::Ge, 2.0);

// Optimal value is 7, achieved at x = 1 and y = 3.
let solution = problem.solve().unwrap();
assert_eq!(solution.objective(), 7.0);
assert_eq!(solution[x], 1.0);
assert_eq!(solution[y], 3.0);

For a more involved example, see examples/tsp, a solver for the travelling salesman problem.

License

This project is licensed under the Apache License, Version 2.0.

Dependencies

~2MB
~45K SLoC