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:
termsis always sorted by Variable T.termsnever contains coefficients with abs() < tolerance (effectively zero).
Fields§
§terms: Vec<(T, f64)>§constant: f64Implementations§
Source§impl<T: ExprVariable> LinearExpr<T>
impl<T: ExprVariable> LinearExpr<T>
pub fn new() -> Self
pub fn with_term(var: T, coefficient: f64) -> Self
pub fn with_terms(terms: Vec<(T, f64)>) -> Self
pub fn with_constant(constant: f64) -> Self
pub fn with_terms_and_constant(terms: Vec<(T, f64)>, constant: f64) -> Self
pub fn coefficient(&self, var: &T) -> f64
pub fn add_term(&mut self, var: T, coefficient: f64)
pub fn remove_term(&mut self, var: &T) -> Option<f64>
pub fn add_expr(&mut self, other: &Self)
pub fn sub_expr(&mut self, other: &Self)
pub fn add_scaled_expr(&mut self, other: &Self, scale: f64)
pub fn add_constant(&mut self, constant: f64)
pub fn scale(&mut self, scalar: f64)
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
impl<'a> Add<&'a LinearExpr<DictionaryVariableKey>> for f64
Implements f64 + &Expr
Source§type Output = LinearExpr<DictionaryVariableKey>
type Output = LinearExpr<DictionaryVariableKey>
+ operator.Source§fn add(
self,
expr: &'a LinearExpr<DictionaryVariableKey>,
) -> LinearExpr<DictionaryVariableKey>
fn add( self, expr: &'a LinearExpr<DictionaryVariableKey>, ) -> LinearExpr<DictionaryVariableKey>
+ operation. Read moreSource§impl<'a> Add<&'a LinearExpr<StandardVariableKey>> for f64
Implements f64 + &Expr
impl<'a> Add<&'a LinearExpr<StandardVariableKey>> for f64
Implements f64 + &Expr
Source§type Output = LinearExpr<StandardVariableKey>
type Output = LinearExpr<StandardVariableKey>
+ operator.Source§fn add(
self,
expr: &'a LinearExpr<StandardVariableKey>,
) -> LinearExpr<StandardVariableKey>
fn add( self, expr: &'a LinearExpr<StandardVariableKey>, ) -> LinearExpr<StandardVariableKey>
+ operation. Read moreSource§impl<'a, T: ExprVariable> Add<&'a LinearExpr<T>> for LinearExpr<T>
Implements Expr + &Expr (Reuse LHS)
impl<'a, T: ExprVariable> Add<&'a LinearExpr<T>> for LinearExpr<T>
Implements Expr + &Expr (Reuse LHS)
Source§type Output = LinearExpr<T>
type Output = LinearExpr<T>
+ operator.Source§fn add(self, rhs: &'a LinearExpr<T>) -> Self
fn add(self, rhs: &'a LinearExpr<T>) -> Self
+ operation. Read moreSource§impl<'a> Add<&'a LinearExpr<VariableKey>> for f64
Implements f64 + &Expr
impl<'a> Add<&'a LinearExpr<VariableKey>> for f64
Implements f64 + &Expr
Source§type Output = LinearExpr<VariableKey>
type Output = LinearExpr<VariableKey>
+ operator.Source§fn add(self, expr: &'a LinearExpr<VariableKey>) -> LinearExpr<VariableKey>
fn add(self, expr: &'a LinearExpr<VariableKey>) -> LinearExpr<VariableKey>
+ operation. Read moreSource§impl Add<LinearExpr<DictionaryVariableKey>> for f64
Implements f64 + Expr
impl Add<LinearExpr<DictionaryVariableKey>> for f64
Implements f64 + Expr
Source§type Output = LinearExpr<DictionaryVariableKey>
type Output = LinearExpr<DictionaryVariableKey>
+ operator.Source§fn add(
self,
expr: LinearExpr<DictionaryVariableKey>,
) -> LinearExpr<DictionaryVariableKey>
fn add( self, expr: LinearExpr<DictionaryVariableKey>, ) -> LinearExpr<DictionaryVariableKey>
+ operation. Read moreSource§impl Add<LinearExpr<StandardVariableKey>> for f64
Implements f64 + Expr
impl Add<LinearExpr<StandardVariableKey>> for f64
Implements f64 + Expr
Source§type Output = LinearExpr<StandardVariableKey>
type Output = LinearExpr<StandardVariableKey>
+ operator.Source§fn add(
self,
expr: LinearExpr<StandardVariableKey>,
) -> LinearExpr<StandardVariableKey>
fn add( self, expr: LinearExpr<StandardVariableKey>, ) -> LinearExpr<StandardVariableKey>
+ operation. Read moreSource§impl Add<LinearExpr<VariableKey>> for VariableKey
Implements Var + Expr
impl Add<LinearExpr<VariableKey>> for VariableKey
Implements Var + Expr
Source§type Output = LinearExpr<VariableKey>
type Output = LinearExpr<VariableKey>
+ operator.Source§fn add(self, expr: LinearExpr<VariableKey>) -> Self::Output
fn add(self, expr: LinearExpr<VariableKey>) -> Self::Output
+ operation. Read moreSource§impl Add<LinearExpr<VariableKey>> for f64
Implements f64 + Expr
impl Add<LinearExpr<VariableKey>> for f64
Implements f64 + Expr
Source§type Output = LinearExpr<VariableKey>
type Output = LinearExpr<VariableKey>
+ operator.Source§fn add(self, expr: LinearExpr<VariableKey>) -> LinearExpr<VariableKey>
fn add(self, expr: LinearExpr<VariableKey>) -> LinearExpr<VariableKey>
+ operation. Read moreSource§impl<T: ExprVariable> Add<T> for LinearExpr<T>
Implements Expr + Var
impl<T: ExprVariable> Add<T> for LinearExpr<T>
Implements Expr + Var
Source§impl<'a, T: ExprVariable> Add<f64> for &'a LinearExpr<T>
Implements &Expr + f64 (creates new Owned)
impl<'a, T: ExprVariable> Add<f64> for &'a LinearExpr<T>
Implements &Expr + f64 (creates new Owned)
Source§type Output = LinearExpr<T>
type Output = LinearExpr<T>
+ operator.Source§impl<T: ExprVariable> Add<f64> for LinearExpr<T>
Implements Expr + f64
impl<T: ExprVariable> Add<f64> for LinearExpr<T>
Implements Expr + f64
Source§impl<T: ExprVariable> Add for LinearExpr<T>
Implements Expr + Expr (Reuse LHS)
impl<T: ExprVariable> Add for LinearExpr<T>
Implements Expr + Expr (Reuse LHS)
Source§impl<T: ExprVariable> AddAssign for LinearExpr<T>
Implements Expr += Expr
impl<T: ExprVariable> AddAssign for LinearExpr<T>
Implements Expr += Expr
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moreSource§impl<T: Clone + ExprVariable> Clone for LinearExpr<T>
impl<T: Clone + ExprVariable> Clone for LinearExpr<T>
Source§fn clone(&self) -> LinearExpr<T>
fn clone(&self) -> LinearExpr<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug + ExprVariable> Debug for LinearExpr<T>
impl<T: Debug + ExprVariable> Debug for LinearExpr<T>
Source§impl Display for LinearExpr<DictionaryVariableKey>
impl Display for LinearExpr<DictionaryVariableKey>
Source§impl Display for LinearExpr<StandardVariableKey>
impl Display for LinearExpr<StandardVariableKey>
Source§impl Display for LinearExpr<VariableKey>
impl Display for LinearExpr<VariableKey>
Source§impl<'a, T: ExprVariable> Div<f64> for &'a LinearExpr<T>
Implements &Expr / f64 (creates new Owned)
impl<'a, T: ExprVariable> Div<f64> for &'a LinearExpr<T>
Implements &Expr / f64 (creates new Owned)
Source§type Output = LinearExpr<T>
type Output = LinearExpr<T>
/ operator.Source§impl<T: ExprVariable> Div<f64> for LinearExpr<T>
Implements Expr / f64
impl<T: ExprVariable> Div<f64> for LinearExpr<T>
Implements Expr / f64
Source§impl From<VariableKey> for LinearExpr<VariableKey>
Implements From<Var> for LinearExpr
impl From<VariableKey> for LinearExpr<VariableKey>
Implements From<Var> for LinearExpr
Source§fn from(var: VariableKey) -> Self
fn from(var: VariableKey) -> Self
Source§impl<T: ExprVariable> From<f64> for LinearExpr<T>
Implements From<f64> for LinearExpr.
impl<T: ExprVariable> From<f64> for LinearExpr<T>
Implements From<f64> for LinearExpr.
Source§impl<'a> Mul<&'a LinearExpr<DictionaryVariableKey>> for f64
Implements f64 * &Expr
impl<'a> Mul<&'a LinearExpr<DictionaryVariableKey>> for f64
Implements f64 * &Expr
Source§type Output = LinearExpr<DictionaryVariableKey>
type Output = LinearExpr<DictionaryVariableKey>
* operator.Source§fn mul(
self,
expr: &'a LinearExpr<DictionaryVariableKey>,
) -> LinearExpr<DictionaryVariableKey>
fn mul( self, expr: &'a LinearExpr<DictionaryVariableKey>, ) -> LinearExpr<DictionaryVariableKey>
* operation. Read moreSource§impl<'a> Mul<&'a LinearExpr<StandardVariableKey>> for f64
Implements f64 * &Expr
impl<'a> Mul<&'a LinearExpr<StandardVariableKey>> for f64
Implements f64 * &Expr
Source§type Output = LinearExpr<StandardVariableKey>
type Output = LinearExpr<StandardVariableKey>
* operator.Source§fn mul(
self,
expr: &'a LinearExpr<StandardVariableKey>,
) -> LinearExpr<StandardVariableKey>
fn mul( self, expr: &'a LinearExpr<StandardVariableKey>, ) -> LinearExpr<StandardVariableKey>
* operation. Read moreSource§impl<'a> Mul<&'a LinearExpr<VariableKey>> for f64
Implements f64 * &Expr
impl<'a> Mul<&'a LinearExpr<VariableKey>> for f64
Implements f64 * &Expr
Source§type Output = LinearExpr<VariableKey>
type Output = LinearExpr<VariableKey>
* operator.Source§fn mul(self, expr: &'a LinearExpr<VariableKey>) -> LinearExpr<VariableKey>
fn mul(self, expr: &'a LinearExpr<VariableKey>) -> LinearExpr<VariableKey>
* operation. Read moreSource§impl Mul<LinearExpr<DictionaryVariableKey>> for f64
Implements f64 * Expr
impl Mul<LinearExpr<DictionaryVariableKey>> for f64
Implements f64 * Expr
Source§type Output = LinearExpr<DictionaryVariableKey>
type Output = LinearExpr<DictionaryVariableKey>
* operator.Source§fn mul(
self,
expr: LinearExpr<DictionaryVariableKey>,
) -> LinearExpr<DictionaryVariableKey>
fn mul( self, expr: LinearExpr<DictionaryVariableKey>, ) -> LinearExpr<DictionaryVariableKey>
* operation. Read moreSource§impl Mul<LinearExpr<StandardVariableKey>> for f64
Implements f64 * Expr
impl Mul<LinearExpr<StandardVariableKey>> for f64
Implements f64 * Expr
Source§type Output = LinearExpr<StandardVariableKey>
type Output = LinearExpr<StandardVariableKey>
* operator.Source§fn mul(
self,
expr: LinearExpr<StandardVariableKey>,
) -> LinearExpr<StandardVariableKey>
fn mul( self, expr: LinearExpr<StandardVariableKey>, ) -> LinearExpr<StandardVariableKey>
* operation. Read moreSource§impl Mul<LinearExpr<VariableKey>> for f64
Implements f64 * Expr
impl Mul<LinearExpr<VariableKey>> for f64
Implements f64 * Expr
Source§type Output = LinearExpr<VariableKey>
type Output = LinearExpr<VariableKey>
* operator.Source§fn mul(self, expr: LinearExpr<VariableKey>) -> LinearExpr<VariableKey>
fn mul(self, expr: LinearExpr<VariableKey>) -> LinearExpr<VariableKey>
* operation. Read moreSource§impl<'a, T: ExprVariable> Mul<f64> for &'a LinearExpr<T>
Implements &Expr * f64 (creates new Owned)
impl<'a, T: ExprVariable> Mul<f64> for &'a LinearExpr<T>
Implements &Expr * f64 (creates new Owned)
Source§type Output = LinearExpr<T>
type Output = LinearExpr<T>
* operator.Source§impl<T: ExprVariable> Mul<f64> for LinearExpr<T>
Implements Expr * f64
impl<T: ExprVariable> Mul<f64> for LinearExpr<T>
Implements Expr * f64
Source§impl<'a, T: ExprVariable> Neg for &'a LinearExpr<T>
Implements -&Expr (creates new Owned)
impl<'a, T: ExprVariable> Neg for &'a LinearExpr<T>
Implements -&Expr (creates new Owned)
Source§type Output = LinearExpr<T>
type Output = LinearExpr<T>
- operator.Source§fn neg(self) -> LinearExpr<T>
fn neg(self) -> LinearExpr<T>
- operation. Read moreSource§impl<T: ExprVariable> Neg for LinearExpr<T>
Implements -Expr
impl<T: ExprVariable> Neg for LinearExpr<T>
Implements -Expr
Source§impl<'a> Sub<&'a LinearExpr<DictionaryVariableKey>> for f64
Implements f64 - &Expr
impl<'a> Sub<&'a LinearExpr<DictionaryVariableKey>> for f64
Implements f64 - &Expr
Source§type Output = LinearExpr<DictionaryVariableKey>
type Output = LinearExpr<DictionaryVariableKey>
- operator.Source§fn sub(
self,
expr: &'a LinearExpr<DictionaryVariableKey>,
) -> LinearExpr<DictionaryVariableKey>
fn sub( self, expr: &'a LinearExpr<DictionaryVariableKey>, ) -> LinearExpr<DictionaryVariableKey>
- operation. Read moreSource§impl<'a> Sub<&'a LinearExpr<StandardVariableKey>> for f64
Implements f64 - &Expr
impl<'a> Sub<&'a LinearExpr<StandardVariableKey>> for f64
Implements f64 - &Expr
Source§type Output = LinearExpr<StandardVariableKey>
type Output = LinearExpr<StandardVariableKey>
- operator.Source§fn sub(
self,
expr: &'a LinearExpr<StandardVariableKey>,
) -> LinearExpr<StandardVariableKey>
fn sub( self, expr: &'a LinearExpr<StandardVariableKey>, ) -> LinearExpr<StandardVariableKey>
- operation. Read moreSource§impl<'a, T: ExprVariable> Sub<&'a LinearExpr<T>> for LinearExpr<T>
Implements Expr - &Expr (Reuse LHS)
impl<'a, T: ExprVariable> Sub<&'a LinearExpr<T>> for LinearExpr<T>
Implements Expr - &Expr (Reuse LHS)
Source§type Output = LinearExpr<T>
type Output = LinearExpr<T>
- operator.Source§fn sub(self, rhs: &'a LinearExpr<T>) -> Self
fn sub(self, rhs: &'a LinearExpr<T>) -> Self
- operation. Read moreSource§impl<'a> Sub<&'a LinearExpr<VariableKey>> for f64
Implements f64 - &Expr
impl<'a> Sub<&'a LinearExpr<VariableKey>> for f64
Implements f64 - &Expr
Source§type Output = LinearExpr<VariableKey>
type Output = LinearExpr<VariableKey>
- operator.Source§fn sub(self, expr: &'a LinearExpr<VariableKey>) -> LinearExpr<VariableKey>
fn sub(self, expr: &'a LinearExpr<VariableKey>) -> LinearExpr<VariableKey>
- operation. Read moreSource§impl Sub<LinearExpr<DictionaryVariableKey>> for f64
Implements f64 - Expr
impl Sub<LinearExpr<DictionaryVariableKey>> for f64
Implements f64 - Expr
Source§type Output = LinearExpr<DictionaryVariableKey>
type Output = LinearExpr<DictionaryVariableKey>
- operator.Source§fn sub(
self,
expr: LinearExpr<DictionaryVariableKey>,
) -> LinearExpr<DictionaryVariableKey>
fn sub( self, expr: LinearExpr<DictionaryVariableKey>, ) -> LinearExpr<DictionaryVariableKey>
- operation. Read moreSource§impl Sub<LinearExpr<StandardVariableKey>> for f64
Implements f64 - Expr
impl Sub<LinearExpr<StandardVariableKey>> for f64
Implements f64 - Expr
Source§type Output = LinearExpr<StandardVariableKey>
type Output = LinearExpr<StandardVariableKey>
- operator.Source§fn sub(
self,
expr: LinearExpr<StandardVariableKey>,
) -> LinearExpr<StandardVariableKey>
fn sub( self, expr: LinearExpr<StandardVariableKey>, ) -> LinearExpr<StandardVariableKey>
- operation. Read moreSource§impl Sub<LinearExpr<VariableKey>> for VariableKey
Implements Var - Expr
impl Sub<LinearExpr<VariableKey>> for VariableKey
Implements Var - Expr
Source§type Output = LinearExpr<VariableKey>
type Output = LinearExpr<VariableKey>
- operator.Source§fn sub(self, expr: LinearExpr<VariableKey>) -> Self::Output
fn sub(self, expr: LinearExpr<VariableKey>) -> Self::Output
- operation. Read moreSource§impl Sub<LinearExpr<VariableKey>> for f64
Implements f64 - Expr
impl Sub<LinearExpr<VariableKey>> for f64
Implements f64 - Expr
Source§type Output = LinearExpr<VariableKey>
type Output = LinearExpr<VariableKey>
- operator.Source§fn sub(self, expr: LinearExpr<VariableKey>) -> LinearExpr<VariableKey>
fn sub(self, expr: LinearExpr<VariableKey>) -> LinearExpr<VariableKey>
- operation. Read moreSource§impl<T: ExprVariable> Sub<T> for LinearExpr<T>
Implements Expr - Var
impl<T: ExprVariable> Sub<T> for LinearExpr<T>
Implements Expr - Var
Source§impl<'a, T: ExprVariable> Sub<f64> for &'a LinearExpr<T>
Implements &Expr - f64 (creates new Owned)
impl<'a, T: ExprVariable> Sub<f64> for &'a LinearExpr<T>
Implements &Expr - f64 (creates new Owned)
Source§type Output = LinearExpr<T>
type Output = LinearExpr<T>
- operator.Source§impl<T: ExprVariable> Sub<f64> for LinearExpr<T>
Implements Expr - f64
impl<T: ExprVariable> Sub<f64> for LinearExpr<T>
Implements Expr - f64
Source§impl<T: ExprVariable> Sub for LinearExpr<T>
Implements Expr - Expr (Reuse LHS)
impl<T: ExprVariable> Sub for LinearExpr<T>
Implements Expr - Expr (Reuse LHS)
Source§impl<T: ExprVariable> SubAssign for LinearExpr<T>
Implements Expr -= Expr
impl<T: ExprVariable> SubAssign for LinearExpr<T>
Implements Expr -= Expr
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read more