[][src]Struct minilp::Problem

pub struct Problem { /* fields omitted */ }

A specification of a linear programming problem.

Methods

impl Problem[src]

pub fn new(direction: OptimizationDirection) -> Self[src]

Create a new problem instance.

pub fn add_var(&mut self, obj_coeff: f64, (min, max): (f64, f64)) -> Variable[src]

Add a new variable to the problem.

obj_coeff is a coefficient of the term in the objective function corresponding to this variable, min and max are the minimum and maximum (inclusive) bounds of this variable. If one of the bounds is absent, use f64::NEG_INFINITY for minimum and f64::INFINITY for maximum.

pub fn add_constraint(
    &mut self,
    expr: impl Into<LinearExpr>,
    cmp_op: ComparisonOp,
    rhs: f64
)
[src]

Add a linear constraint to the problem.

Panics

Will panic if a variable was added more than once to the left-hand side expression.

Examples

Left-hand side of the constraint can be specified in several ways:

let mut problem = Problem::new(OptimizationDirection::Minimize);
let x = problem.add_var(1.0, (0.0, f64::INFINITY));
let y = problem.add_var(1.0, (0.0, f64::INFINITY));

// Add an x + y >= 2 constraint, specifying the left-hand side expression:

// * by passing a slice of pairs (useful when explicitly enumerating variables)
problem.add_constraint(&[(x, 1.0), (y, 1.0)], ComparisonOp::Ge, 2.0);

// * by passing an iterator of variable-coefficient pairs.
let vars = [x, y];
problem.add_constraint(vars.iter().map(|&v| (v, 1.0)), ComparisonOp::Ge, 2.0);

// * by manually constructing a LinearExpr.
let mut lhs = LinearExpr::empty();
for &v in &vars {
    lhs.add(v, 1.0);
}
problem.add_constraint(lhs, ComparisonOp::Ge, 2.0);

pub fn solve(&self) -> Result<Solution, Error>[src]

Solve the problem, finding the optimal objective function value and variable values.

Errors

Will return an error, if the problem is infeasible (constraints can't be satisfied) or if the objective value is unbounded.

Trait Implementations

impl Clone for Problem[src]

impl Debug for Problem[src]

Auto Trait Implementations

impl RefUnwindSafe for Problem

impl Send for Problem

impl Sync for Problem

impl Unpin for Problem

impl UnwindSafe for Problem

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.