pub struct LpProblem { /* private fields */ }Expand description
A linear program in builder form. See the module docs for the problem shape and the meaning of the results.
Every variable defaults to 0 ≤ xⱼ < ∞; change that with
bounds or free. Constraint rows are
kept in insertion order, which is also the order of
LpSolution::duals and LpSolution::farkas.
§Examples
use symplex::linprog::{LpProblem, LpStatus, q, qi};
// min x + y s.t. x + 2y ≥ 1, 3x + y ≥ 1, x, y ≥ 0 → (1/5, 2/5)
let sol = LpProblem::minimize(vec![qi(1), qi(1)])
.ge(vec![qi(1), qi(2)], qi(1))
.ge(vec![qi(3), qi(1)], qi(1))
.solve()
.unwrap();
assert_eq!(sol.status, LpStatus::Optimal);
assert_eq!(sol.x, vec![q(1, 5), q(2, 5)]);
assert_eq!(sol.objective, Some(q(3, 5)));Implementations§
Source§impl LpProblem
impl LpProblem
Sourcepub fn bounds(self, var: usize, bounds: Bounds<Q>) -> Self
pub fn bounds(self, var: usize, bounds: Bounds<Q>) -> Self
Set the bounds lower ≤ x[var] ≤ upper of one variable: .bounds(j, Bounds::closed(q(1, 2), qi(3))), .bounds(j, Bounds::at_most(qi(3))),
…. An absent side is unbounded; Bounds::free makes the variable
free (see also free).
An out-of-range var is reported by solve.
Sourcepub fn num_constraints(&self) -> usize
pub fn num_constraints(&self) -> usize
Number of constraint rows added so far.
Sourcepub fn with_budget(self, budget: Budget) -> Self
pub fn with_budget(self, budget: Budget) -> Self
Bound the solve by a Budget (deadline and/or pivot cap). When
it runs out, solve returns
LpStatus::BudgetExhausted. The default budget is unlimited.
Sourcepub fn budget(&self) -> &Budget
pub fn budget(&self) -> &Budget
The budget the solve runs under (unlimited unless
with_budget was called).
Sourcepub fn solve(&self) -> Result<LpSolution, SymplexError>
pub fn solve(&self) -> Result<LpSolution, SymplexError>
Solve the program exactly.
The returned LpSolution reports LpStatus::Optimal,
LpStatus::Infeasible (with a Farkas certificate),
LpStatus::Unbounded or — only under a Budget —
LpStatus::BudgetExhausted; none of these is an error.
§Errors
SymplexError::InvalidArgumentfor malformed input: no variables, a constraint row whose length differs fromc.len(), or a bound set for a variable index≥ c.len().SymplexError::ComputationFailedif the pivot cap (10 000 + 50·(m + n)) is exceeded — not expected in practice, since Bland’s rule rules out cycling.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LpProblem
impl RefUnwindSafe for LpProblem
impl Send for LpProblem
impl Sync for LpProblem
impl Unpin for LpProblem
impl UnsafeUnpin for LpProblem
impl UnwindSafe for LpProblem
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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> ⓘ
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> ⓘ
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