lumix.nonlinear.terms.LXIndicatorTerm¶
- class lumix.nonlinear.terms.LXIndicatorTerm(binary_var, condition, linear_expr, sense='<=', rhs=0.0)[source]¶
Conditional constraint: if binary_var == condition then constraint holds.
Represents a constraint that is only enforced when a binary variable takes a specific value. This is also known as an indicator constraint or conditional constraint.
- The linearization uses the Big-M method:
If condition=True and sense=’<=’: expr <= rhs + M*(1-b)
If condition=False and sense=’<=’: expr <= rhs + M*b
Similar formulations for ‘>=’ and ‘==’
- Parameters:
binary_var (LXVariable)
condition (bool)
linear_expr (LXLinearExpression)
sense (Literal['<=', '>=', '=='])
rhs (float)
- binary_var¶
The binary variable that controls the constraint activation.
- condition¶
Value of binary_var that activates the constraint (True or False).
- linear_expr¶
The linear expression on the left-hand side of the constraint.
- sense¶
Constraint sense - ‘<=’, ‘>=’, or ‘==’ (default: ‘<=’).
- rhs¶
Right-hand side value of the constraint (default: 0.0).
Example
Minimum demand when warehouse is open:
from lumix.nonlinear import LXIndicatorTerm from lumix.core import LXVariable, LXLinearExpression # If warehouse is open, then demand must be >= minimum is_open = LXVariable[Warehouse, int]("is_open").binary() demand = LXVariable[Warehouse, float]("demand").continuous() demand_expr = LXLinearExpression().add_term(demand, 1.0) min_demand_constraint = LXIndicatorTerm( binary_var=is_open, condition=True, # When is_open == 1 linear_expr=demand_expr, sense='>=', rhs=100.0 # minimum_demand )
Maximum capacity when machine is active:
# If machine is active, production <= capacity is_active = LXVariable[Machine, int]("is_active").binary() production = LXVariable[Machine, float]("production").continuous() prod_expr = LXLinearExpression().add_term(production, 1.0) capacity_constraint = LXIndicatorTerm( binary_var=is_active, condition=True, linear_expr=prod_expr, sense='<=', rhs=500.0 # capacity )
Route selection constraint:
# If route NOT selected, flow must be zero route_selected = LXVariable[Route, int]("selected").binary() flow = LXVariable[Route, float]("flow").continuous() flow_expr = LXLinearExpression().add_term(flow, 1.0) no_flow_constraint = LXIndicatorTerm( binary_var=route_selected, condition=False, # When selected == 0 linear_expr=flow_expr, sense='==', rhs=0.0 )
Note
The Big-M method requires selecting an appropriate value of M (big-M constant). The linearization engine typically computes M based on variable bounds.
If M is too small, the constraint may not be properly enforced. If M is too large, it can cause numerical issues in the solver.
- __init__(binary_var, condition, linear_expr, sense='<=', rhs=0.0)¶
- Parameters:
binary_var (LXVariable)
condition (bool)
linear_expr (LXLinearExpression)
sense (Literal['<=', '>=', '=='])
rhs (float)
- Return type:
None
Methods
__init__(binary_var, condition, linear_expr)Attributes
-
binary_var:
LXVariable¶
-
linear_expr:
LXLinearExpression¶
- __init__(binary_var, condition, linear_expr, sense='<=', rhs=0.0)¶
- Parameters:
binary_var (LXVariable)
condition (bool)
linear_expr (LXLinearExpression)
sense (Literal['<=', '>=', '=='])
rhs (float)
- Return type:
None