Struct good_lp::variable::VariableDefinition [−][src]
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]
fn clone(&self) -> VariableDefinition[src]
pub fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Debug for VariableDefinition[src]
impl Default for VariableDefinition[src]
Creates an unbounded continuous linear variable
impl PartialEq<VariableDefinition> for VariableDefinition[src]
fn eq(&self, other: &VariableDefinition) -> bool[src]
fn ne(&self, other: &VariableDefinition) -> bool[src]
impl StructuralPartialEq for VariableDefinition[src]
Auto Trait Implementations
impl RefUnwindSafe for VariableDefinition
impl Send for VariableDefinition
impl Sync for VariableDefinition
impl Unpin for VariableDefinition
impl UnwindSafe for VariableDefinition
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,