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="clarabel"))) {
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 initial<N: Into<f64>>(self, value: N) -> Self
pub fn initial<N: Into<f64>>(self, value: N) -> Self
Set the initial value of the variable. This may help the solver to find a solution significantly faster.
Note that the given value may be disregarded by some solvers if
with_initial_solution
is called on the problem instance. It is
advisable to rely either on with_initial_solution
, or to set initial
values on the variables directly, but not both.
Warning: not all solvers support initial solutions. Refer to the documentation of the solver you are using.
let mut problem = ProblemVariables::new();
let x = problem.add(variable().max(3).initial(3));
let y = problem.add(variable().max(5).initial(5));
if cfg!(not(any(feature="clarabel"))) {
let solution = problem.maximise(x + y).using(default_solver).solve().unwrap();
assert_eq!(solution.value(x), 3.);
assert_eq!(solution.value(y), 5.);
}
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
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for VariableDefinition
impl Debug for VariableDefinition
Source§impl Default for VariableDefinition
Creates an unbounded continuous linear variable
impl Default for VariableDefinition
Creates an unbounded continuous linear variable
Source§impl PartialEq for VariableDefinition
impl PartialEq for VariableDefinition
impl StructuralPartialEq for VariableDefinition
Auto Trait Implementations§
impl Freeze for VariableDefinition
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more