Skip to main content

LinearExpr

Struct LinearExpr 

Source
pub struct LinearExpr<T: ExprVariable> {
    pub terms: Vec<(T, f64)>,
    pub constant: f64,
}
Expand description

A linear expression stored as a sorted sparse vector. Invariants:

  1. terms is always sorted by Variable T.
  2. terms never contains coefficients with abs() < tolerance (effectively zero).

Fields§

§terms: Vec<(T, f64)>§constant: f64

Implementations§

Source§

impl<T: ExprVariable> LinearExpr<T>

Source

pub fn new() -> Self

Source

pub fn with_term(var: T, coefficient: f64) -> Self

Source

pub fn with_terms(terms: Vec<(T, f64)>) -> Self

Source

pub fn with_constant(constant: f64) -> Self

Source

pub fn with_terms_and_constant(terms: Vec<(T, f64)>, constant: f64) -> Self

Source

pub fn coefficient(&self, var: &T) -> f64

Source

pub fn add_term(&mut self, var: T, coefficient: f64)

Source

pub fn remove_term(&mut self, var: &T) -> Option<f64>

Source

pub fn add_expr(&mut self, other: &Self)

Source

pub fn sub_expr(&mut self, other: &Self)

Source

pub fn add_scaled_expr(&mut self, other: &Self, scale: f64)

Source

pub fn add_constant(&mut self, constant: f64)

Source

pub fn scale(&mut self, scalar: f64)

Source

pub fn replace_var_with_expr( &mut self, var: T, replacement_expr: &LinearExpr<T>, ) -> Option<f64>

Trait Implementations§

Source§

impl<'a> Add<&'a LinearExpr<DictionaryVariableKey>> for f64

Implements f64 + &Expr

Source§

type Output = LinearExpr<DictionaryVariableKey>

The resulting type after applying the + operator.
Source§

