Linear programming library that provides primal and dual simplex solvers. Both solvers are currently working for a small set of test problems. This library is an early work-in-progress.
Here is example code that sets up a linear program, and then solves it with both the primal and dual simplex solvers.
```rust use ellp::*;
let mut prob = Problem::new();
let x1 = prob .addvar(2., Bound::TwoSided(-1., 1.), Some("x1".tostring())) .unwrap();
let x2 = prob .addvar(10., Bound::Upper(6.), Some("x2".tostring())) .unwrap();
let x3 = prob .addvar(0., Bound::Lower(0.), Some("x3".tostring())) .unwrap();
let x4 = prob .addvar(1., Bound::Fixed(0.), Some("x4".tostring())) .unwrap();
let x5 = prob .addvar(0., Bound::Free, Some("x5".tostring())) .unwrap();
prob.add_constraint(vec![(x1, 2.5), (x2, 3.5)], ConstraintOp::Gte, 5.) .unwrap();
prob.add_constraint(vec![(x2, 2.5), (x1, 4.5)], ConstraintOp::Lte, 1.) .unwrap();
prob.add_constraint(vec![(x3, -1.), (x4, -3.), (x5, -4.)], ConstraintOp::Eq, 2.) .unwrap();
println!("{}", prob);
let primalsolver = PrimalSimplexSolver::default(); let dualsolver = DualSimplexSolver::default();
let primalresult = primalsolver.solve(prob.clone()).unwrap(); let dualresult = dualsolver.solve(prob).unwrap();
if let SolverResult::Optimal(sol) = primal_result { println!("primal obj: {}", sol.obj()); println!("primal opt point: {}", sol.x()); } else { panic!("should have an optimal point"); }
if let SolverResult::Optimal(sol) = dual_result { println!("dual obj: {}", sol.obj()); println!("dual opt point: {}", sol.x()); } else { panic!("should have an optimal point"); } ```
The output is ``` minimize + 2 x1 + 10 x2 + 1 x4
subject to + 2.5 x1 + 3.5 x2 ≥ 5 + 2.5 x2 + 4.5 x1 ≤ 1 - 1 x3 - 3 x4 - 4 x5 = 2
with the bounds -1 ≤ x1 ≤ 1 x2 ≤ 6 x3 ≥ 0 x4 = 0 x5 free
primal obj: 19.157894736842103 primal opt point: ┌ ┐ │ -0.9473684210526313 │ │ 2.1052631578947367 │ │ 0 │ │ 0 │ │ -0.5 │ └ ┘
dual obj: 19.157894736842103 dual opt point: ┌ ┐ │ -0.9473684210526313 │ │ 2.1052631578947367 │ │ 0 │ │ 0 │ │ -0.5 │ └ ┘ ```
If the problem is infeasible or unbounded, then solve
will return SolverResult::Infeasible
or SolverResult::Unbounded
, respectively.