Normalize (cpmpy.transformations.normalize)
Normalize a toplevel list, or simplify Boolean expressions.
- cpmpy.transformations.normalize.simplify_boolean(lst_of_expr: list[Expression], num_context=False) list[Expression][source]
Removes Boolean constants from CPMpy expressions, except inside global constraints/functions.
Solver interfaces are expected to handle typing of Boolean constants in global constraints/functions themselves. Expects all
notoperators to have been eliminated bypush_down_negation()beforehand (exceptnotover aGlobalConstraint).Boolean constants are promoted to integers in numerical context (e.g. in wsum); integers are never converted to Booleans.
- Parameters:
lst_of_expr (list[Expression]) – list of CPMpy expressions
num_context (bool) – whether the expressions are used as numeric arguments (default: False)
- Returns:
simplified expressions; returns
lst_of_exprunchanged if nothing changed- Return type:
list[Expression]
- cpmpy.transformations.normalize.toplevel_list(cpm_expr, merge_and=True)[source]
Unravels nested lists and top-level AND’s and ensures every element returned is a CPMpy Expression with
is_bool()true.- Parameters:
cpm_expr – Expression or list of Expressions
merge_and – if True then a toplevel ‘and’ will have its arguments merged at top level