Expression utilities (cpmpy.expressions.utils)

Internal utilities for expression handling.

is_int

can it be interpreted as an integer? (incl bool and numpy variants)

is_num

is it an int or float? (incl numpy variants)

is_pure_list

is it a list or tuple?

is_any_list

is it a list or tuple or numpy array?

flatlist

recursively flatten arguments into one single list

all_pairs

returns all pairwise combinations of elements in args

argval

returns .value() of Expression, otherwise the variable itself

eval_comparison

Internal function: evaluates the textual str_op comparison operator lhs <str_op> rhs

cpmpy.expressions.utils.all_pairs(args)[source]

returns all pairwise combinations of elements in args

cpmpy.expressions.utils.argval(a)[source]

returns .value() of Expression, otherwise the variable itself

We check with hasattr instead of isinstance to avoid circular dependency

cpmpy.expressions.utils.eval_comparison(str_op, lhs, rhs)[source]

Internal function: evaluates the textual str_op comparison operator lhs <str_op> rhs

Valid str_op’s: * ‘==’ * ‘!=’ * ‘>’ * ‘>=’ * ‘<’ * ‘<=’

Especially useful in decomposition and transformation functions that already involve a comparison.

cpmpy.expressions.utils.flatlist(args)[source]

recursively flatten arguments into one single list

cpmpy.expressions.utils.get_bounds(expr)[source]

return the bounds of the expression returns appropriately rounded integers

cpmpy.expressions.utils.is_any_list(arg)[source]

is it a list or tuple or numpy array?

cpmpy.expressions.utils.is_bool(arg)[source]

is it a boolean (incl numpy variants)

cpmpy.expressions.utils.is_boolexpr(expr)[source]

is the argument a boolean expression or a boolean value

cpmpy.expressions.utils.is_false_cst(arg)[source]

is the argument the constant False (can be of type bool, np.bool and BoolVal)

cpmpy.expressions.utils.is_int(arg)[source]

can it be interpreted as an integer? (incl bool and numpy variants)

cpmpy.expressions.utils.is_num(arg)[source]

is it an int or float? (incl numpy variants)

cpmpy.expressions.utils.is_pure_list(arg)[source]

is it a list or tuple?

cpmpy.expressions.utils.is_true_cst(arg)[source]

is the argument the constant True (can be of type bool, np.bool and BoolVal)