diff --git a/cpmpy/solvers/minizinc.py b/cpmpy/solvers/minizinc.py index 1e5e7e449..3ff7146e8 100644 --- a/cpmpy/solvers/minizinc.py +++ b/cpmpy/solvers/minizinc.py @@ -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): diff --git a/tests/test_globalconstraints.py b/tests/test_globalconstraints.py index 2ac7028be..97d78472f 100644 --- a/tests/test_globalconstraints.py +++ b/tests/test_globalconstraints.py @@ -614,7 +614,6 @@ def test_count_onearg(self): except (NotImplementedError, NotSupportedError): pass - def test_nvalue(self): iv = cp.intvar(-8, 8, shape=3) @@ -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)