Crates.io | simplex |
lib.rs | simplex |
version | 1.0.0 |
source | src |
created_at | 2019-08-23 10:12:54.86675 |
updated_at | 2020-09-12 18:25:23.04255 |
description | A Linear Programming solver |
homepage | |
repository | |
max_upload_size | |
id | 159170 |
size | 21,458 |
A Linear Programming solver.
Use it to solve your linear programming problems directly from Rust. For example, for this problem:
minimize -3x + y - 2z
with 2x - 2y + 3z <= 5
x + y - z <= 3
x - y + z <= 2
You can do:
use simplex::*;
fn main(){
let program = Simplex::minimize(&vec![-3.0, 1.0, -2.0])
.with(vec![
SimplexConstraint::LessThan(vec![2.0, -2.0, 3.0], 5.0),
SimplexConstraint::LessThan(vec![1.0, 1.0, -1.0], 3.0),
SimplexConstraint::LessThan(vec![1.0, -1.0, 1.0], 2.0),
]);
let mut simplex = program.unwrap();
match simplex.solve() {
SimplexOutput::UniqueOptimum(x) => println!("{}", x),
SimplexOutput::MultipleOptimum(x) => println!("{}", x),
_ => panic!("No solution or unbounded"),
}
println!("{:?}", simplex.get_var(1));
println!("{:?}", simplex.get_var(2));
println!("{:?}", simplex.get_var(3));
}