From 5434a233957a9c01e315819f56dda213e8e45c00 Mon Sep 17 00:00:00 2001 From: wout4 Date: Thu, 13 Jul 2023 12:37:44 +0200 Subject: [PATCH] clean up reify_rewrite a little bit --- cpmpy/transformations/reification.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/cpmpy/transformations/reification.py b/cpmpy/transformations/reification.py index c5b6930c8..2ae83cd3a 100644 --- a/cpmpy/transformations/reification.py +++ b/cpmpy/transformations/reification.py @@ -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 @@ -127,12 +129,8 @@ 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 @@ -140,9 +138,7 @@ def reify_rewrite(constraints, supported=frozenset()): # 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)