pub struct Variable { /* private fields */ }Expand description
A variable in a problem. Use variables to create expressions, to express the objective and the Constraints of your model.
Variables are created using ProblemVariables::add. They implement std::ops basic math operations on f64 and i32 values.
§Warning
Eq is implemented on this type, but
v1 == v2 is true only if the two variables represent the same object,
not if they have the same definition.
let mut vars = variables!();
let v1 = vars.add(variable().min(1).max(8));
let v2 = vars.add(variable().min(1).max(8));
assert_ne!(v1, v2);
let v1_copy = v1;
assert_eq!(v1, v1_copy);Trait Implementations§
Source§impl<RHS: IntoAffineExpression> Add<RHS> for Variable
impl<RHS: IntoAffineExpression> Add<RHS> for Variable
Source§impl FormatWithVars for Variable
impl FormatWithVars for Variable
Source§fn format_with<FUN>(
&self,
f: &mut Formatter<'_>,
variable_format: FUN,
) -> Result
fn format_with<FUN>( &self, f: &mut Formatter<'_>, variable_format: FUN, ) -> Result
Write the element to the formatter. See std::fmt::Display
Source§fn format_debug(&self, f: &mut Formatter<'_>) -> Result
fn format_debug(&self, f: &mut Formatter<'_>) -> Result
Write the elements, naming the variables v0, v1, … vn
Source§impl From<Variable> for Expression
impl From<Variable> for Expression
Source§fn from(x: Variable) -> Expression
fn from(x: Variable) -> Expression
Converts to this type from the input type.
Source§impl IntoAffineExpression for &Variable
impl IntoAffineExpression for &Variable
Source§fn linear_coefficients(self) -> Self::Iter
fn linear_coefficients(self) -> Self::Iter
An iterator over variables and their coefficients.
For instance
a + 2b - 3a - 7 should yield [(a, -2), (b, 2)]Source§fn constant(&self) -> f64
fn constant(&self) -> f64
The constant factor in the expression.
For instance,
a + 2b - 7 will give -7Source§fn into_expression(self) -> Expressionwhere
Self: Sized,
fn into_expression(self) -> Expressionwhere
Self: Sized,
Transform the value into a concrete Expression struct.
Source§impl IntoAffineExpression for Variable
impl IntoAffineExpression for Variable
Source§fn linear_coefficients(self) -> Self::Iter
fn linear_coefficients(self) -> Self::Iter
An iterator over variables and their coefficients.
For instance
a + 2b - 3a - 7 should yield [(a, -2), (b, 2)]Source§fn constant(&self) -> f64
fn constant(&self) -> f64
The constant factor in the expression.
For instance,
a + 2b - 7 will give -7Source§fn into_expression(self) -> Expressionwhere
Self: Sized,
fn into_expression(self) -> Expressionwhere
Self: Sized,
Transform the value into a concrete Expression struct.
Source§impl Not for Variable
Useful for binary variables. !x is equivalent to 1-x.
impl Not for Variable
Useful for binary variables. !x is equivalent to 1-x.
#[cfg(any(feature = "coin_cbc", feature = "lpsolve"))] {
use good_lp::*;
variables! {pb: x (binary); y (binary); }
let solution = pb.maximise(!x + y)
.using(default_solver)
.solve().unwrap();
assert_eq!(solution.value(x), 0.);
assert_eq!(solution.value(y), 1.);Source§impl<RHS: IntoAffineExpression> Sub<RHS> for Variable
impl<RHS: IntoAffineExpression> Sub<RHS> for Variable
impl Copy for Variable
impl Eq for Variable
impl StructuralPartialEq for Variable
Auto Trait Implementations§
impl Freeze for Variable
impl RefUnwindSafe for Variable
impl Send for Variable
impl Sync for Variable
impl Unpin for Variable
impl UnsafeUnpin for Variable
impl UnwindSafe for Variable
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
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>
Converts
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>
Converts
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