lumix.nonlinear.terms.LXAbsoluteTerm¶
- class lumix.nonlinear.terms.LXAbsoluteTerm(var, coefficient=1.0)[source]¶
Absolute value term: x.
Represents the absolute value of a variable, which can be linearized using auxiliary variables and linear constraints. The linearization introduces a new variable z and constraints: z >= x and z >= -x.
- Parameters:
var (LXVariable)
coefficient (float)
- var¶
The variable to take the absolute value of.
- coefficient¶
Coefficient to multiply the absolute value by (default: 1.0).
Example
Basic absolute value term:
from lumix.nonlinear import LXAbsoluteTerm from lumix.core import LXVariable # Minimize absolute deviation from target actual = LXVariable[Product, float]("actual").from_data(products) abs_deviation = LXAbsoluteTerm(var=actual, coefficient=1.0)
With coefficient:
# Weighted absolute penalty penalty = LXAbsoluteTerm(var=deviation, coefficient=10.0)
Note
The linearization creates auxiliary variables and adds constraints automatically during the model building phase. The auxiliary variable z will appear in the objective function or constraints where the absolute value is used.
- __init__(var, coefficient=1.0)¶
- Parameters:
var (LXVariable)
coefficient (float)
- Return type:
None
Methods
__init__(var[, coefficient])Attributes
-
var:
LXVariable¶
- __init__(var, coefficient=1.0)¶
- Parameters:
var (LXVariable)
coefficient (float)
- Return type:
None