Skip to content

Commit

Permalink
Merge branch 'master' into xcsp3_executable
Browse files Browse the repository at this point in the history
# Conflicts:
#	cpmpy/expressions/globalfunctions.py
  • Loading branch information
Wout4 committed Jun 4, 2024
2 parents 4028f41 + 7e86304 commit 278dcd3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
6 changes: 0 additions & 6 deletions cpmpy/expressions/globalfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ def decompose_comparison(self, cpm_op, cpm_rhs):
they should be enforced toplevel.
"""
from .python_builtins import any, all
if cpm_op == "==": # can avoid creating aux var
return [any(x <= cpm_rhs for x in self.args)], [all(x >= cpm_rhs for x in self.args)]

lb, ub = self.get_bounds()
_min = intvar(lb, ub)
return [eval_comparison(cpm_op, _min, cpm_rhs)], \
Expand Down Expand Up @@ -173,9 +170,6 @@ def decompose_comparison(self, cpm_op, cpm_rhs):
they should be enforced toplevel.
"""
from .python_builtins import any, all
if cpm_op == "==": # can avoid creating aux var here
return [any(x >= cpm_rhs for x in self.args)], [all(x <= cpm_rhs for x in self.args)]

lb, ub = self.get_bounds()
_max = intvar(lb, ub)
return [eval_comparison(cpm_op, _max, cpm_rhs)], \
Expand Down
6 changes: 3 additions & 3 deletions tests/test_transf_decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ def test_decompose_nested(self):

cons = [min(ivs) == max(ivs)]
self.assertEqual(str(decompose_in_tree(cons, supported={"min"})),
"[or([(x) >= (min(x,y,z)), (y) >= (min(x,y,z)), (z) >= (min(x,y,z))]), (x) <= (min(x,y,z)), (y) <= (min(x,y,z)), (z) <= (min(x,y,z))]")
'[(IV0) == (min(x,y,z)), or([(x) >= (IV0), (y) >= (IV0), (z) >= (IV0)]), (x) <= (IV0), (y) <= (IV0), (z) <= (IV0)]')

self.assertEqual(str(decompose_in_tree(cons, supported={"max"})),
"[or([(x) <= (max(x,y,z)), (y) <= (max(x,y,z)), (z) <= (max(x,y,z))]), (x) >= (max(x,y,z)), (y) >= (max(x,y,z)), (z) >= (max(x,y,z))]")
"[(IV1) == (max(x,y,z)), or([(x) <= (IV1), (y) <= (IV1), (z) <= (IV1)]), (x) >= (IV1), (y) >= (IV1), (z) >= (IV1)]")

# numerical in non-comparison context
cons = [AllEqual([min(ivs[:-1]),ivs[-1]])]
self.assertEqual(str(decompose_in_tree(cons, supported={"allequal"})),
"[allequal(IV0,z), ((x) <= (IV0)) or ((y) <= (IV0)), (x) >= (IV0), (y) >= (IV0)]")
"[allequal(IV2,z), (IV3) == (IV2), ((x) <= (IV3)) or ((y) <= (IV3)), (x) >= (IV3), (y) >= (IV3)]")

self.assertEqual(str(decompose_in_tree(cons, supported={"min"})),
"[(min(x,y)) == (z)]")
Expand Down

0 comments on commit 278dcd3

Please sign in to comment.