4 releases

0.2.2 May 25, 2020
0.2.1 May 6, 2020
0.2.0 May 3, 2020
0.1.0 Apr 11, 2020

#1545 in Math

Download history 10722/week @ 2023-11-20 8683/week @ 2023-11-27 8120/week @ 2023-12-04 6812/week @ 2023-12-11 6234/week @ 2023-12-18 6044/week @ 2023-12-25 4753/week @ 2024-01-01 5393/week @ 2024-01-08 4822/week @ 2024-01-15 6044/week @ 2024-01-22 6242/week @ 2024-01-29 10240/week @ 2024-02-05 7049/week @ 2024-02-12 5598/week @ 2024-02-19 4725/week @ 2024-02-26 5400/week @ 2024-03-04

24,045 downloads per month
Used in 39 crates (5 directly)

Apache-2.0

150KB
3.5K SLoC

minilp

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 continuous 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.

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!

Examples

Basic usage

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

// Maximize an objective function x + 2 * y of two 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
~40K SLoC