Expression

Struct Expression 

Source
pub struct Expression { /* private fields */ }
Expand description

Represents an affine expression, such as 2x + 3 or x + y + z

Implementations§

Source§

impl Expression

Source

pub fn with_capacity(capacity: usize) -> Self

Create an expression that has the value 0, but has memory allocated for capacity coefficients.

Source

pub fn from_other_affine<E: IntoAffineExpression>(source: E) -> Self

Create a concrete expression struct from anything that has linear coefficients and a constant

Expression::from_other_affine(0.); // A constant expression
Source

pub fn leq<RHS>(self, rhs: RHS) -> Constraint
where Expression: Sub<RHS, Output = Expression>,

Creates a constraint indicating that this expression is lesser than or equal to the right hand side

Source

pub fn geq<RHS: Sub<Expression, Output = Expression>>( self, rhs: RHS, ) -> Constraint

Creates a constraint indicating that this expression is greater than or equal to the right hand side

Source

pub fn eq<RHS>(self, rhs: RHS) -> Constraint
where Expression: Sub<RHS, Output = Expression>,

Creates a constraint indicating that this expression is equal to the right hand side

Source

pub fn add_mul<N: Into<f64>, E: IntoAffineExpression>(&mut self, a: N, b: E)

Performs self = self + (a * b)

Source

pub fn eval_with<S: Solution>(&self, values: &S) -> f64

Trait Implementations§

Source§

impl Add<Expression> for f64

Source§

type Output = Expression

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl Add<Expression> for i32

Source§

type Output = Expression

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<RHS: IntoAffineExpression> Add<RHS> for Expression

Source§

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<RHS: IntoAffineExpression> AddAssign<RHS> for Expression

Source§

fn add_assign(&mut self, rhs: RHS)

Performs the += operation. Read more
Source§

impl Clone for Expression

Source§

fn clone(&self) -> Self

Returns a duplicate 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 Expression

Source§

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

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

impl Default for Expression

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<N: Into<f64>> Div<N> for Expression

Source§

type Output = Expression

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

impl FormatWithVars for Expression

Source§

fn format_with<FUN>( &self, f: &mut Formatter<'_>, variable_format: FUN, ) -> Result
where 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 From<f64> for Expression

Source§

fn from(x: f64) -> Expression

Converts to this type from the input type.
Source§

impl From<i32> for Expression

Source§

fn from(x: i32) -> Expression

Converts to this type from the input type.
Source§

impl<'a> IntoAffineExpression for &'a Expression

This implementation copies all the variables and coefficients from the referenced Expression into the created iterator

Source§

type Iter = <&'a LinearExpression as IntoAffineExpression>::Iter

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) -> Expression
where Self: Sized,

Transform the value into a concrete Expression struct.
Source§

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

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

impl IntoAffineExpression for Expression

Source§

type Iter = <LinearExpression as IntoAffineExpression>::Iter

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) -> Expression
where Self: Sized,

Transform the value into a concrete Expression struct.
Source§

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

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

impl Mul<Expression> for f64

Source§

type Output = Expression

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<Expression> for i32

Source§

type Output = Expression

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

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

Source§

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<N: Into<f64>> MulAssign<N> for Expression

Source§

fn mul_assign(&mut self, rhs: N)

Performs the *= operation. Read more
Source§

impl Neg for Expression

Source§

type Output = Expression

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq for Expression

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

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 Expression

Source§

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 Sub<Expression> for f64

Source§

type Output = Expression

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl Sub<Expression> for i32

Source§

type Output = Expression

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

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

Source§

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<RHS: IntoAffineExpression> SubAssign<RHS> for Expression

Source§

fn sub_assign(&mut self, rhs: RHS)

Performs the -= operation. Read more
Source§

impl<E: IntoAffineExpression> Sum<E> for Expression

Source§

fn sum<I: Iterator<Item = E>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<N, A, B> MulAcc<A, B> for N
where &'x A: for<'x> Mul<&'x B, Output = N>, N: AddAssign,

Source§

fn mul_acc(&mut self, a: &A, b: &B)

Multiply and accumulate in this variable, formally *self += a * b.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.