inequality

(function from pyomo.core.expr.relational_expr)

pyomo.core.expr.relational_expr.inequality(lower=None, body=None, upper=None, strict=False)[source]

A utility function that can be used to declare inequality and ranged inequality expressions.

The expression:

inequality(2, model.x)

is equivalent to:

\[2 \leq x\]

and the expression:

inequality(2, model.x, 3)

is equivalent to:

\[2 \leq x \leq 3\]

Note

Pyomo does not support constructing RangedExpression objects using Python’s chained comparison syntax (lb <= body <= ub).

Python relies on the pairwise comparisons returning intermediates that are convertible to bool, which is incompatible with Pyomo’s operator overloading. Instead, RangedExpression objects should be created using this function.

inequality() allows for any (or all) of lower, body, and upper to be None. What gets returned from the function depends on the number and type of values provided:

No arguments are None

If lower, body, and upper are all non-None, then the function will return a RangedExpression, unless two adjacent arguments (either lower and body, or body and upper) are both constants (e.g., native numeric types or immutable Param objects). If there are two adjacent constant values, then that pair is evaluated. If the result is False, then the constraint is known to be trivially infeasible and inequality() will return False. If the result is True, then the return value is as if the “outer” (lower or upper) argument had been None (see the following).

One argument is None

If one of lower, body, or upper is None, then inequality() will return an InequalityExpression object, unless both arguments are constants (e.g., native numeric types or immutable Param objects), in which case the expression will be evaluated and the resulting bool returned.

Two arguments are None

If two of lower, body, or upper are None, then the remaining argument is returned from inequality().

All None

If all arguments are None, then None is returned

Parameters:
  • lower (int | float | NumericValue | None) – The expression for the lower bound

  • body (int | float | NumericValue | None) – The expression for the body of a ranged constraint

  • upper (int | float | NumericValue | None) – The expression for the upper bound

  • strict (bool) – If True, construct strict inequalities (<); otherwise use <=.

Return type:

RangedExpression | InequalityExpression | NumericValue | int | float | None