Skip to content

Commit

Permalink
prepare use of has_nested in push_down_negation
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomSerg committed May 21, 2024
1 parent a762b26 commit fcbe809
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions cpmpy/transformations/flatten_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ def flatten_constraint(expr, pdn=True, _has_nested=None):
# transformation, that calls (preceding) transformations itself
# e.g. `toplevel_list()` ensures it is a list
lst_of_expr = toplevel_list(expr) # ensure it is a list
lst_of_expr = push_down_negation(lst_of_expr) # push negation into the arguments to simplify expressions
expr_has_nested = _has_nested#[has_nested(e) for e in lst_of_expr]
lst_of_expr = simplify_boolean(lst_of_expr, _has_nested=expr_has_nested) # simplify boolean expressions, and ensure types are correct
lst_of_expr = push_down_negation(lst_of_expr, _has_nested=_has_nested) # push negation into the arguments to simplify expressions
# expr_has_nested = _has_nested#[has_nested(e) for e in lst_of_expr]
lst_of_expr = simplify_boolean(lst_of_expr, _has_nested=_has_nested) # simplify boolean expressions, and ensure types are correct
for i_expr, expr in enumerate(lst_of_expr):
if not expr_has_nested[i_expr]:
if _has_nested is not None and not _has_nested[i_expr]:
newlist.append(expr) # no need to do anything
elif _has_nested is None and not has_nested(expr):
newlist.append(expr) # no need to do anything

elif isinstance(expr, Operator):
Expand Down
2 changes: 1 addition & 1 deletion cpmpy/transformations/negation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..expressions.utils import is_any_list, has_nested, is_boolexpr, is_bool


def push_down_negation(lst_of_expr, toplevel=True):
def push_down_negation(lst_of_expr, toplevel=True, _has_nested=None):
"""
Transformation that checks all elements from the list,
and pushes down any negation it finds with the `recurse_negation()` function.
Expand Down

0 comments on commit fcbe809

Please sign in to comment.