Skip to content

Commit

Permalink
only_bv_reifies
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimosts committed Sep 18, 2023
1 parent a188ba3 commit 15d5cd2
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cpmpy/transformations/reification.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@
- reify_rewrite(): rewrites reifications not supported by a solver to ones that are
"""

def only_bv_reifies(constraints):
newcons = []
for cpm_expr in constraints:
if cpm_expr.name in ['->', "=="]:
a0, a1 = cpm_expr.args
if not isinstance(a0, _BoolVarImpl) and \
isinstance(a1, _BoolVarImpl):
# BE -> BV :: ~BV -> ~BE
if cpm_expr.name == '->':
newexpr = [(~a1).implies(recurse_negation(a0))]
else:
newexpr = [a1 == a0] # BE == BV :: BV == BE
if not a0.is_bool():
newexpr = flatten_constraint(newexpr)
newcons.extend(newexpr)
else:
newcons.append(cpm_expr)
else:
newcons.append(cpm_expr)
return newcons

def only_bv_implies(constraints):
"""
Transforms all reifications to BV -> BE form
Expand Down

0 comments on commit 15d5cd2

Please sign in to comment.