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
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) -> Resultwhere
FUN: FnMut(&mut Formatter<'_>, Variable) -> Result,
fn format_with<FUN>(&self, f: &mut Formatter<'_>, variable_format: FUN) -> Resultwhere FUN: FnMut(&mut Formatter<'_>, Variable) -> 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<'a> IntoAffineExpression for &'a Variable
impl<'a> IntoAffineExpression for &'a 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 -7
source§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 -7
source§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
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.);