pub struct LinearProgram {
pub ge_ph: Polyhedron,
pub eq_ph: Polyhedron,
pub of: Vec<f64>,
}Expand description
Data structure for a linear program (LP).
Fields§
§ge_ph: PolyhedronPolyhedron with constraints on the form $ A \ge b $.
eq_ph: PolyhedronPolyhedron with constraints on the form $ A = b $.
of: Vec<f64>Objective function.
Implementations§
Source§impl LinearProgram
impl LinearProgram
Sourcepub fn solve(&self) -> Solution
pub fn solve(&self) -> Solution
Solves a linear program with the revised simplex algorithm.
§Example:
Solve the linear program $$ \max \quad -4x_1+-5x_2 $$ $$ s.t. \quad x_1+4x_2 \geq 4 $$ $$ \qquad \ 3x_1+2x_2 \geq 6 $$ $$ \qquad \ x_1, x_2 \geq 0$$
use puanrs::polyopt::{Polyhedron, VariableFloat};
use puanrs::solver::LinearProgram;
use puanrs::linalg::Matrix;
let sol = LinearProgram {
ge_ph: Polyhedron {
a: Matrix{val: vec![1.0, 4.0, 3.0, 2.0],
nrows: 2,
ncols: 2
},
b: vec![4.0, 6.0],
variables: vec![ VariableFloat { id: 0, bounds: (0.0,f64::MAX) }, VariableFloat { id: 1, bounds: (0.0,f64::MAX) }],
index: vec![Some(0),Some(1)],
},
eq_ph: Default::default(),
of: vec![-4.0, -5.0],
}.solve();
assert_eq!(sol.z, -9.4);
assert_eq!(sol.x, vec![1.6000000000000003, 0.5999999999999999]);
assert_eq!(sol.status_code, 5);Trait Implementations§
Source§impl Clone for LinearProgram
impl Clone for LinearProgram
Source§impl Default for LinearProgram
impl Default for LinearProgram
Source§fn default() -> LinearProgram
fn default() -> LinearProgram
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for LinearProgram
impl RefUnwindSafe for LinearProgram
impl Send for LinearProgram
impl Sync for LinearProgram
impl Unpin for LinearProgram
impl UnsafeUnpin for LinearProgram
impl UnwindSafe for LinearProgram
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more