Skip to content

Commit

Permalink
clean up reify_rewrite a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Wout4 committed Jul 13, 2023
1 parent 21569a6 commit 5434a23
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions cpmpy/transformations/reification.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import copy

from ..exceptions import NotSupportedError
from ..expressions.core import Operator, Comparison, Expression
from ..expressions.globalconstraints import GlobalConstraint
from ..expressions.globalfunctions import Element
Expand Down Expand Up @@ -127,22 +129,16 @@ def reify_rewrite(constraints, supported=frozenset()):
newcons.append(cpm_expr)
# could actually rewrite into list of clauses like to_cnf() does... not for here
elif isinstance(boolexpr, GlobalConstraint):
# Case 2, BE is a GlobalConstraint
# replace BE by its decomposition, then flatten
if boolexpr.name in supported:
newcons.append(cpm_expr)
else:
raise ValueError(f"Unsupported boolexpr {boolexpr} in reification, run a suitable decomposition transformation from `cpmpy.transformations.decompose_global` to decompose unsupported global constraints")
# decomposing should be done already in decompose_in_tree
raise NotSupportedError(f"Unsupported boolexpr {boolexpr} in reification, run a suitable decomposition transformation from `cpmpy.transformations.decompose_global` to decompose unsupported global constraints")
elif isinstance(boolexpr, Comparison):
# Case 3, BE is Comparison(OP, LHS, RHS)
op, (lhs, rhs) = boolexpr.name, boolexpr.args
# have list of supported lhs's such as sum and wsum...
# at the very least, (iv1 == iv2) == bv has to be supported
if isinstance(lhs, _NumVarImpl) or lhs.name in supported:
newcons.append(cpm_expr)
else: # other cases (assuming LHS is a total function):
# (AUX,c) = get_or_make_var(LHS)
# return c+[Comp(OP,AUX,RHS) == BV] or +[Comp(OP,AUX,RHS) -> BV] or +[Comp(OP,AUX,RHS) <- BV]
else: # other cases:
(auxvar, cons) = get_or_make_var(lhs)
newcons += cons
reifexpr = copy.copy(cpm_expr)
Expand Down

0 comments on commit 5434a23

Please sign in to comment.