Struct good_lp::variable::VariableDefinition
source · pub struct VariableDefinition { /* private fields */ }Expand description
Defines the properties of a variable, such as its lower and upper bounds.
Implementations§
source§impl VariableDefinition
impl VariableDefinition
sourcepub fn integer(self) -> Self
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.);sourcepub fn binary(self) -> Self
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"))) {
let solution = problem.maximise(x + y).using(default_solver).solve().unwrap();
assert_eq!(solution.value(x), 1.);
assert_eq!(solution.value(y), 1.);
}sourcepub fn name<S: Into<String>>(self, name: S) -> Self
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());sourcepub fn bounds<N: Into<f64> + Copy, B: RangeBounds<N>>(self, bounds: B) -> Self
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)
);
Trait Implementations§
source§impl Clone for VariableDefinition
impl Clone for VariableDefinition
source§fn clone(&self) -> VariableDefinition
fn clone(&self) -> VariableDefinition
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for VariableDefinition
impl Debug for VariableDefinition
source§impl Default for VariableDefinition
impl Default for VariableDefinition
Creates an unbounded continuous linear variable
source§impl PartialEq<VariableDefinition> for VariableDefinition
impl PartialEq<VariableDefinition> for VariableDefinition
source§fn eq(&self, other: &VariableDefinition) -> bool
fn eq(&self, other: &VariableDefinition) -> bool
This method tests for
self and other values to be equal, and is used
by ==.impl StructuralPartialEq for VariableDefinition
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§
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
Mutably borrows from an owned value. Read more