Skip to content

Commit

Permalink
add minizinc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Wout4 committed Jan 19, 2024
1 parent 30a1407 commit 65e431a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cpmpy/solvers/minizinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def transform(self, cpm_expr):
cpm_cons = toplevel_list(cpm_expr)
supported = {"min", "max", "abs", "element", "count", "nvalue", "alldifferent", "alldifferent_except0", "allequal",
"inverse", "ite" "xor", "table", "cumulative", "circuit", "gcc"}
return decompose_in_tree(cpm_cons, supported, supported_reified=supported - {"circuit"})
return decompose_in_tree(cpm_cons, supported, supported_reified=supported - {"circuit", 'nvalue'})


def __add__(self, cpm_expr):
Expand Down
27 changes: 26 additions & 1 deletion tests/test_globalconstraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ def test_count_onearg(self):
except (NotImplementedError, NotSupportedError):
pass


def test_nvalue(self):

iv = cp.intvar(-8, 8, shape=3)
Expand All @@ -633,10 +632,36 @@ def test_nvalue(self):
# test nested
bv = cp.boolvar()
cons = bv == (cp.NValue(iv) <= 2)

def check_true():
self.assertTrue(cons.value())
cp.Model(cons).solveAll(display=check_true)

@pytest.mark.skipif(not CPM_minizinc.supported(),
reason="Minizinc not installed")
def test_nvalue_minizinc(self):
iv = cp.intvar(-8, 8, shape=3)
cnt = cp.intvar(0, 10)

''' self.assertFalse(cp.Model(cp.all(iv == 1), cp.NValue(iv) > 1).solve('minizinc'))
self.assertTrue(cp.Model(cp.all(iv == 1), cp.NValue(iv) > cnt).solve('minizinc'))
self.assertGreater(len(set(iv.value())), cnt.value())
self.assertTrue(cp.Model(cp.NValue(iv) != cnt).solve('minizinc'))
self.assertTrue(cp.Model(cp.NValue(iv) >= cnt).solve('minizinc'))
self.assertTrue(cp.Model(cp.NValue(iv) <= cnt).solve('minizinc'))
self.assertTrue(cp.Model(cp.NValue(iv) < cnt).solve('minizinc'))
self.assertTrue(cp.Model(cp.NValue(iv) > cnt).solve('minizinc'))'''

# test nested
bv = cp.boolvar()
cons = bv == (cp.NValue(iv) <= 2)

def check_true():
self.assertTrue(cons.value())

cp.Model(cons).solveAll(solver='minizinc')

class TestBounds(unittest.TestCase):
def test_bounds_minimum(self):
x = cp.intvar(-8, 8)
Expand Down

0 comments on commit 65e431a

Please sign in to comment.