Struct good_lp::variable::VariableDefinition[][src]

pub struct VariableDefinition { /* fields omitted */ }

Defines the properties of a variable, such as its lower and upper bounds.

Implementations

impl VariableDefinition[src]

pub fn new() -> Self[src]

Creates an unbounded continuous linear variable

pub fn integer(self) -> Self[src]

Define the variable as an integer. The variable will only be able to take an integer value in the solution.

Warning: not all solvers support integer variables. Refer to the documentation of the solver you are using.

let mut problem = ProblemVariables::new();
let x = problem.add(variable().integer().min(0).max(2.5));
if cfg!(not(any(feature = "minilp", feature = "highs"))) {
    let solution = problem.maximise(x).using(default_solver).solve().unwrap();
    // x is bound to [0; 2.5], but the solution is x=2 because x needs to be an integer
    assert_eq!(solution.value(x), 2.);
}

pub fn binary(self) -> Self[src]

Define the variable as an integer that can only take the value 0 or 1.

Warning: not all solvers support integer variables. Refer to the documentation of the solver you are using.

let mut problem = ProblemVariables::new();
let x = problem.add(variable().binary());
let y = problem.add(variable().binary());
if cfg!(not(any(feature = "minilp", feature = "highs"))) {
    let solution = problem.maximise(x + y).using(default_solver).solve().unwrap();
    assert_eq!(solution.value(x), 1.);
    assert_eq!(solution.value(y), 1.);
}

pub fn name<S: Into<String>>(self, name: S) -> Self[src]

Set the name of the variable. This is useful in particular when displaying the problem for debugging purposes.

let mut pb = ProblemVariables::new();
let x = pb.add(variable().name("x"));
assert_eq!("x", pb.display(&x).to_string());

pub fn bounds<N: Into<f64> + Copy, B: RangeBounds<N>>(self, bounds: B) -> Self[src]

Set the lower and/or higher bounds of the variable

Examples

assert_eq!(
    variable().bounds(1..2),
    variable().min(1).max(2)
);

assert_eq!(
    variable().bounds(1..),
    variable().min(1)
);

assert_eq!(
    variable().bounds(..=2),
    variable().max(2)
);

pub fn min<N: Into<f64>>(self, min: N) -> Self[src]

Set the lower bound of the variable

pub fn max<N: Into<f64>>(self, max: N) -> Self[src]

Set the higher bound of the variable

pub fn clamp<N1: Into<f64>, N2: Into<f64>>(self, min: N1, max: N2) -> Self[src]

Set both the lower and higher bounds of the variable

Trait Implementations

impl Clone for VariableDefinition[src]

impl Debug for VariableDefinition[src]

impl Default for VariableDefinition[src]

Creates an unbounded continuous linear variable

impl PartialEq<VariableDefinition> for VariableDefinition[src]

impl StructuralPartialEq for VariableDefinition[src]

Auto Trait Implementations

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.