Struct good_lp::variable::Variable

source ·
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

§

type Output = Expression

The resulting type after applying the + operator.
source§

fn add(self, rhs: RHS) -> Self::Output

Performs the + operation. Read more
source§

impl Add<Variable> for f64

§

type Output = Expression

The resulting type after applying the + operator.
source§

fn add(self, rhs: Variable) -> Self::Output

Performs the + operation. Read more
source§

impl Add<Variable> for i32

§

type Output = Expression

The resulting type after applying the + operator.
source§

fn add(self, rhs: Variable) -> Self::Output

Performs the + operation. Read more
source§

impl Clone for Variable

source§

fn clone(&self) -> Variable

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Variable

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Div<f64> for Variable

§

type Output = Expression

The resulting type after applying the / operator.
source§

fn div(self, rhs: f64) -> Self::Output

Performs the / operation. Read more
source§

impl Div<i32> for Variable

§

type Output = Expression

The resulting type after applying the / operator.
source§

fn div(self, rhs: i32) -> Self::Output

Performs the / operation. Read more
source§

impl FormatWithVars for Variable

source§

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

Write the elements, naming the variables v0, v1, … vn
source§

impl From<Variable> for Expression

source§

fn from(x: Variable) -> Expression

Converts to this type from the input type.
source§

impl Hash for Variable

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a> IntoAffineExpression for &'a Variable

§

type Iter = Once<(Variable, f64)>

The iterator returned by linear_coefficients.
source§

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

The constant factor in the expression. For instance, a + 2b - 7 will give -7
source§

fn into_expression(self) -> Expressionwhere Self: Sized,

Transform the value into a concrete Expression struct.
source§

fn eval_with<S: Solution>(self, values: &S) -> f64where Self: Sized,

Evaluate the concrete value of the expression, given the values of the variables Read more
source§

impl IntoAffineExpression for Variable

§

type Iter = Once<(Variable, f64)>

The iterator returned by linear_coefficients.
source§

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

The constant factor in the expression. For instance, a + 2b - 7 will give -7
source§

fn into_expression(self) -> Expressionwhere Self: Sized,

Transform the value into a concrete Expression struct.
source§

fn eval_with<S: Solution>(self, values: &S) -> f64where Self: Sized,

Evaluate the concrete value of the expression, given the values of the variables Read more
source§

impl<N: Into<f64>> Mul<N> for Variable

§

type Output = Expression

The resulting type after applying the * operator.
source§

fn mul(self, rhs: N) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Variable> for f64

§

type Output = Expression

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Variable) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<Variable> for i32

§

type Output = Expression

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Variable) -> Self::Output

Performs the * operation. Read more
source§

impl Neg for Variable

§

type Output = Expression

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

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.);
§

type Output = Expression

The resulting type after applying the ! operator.
source§

fn not(self) -> Self::Output

Performs the unary ! operation. Read more
source§

impl PartialEq<Variable> for Variable

source§

fn eq(&self, other: &Variable) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<RHS> Shl<RHS> for Variablewhere Self: Sub<RHS, Output = Expression>,

§

type Output = Constraint

The resulting type after applying the << operator.
source§

fn shl(self, rhs: RHS) -> Self::Output

Performs the << operation. Read more
source§

impl<RHS: Sub<Self, Output = Expression>> Shr<RHS> for Variable

§

type Output = Constraint

The resulting type after applying the >> operator.
source§

fn shr(self, rhs: RHS) -> Self::Output

Performs the >> operation. Read more
source§

impl<RHS: IntoAffineExpression> Sub<RHS> for Variable

§

type Output = Expression

The resulting type after applying the - operator.
source§

fn sub(self, rhs: RHS) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<Variable> for f64

§

type Output = Expression

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Variable) -> Self::Output

Performs the - operation. Read more
source§

impl Sub<Variable> for i32

§

type Output = Expression

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Variable) -> Self::Output

Performs the - operation. Read more
source§

impl Copy for Variable

source§

impl Eq for Variable

source§

impl StructuralEq for Variable

source§

impl StructuralPartialEq for Variable

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.