lumix.core.expressions.LXNonLinearExpression

class lumix.core.expressions.LXNonLinearExpression(linear_terms=<factory>, nonlinear_terms=<factory>, constant=0.0)[source]

Non-linear expression containing arbitrary non-linear terms.

Supports: - Bilinear terms (x * y) - Absolute value (x) - Min/max functions - Piecewise-linear approximations - Conditional expressions - Custom non-linear functions

These will be automatically linearized by the Linearizer engine.

Example

# Create nonlinear expression expr = LXNonLinearExpression()

# Add bilinear product expr.add_product(length, width)

# Add absolute value expr.add_abs(deviation)

# Add piecewise function expr.add_piecewise(time, lambda t: math.exp(t), num_segments=30)

Parameters:
__init__(linear_terms=<factory>, nonlinear_terms=<factory>, constant=0.0)
Parameters:
Return type:

None

Methods

__init__([linear_terms, nonlinear_terms, ...])

add_abs(var[, coeff])

Add absolute value term: coeff * var

add_indicator(binary_var, condition, linear_expr)

Add conditional constraint: if binary_var == condition then linear_expr

add_linear(expr)

Add linear terms.

add_max(*vars[, coefficients])

Add maximum function: max(vars)

add_min(*vars[, coefficients])

Add minimum function: min(vars)

add_nonlinear_term(term)

Add pre-constructed non-linear term.

add_nonlinear_terms(terms)

Add multiple non-linear terms.

add_piecewise(var, func[, num_segments, ...])

Add piecewise-linear approximation of arbitrary function.

add_product(var1, var2[, coeff])

Add bilinear product: coeff * var1 * var2

Attributes

linear_terms: LXLinearExpression
nonlinear_terms: List[Any]
constant: float = 0.0
add_linear(expr)[source]

Add linear terms.

Parameters:

expr (LXLinearExpression) – Linear expression to add

Return type:

Self

Returns:

Self for chaining

add_abs(var, coeff=1.0)[source]

Add absolute value term: coeff * var

Parameters:
  • var (LXVariable) – Variable to take absolute value of

  • coeff (float) – Coefficient (default: 1.0)

Return type:

Self

Returns:

Self for chaining

Example

# Minimize absolute deviation expr.add_abs(actual - target)

add_min(*vars, coefficients=None)[source]

Add minimum function: min(vars)

Parameters:
Return type:

Self

Returns:

Self for chaining

Example

# Minimum of three costs expr.add_min(cost_a, cost_b, cost_c)

add_max(*vars, coefficients=None)[source]

Add maximum function: max(vars)

Parameters:
Return type:

Self

Returns:

Self for chaining

Example

# Maximum capacity expr.add_max(capacity_1, capacity_2, capacity_3)

add_product(var1, var2, coeff=1.0)[source]

Add bilinear product: coeff * var1 * var2

Automatically linearized based on variable types: - Binary × Binary: AND logic - Binary × Continuous: Big-M method - Continuous × Continuous: McCormick envelopes

Parameters:
Return type:

Self

Returns:

Self for chaining

Example

# Rectangle area expr.add_product(length, width)

# Facility open × flow amount expr.add_product(is_open, flow_amount)

add_indicator(binary_var, condition, linear_expr)[source]

Add conditional constraint: if binary_var == condition then linear_expr

Parameters:
  • binary_var (LXVariable) – Binary variable

  • condition (bool) – Condition value (True or False)

  • linear_expr (LXLinearExpression) – Expression to apply when condition is met

Return type:

Self

Returns:

Self for chaining

Example:

# If warehouse is open, then demand must be met
expr.add_indicator(
    is_open,
    True,
    LXLinearExpression().add_term(supply, 1.0)
)
add_piecewise(var, func, num_segments=20, x_min=None, x_max=None, adaptive=True, method='sos2')[source]

Add piecewise-linear approximation of arbitrary function.

Parameters:
  • var (LXVariable) – Input variable

  • func (Callable[[float], float]) – Function to approximate (e.g., lambda x: math.exp(x))

  • num_segments (int) – Number of linear segments

  • x_min (Optional[float]) – Minimum domain value (default: var.lower_bound)

  • x_max (Optional[float]) – Maximum domain value (default: var.upper_bound)

  • adaptive (bool) – Use adaptive breakpoint generation

  • method (Literal['sos2', 'incremental', 'logarithmic']) – Linearization method (“sos2”, “incremental”, “logarithmic”)

Return type:

Self

Returns:

Self for chaining

Example:

# Exponential growth
expr.add_piecewise(time, lambda t: math.exp(t), num_segments=30)

# Custom discount curve
expr.add_piecewise(
    quantity,
    lambda q: 1.0 if q < 100 else 0.9 if q < 1000 else 0.8,
    num_segments=50
)
add_nonlinear_term(term)[source]

Add pre-constructed non-linear term.

Parameters:

term (Any) – Non-linear term object

Return type:

Self

Returns:

Self for chaining

add_nonlinear_terms(terms)[source]

Add multiple non-linear terms.

Parameters:

terms (List[Any]) – List of non-linear terms

Return type:

Self

Returns:

Self for chaining

__init__(linear_terms=<factory>, nonlinear_terms=<factory>, constant=0.0)
Parameters:
Return type:

None