pub struct LinearExpr {
pub constant: Rational,
pub coefficients: BTreeMap<i64, Rational>,
}Expand description
A linear expression of the form c₀ + c₁x₁ + c₂x₂ + … + cₙxₙ.
Stored as a constant term plus a sparse map of variable coefficients. Variables with coefficient 0 are automatically removed.
§Representation
The expression 3 + 2x - y is stored as:
constant = 3coefficients = {0: 2, 1: -1}(assuming x is var 0, y is var 1)
Fields§
§constant: RationalThe constant term c₀.
coefficients: BTreeMap<i64, Rational>Maps variable index to its coefficient (sparse representation).
Implementations§
Source§impl LinearExpr
impl LinearExpr
Sourcepub fn add(&self, other: &LinearExpr) -> LinearExpr
pub fn add(&self, other: &LinearExpr) -> LinearExpr
Add two linear expressions
Sourcepub fn neg(&self) -> LinearExpr
pub fn neg(&self) -> LinearExpr
Negate a linear expression
Sourcepub fn sub(&self, other: &LinearExpr) -> LinearExpr
pub fn sub(&self, other: &LinearExpr) -> LinearExpr
Subtract two linear expressions
Sourcepub fn scale(&self, c: &Rational) -> LinearExpr
pub fn scale(&self, c: &Rational) -> LinearExpr
Scale a linear expression by a rational constant
Sourcepub fn is_constant(&self) -> bool
pub fn is_constant(&self) -> bool
Check if this is a constant expression (no variables)
Trait Implementations§
Source§impl Clone for LinearExpr
impl Clone for LinearExpr
Source§fn clone(&self) -> LinearExpr
fn clone(&self) -> LinearExpr
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LinearExpr
impl Debug for LinearExpr
Source§impl PartialEq for LinearExpr
impl PartialEq for LinearExpr
impl Eq for LinearExpr
impl StructuralPartialEq for LinearExpr
Auto Trait Implementations§
impl Freeze for LinearExpr
impl RefUnwindSafe for LinearExpr
impl Send for LinearExpr
impl Sync for LinearExpr
impl Unpin for LinearExpr
impl UnwindSafe for LinearExpr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more