Crates.io | microlp |
lib.rs | microlp |
version | 0.2.5 |
source | src |
created_at | 2024-10-30 10:11:31.660879 |
updated_at | 2024-11-06 10:35:27.703653 |
description | A fast linear programming solver library. |
homepage | |
repository | https://github.com/Specy/microlp/ |
max_upload_size | |
id | 1428299 |
size | 219,269 |
This is a fork of minilp which i initially made to fix some runtime errors. I'm no expert of optimization, if you have any suggestions or improvements feel free to open an issue or a pull request.
currently panics in rust nightly 1.83.0 and 1.84.0 see here
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.
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!
Basic usage
use microlp::{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.
This project is licensed under the Apache License, Version 2.0.