fn add( self, expr: &'a LinearExpr<DictionaryVariableKey>, ) -> LinearExpr<DictionaryVariableKey>

Performs the + operation. Read more
Source§

impl<'a> Add<&'a LinearExpr<StandardVariableKey>> for f64

Implements f64 + &Expr

Source§

type Output = LinearExpr<StandardVariableKey>

The resulting type after applying the + operator.
Source§

fn add( self, expr: &'a LinearExpr<StandardVariableKey>, ) -> LinearExpr<StandardVariableKey>

Performs the + operation. Read more
Source§

impl<'a, T: ExprVariable> Add<&'a LinearExpr<T>> for LinearExpr<T>

Implements Expr + &Expr (Reuse LHS)

Source§

type Output = LinearExpr<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &'a LinearExpr<T>) -> Self

Performs the + operation. Read more
Source§

impl<'a> Add<&'a LinearExpr<VariableKey>> for f64

Implements f64 + &Expr

Source§

type Output = LinearExpr<VariableKey>

The resulting type after applying the + operator.
Source§

fn add(self, expr: &'a LinearExpr<VariableKey>) -> LinearExpr<VariableKey>

Performs the + operation. Read more
Source§

impl Add<LinearExpr<DictionaryVariableKey>> for f64

Implements f64 + Expr

Source§

type Output = LinearExpr<DictionaryVariableKey>

The resulting type after applying the + operator.
Source§

fn add( self, expr: LinearExpr<DictionaryVariableKey>, ) -> LinearExpr<DictionaryVariableKey>

Performs the + operation. Read more
Source§

impl Add<LinearExpr<StandardVariableKey>> for f64

Implements f64 + Expr

Source§

type Output = LinearExpr<StandardVariableKey>

The resulting type after applying the + operator.
Source§

fn add( self, expr: LinearExpr<StandardVariableKey>, ) -> LinearExpr<StandardVariableKey>

Performs the + operation. Read more
Source§

impl Add<LinearExpr<VariableKey>> for VariableKey

Implements Var + Expr

Source§

type Output = LinearExpr<VariableKey>

The resulting type after applying the + operator.
Source§

fn add(self, expr: LinearExpr<VariableKey>) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<LinearExpr<VariableKey>> for f64

Implements f64 + Expr

Source§

type Output = LinearExpr<VariableKey>

The resulting type after applying the + operator.
Source§

fn add(self, expr: LinearExpr<VariableKey>) -> LinearExpr<VariableKey>

Performs the + operation. Read more
Source§

impl<T: ExprVariable> Add<T> for LinearExpr<T>

Implements Expr + Var

Source§

type Output = LinearExpr<T>

The resulting type after applying the + operator.
Source§

fn add(self, var: T) -> Self

Performs the + operation. Read more
Source§

impl<'a, T: ExprVariable> Add<f64> for &'a LinearExpr<T>

Implements &Expr + f64 (creates new Owned)

Source§

type Output = LinearExpr<T>

The resulting type after applying the + operator.
Source§

fn add(self, constant: f64) -> LinearExpr<T>

Performs the + operation. Read more
Source§

impl<T: ExprVariable> Add<f64> for LinearExpr<T>

Implements Expr + f64

Source§

type Output = LinearExpr<T>

The resulting type after applying the + operator.
Source§

fn add(self, constant: f64) -> Self

Performs the + operation. Read more
Source§

impl<T: ExprVariable> Add for LinearExpr<T>

Implements Expr + Expr (Reuse LHS)

Source§

type Output = LinearExpr<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: ExprVariable> AddAssign for LinearExpr<T>

Implements Expr += Expr

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

impl<T: Clone + ExprVariable> Clone for LinearExpr<T>

Source§

fn clone(&self) -> LinearExpr<T>

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<T: Debug + ExprVariable> Debug for LinearExpr<T>

Source§

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

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

impl Display for LinearExpr<DictionaryVariableKey>

Source§

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

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

impl Display for LinearExpr<StandardVariableKey>

Source§

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

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

impl Display for LinearExpr<VariableKey>

Source§

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

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

impl<'a, T: ExprVariable> Div<f64> for &'a LinearExpr<T>

Implements &Expr / f64 (creates new Owned)

Source§

type Output = LinearExpr<T>

The resulting type after applying the / operator.
Source§

fn div(self, scalar: f64) -> LinearExpr<T>

Performs the / operation. Read more
Source§

impl<T: ExprVariable> Div<f64> for LinearExpr<T>

Implements Expr / f64

Source§

type Output = LinearExpr<T>

The resulting type after applying the / operator.
Source§

fn div(self, scalar: f64) -> Self

Performs the / operation. Read more
Source§

impl From<VariableKey> for LinearExpr<VariableKey>

Implements From<Var> for LinearExpr

Source§

fn from(var: VariableKey) -> Self

Converts to this type from the input type.
Source§

impl<T: ExprVariable> From<f64> for LinearExpr<T>

Implements From<f64> for LinearExpr.

Source§

fn from(constant: f64) -> Self

Converts to this type from the input type.
Source§

impl<'a> Mul<&'a LinearExpr<DictionaryVariableKey>> for f64

Implements f64 * &Expr

Source§

type Output = LinearExpr<DictionaryVariableKey>

The resulting type after applying the * operator.
Source§

fn mul( self, expr: &'a LinearExpr<DictionaryVariableKey>, ) -> LinearExpr<DictionaryVariableKey>

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a LinearExpr<StandardVariableKey>> for f64

Implements f64 * &Expr

Source§

type Output = LinearExpr<StandardVariableKey>

The resulting type after applying the * operator.
Source§

fn mul( self, expr: &'a LinearExpr<StandardVariableKey>, ) -> LinearExpr<StandardVariableKey>

Performs the * operation. Read more
Source§

impl<'a> Mul<&'a LinearExpr<VariableKey>> for f64

Implements f64 * &Expr

Source§

type Output = LinearExpr<VariableKey>

The resulting type after applying the * operator.
Source§

fn mul(self, expr: &'a LinearExpr<VariableKey>) -> LinearExpr<VariableKey>

Performs the * operation. Read more
Source§

impl Mul<LinearExpr<DictionaryVariableKey>> for f64

Implements f64 * Expr

Source§

type Output = LinearExpr<DictionaryVariableKey>

The resulting type after applying the * operator.
Source§

fn mul( self, expr: LinearExpr<DictionaryVariableKey>, ) -> LinearExpr<DictionaryVariableKey>

Performs the * operation. Read more
Source§

impl Mul<LinearExpr<StandardVariableKey>> for f64

Implements f64 * Expr

Source§

type Output = LinearExpr<StandardVariableKey>

The resulting type after applying the * operator.
Source§

fn mul( self, expr: LinearExpr<StandardVariableKey>, ) -> LinearExpr<StandardVariableKey>

Performs the * operation. Read more
Source§

impl Mul<LinearExpr<VariableKey>> for f64

Implements f64 * Expr

Source§

type Output = LinearExpr<VariableKey>

The resulting type after applying the * operator.
Source§

fn mul(self, expr: LinearExpr<VariableKey>) -> LinearExpr<VariableKey>

Performs the * operation. Read more
Source§

impl<'a, T: ExprVariable> Mul<f64> for &'a LinearExpr<T>

Implements &Expr * f64 (creates new Owned)

Source§

type Output = LinearExpr<T>

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: f64) -> LinearExpr<T>

Performs the * operation. Read more
Source§

impl<T: ExprVariable> Mul<f64> for LinearExpr<T>

Implements Expr * f64

Source§

type Output = LinearExpr<T>

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: f64) -> Self

Performs the * operation. Read more
Source§

impl<'a, T: ExprVariable> Neg for &'a LinearExpr<T>

Implements -&Expr (creates new Owned)

Source§

type Output = LinearExpr<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> LinearExpr<T>

Performs the unary - operation. Read more
Source§

impl<T: ExprVariable> Neg for LinearExpr<T>

Implements -Expr

Source§

type Output = LinearExpr<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<'a> Sub<&'a LinearExpr<DictionaryVariableKey>> for f64

Implements f64 - &Expr

Source§

type Output = LinearExpr<DictionaryVariableKey>

The resulting type after applying the - operator.
Source§

fn sub( self, expr: &'a LinearExpr<DictionaryVariableKey>, ) -> LinearExpr<DictionaryVariableKey>

Performs the - operation. Read more
Source§

impl<'a> Sub<&'a LinearExpr<StandardVariableKey>> for f64

Implements f64 - &Expr

Source§

type Output = LinearExpr<StandardVariableKey>

The resulting type after applying the - operator.
Source§

fn sub( self, expr: &'a LinearExpr<StandardVariableKey>, ) -> LinearExpr<StandardVariableKey>

Performs the - operation. Read more
Source§

impl<'a, T: ExprVariable> Sub<&'a LinearExpr<T>> for LinearExpr<T>

Implements Expr - &Expr (Reuse LHS)

Source§

type Output = LinearExpr<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &'a LinearExpr<T>) -> Self

Performs the - operation. Read more
Source§

impl<'a> Sub<&'a LinearExpr<VariableKey>> for f64

Implements f64 - &Expr

Source§

type Output = LinearExpr<VariableKey>

The resulting type after applying the - operator.
Source§

fn sub(self, expr: &'a LinearExpr<VariableKey>) -> LinearExpr<VariableKey>

Performs the - operation. Read more
Source§

impl Sub<LinearExpr<DictionaryVariableKey>> for f64

Implements f64 - Expr

Source§

type Output = LinearExpr<DictionaryVariableKey>

The resulting type after applying the - operator.
Source§

fn sub( self, expr: LinearExpr<DictionaryVariableKey>, ) -> LinearExpr<DictionaryVariableKey>

Performs the - operation. Read more
Source§

impl Sub<LinearExpr<StandardVariableKey>> for f64

Implements f64 - Expr

Source§

type Output = LinearExpr<StandardVariableKey>

The resulting type after applying the - operator.
Source§

fn sub( self, expr: LinearExpr<StandardVariableKey>, ) -> LinearExpr<StandardVariableKey>

Performs the - operation. Read more
Source§

impl Sub<LinearExpr<VariableKey>> for VariableKey

Implements Var - Expr

Source§

type Output = LinearExpr<VariableKey>

The resulting type after applying the - operator.
Source§

fn sub(self, expr: LinearExpr<VariableKey>) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<LinearExpr<VariableKey>> for f64

Implements f64 - Expr

Source§

type Output = LinearExpr<VariableKey>

The resulting type after applying the - operator.
Source§

fn sub(self, expr: LinearExpr<VariableKey>) -> LinearExpr<VariableKey>

Performs the - operation. Read more
Source§

impl<T: ExprVariable> Sub<T> for LinearExpr<T>

Implements Expr - Var

Source§

type Output = LinearExpr<T>

The resulting type after applying the - operator.
Source§

fn sub(self, var: T) -> Self

Performs the - operation. Read more
Source§

impl<'a, T: ExprVariable> Sub<f64> for &'a LinearExpr<T>

Implements &Expr - f64 (creates new Owned)

Source§

type Output = LinearExpr<T>

The resulting type after applying the - operator.
Source§

fn sub(self, constant: f64) -> LinearExpr<T>

Performs the - operation. Read more
Source§

impl<T: ExprVariable> Sub<f64> for LinearExpr<T>

Implements Expr - f64

Source§

type Output = LinearExpr<T>

The resulting type after applying the - operator.
Source§

fn sub(self, constant: f64) -> Self

Performs the - operation. Read more
Source§

impl<T: ExprVariable> Sub for LinearExpr<T>

Implements Expr - Expr (Reuse LHS)

Source§

type Output = LinearExpr<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: ExprVariable> SubAssign for LinearExpr<T>

Implements Expr -= Expr

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for LinearExpr<T>

§

impl<T> RefUnwindSafe for LinearExpr<T>
where T: RefUnwindSafe,

§

impl<T> Send for LinearExpr<T>
where T: Send,

§

impl<T> Sync for LinearExpr<T>
where T: Sync,

§

impl<T> Unpin for LinearExpr<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for LinearExpr<T>

§

impl<T> UnwindSafe for LinearExpr<T>
where T: UnwindSafe,

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.