pub struct VariableDefinition { /* private fields */ }
Expand description

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

Implementations§

source§

impl VariableDefinition

source

pub fn new() -> Self

Creates an unbounded continuous linear variable

source

pub fn integer(self) -> Self

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));
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.);
source

pub fn binary(self) -> Self

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="clarabel"))) {
    let solution = problem.maximise(x + y).using(default_solver).solve().unwrap();
    assert_eq!(solution.value(x), 1.);
    assert_eq!(solution.value(y), 1.);
}
source

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

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());
source

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

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)
);
source

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

Set the lower bound of the variable

source

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

Set the higher bound of the variable

source

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

Set both the lower and higher bounds of the variable

Trait Implementations§

source§

impl Clone for VariableDefinition

source§

fn clone(&self) -> VariableDefinition

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for VariableDefinition

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for VariableDefinition

Creates an unbounded continuous linear variable

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl PartialEq for VariableDefinition

source§

fn eq(&self, other: &VariableDefinition) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for VariableDefinition

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.