Skip to content

Commit

Permalink
remove type restriction for InDomain (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wout4 authored May 10, 2024
1 parent 3619176 commit dfa81ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 0 additions & 2 deletions cpmpy/expressions/globalconstraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,6 @@ class InDomain(GlobalConstraint):
"""

def __init__(self, expr, arr):
assert not (is_boolexpr(expr) or any(is_boolexpr(a) for a in arr)), \
"The expressions in the InDomain constraint should not be boolean"
super().__init__("InDomain", [expr, arr])

def decompose(self):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_globalconstraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,24 @@ def test_InDomain(self):
model = cp.Model(cons)
self.assertTrue(model.solve())
self.assertIn(iv.value(), vals)
vals = [1, 5, 8, -4]
bv = cp.boolvar()
cons = [cp.InDomain(bv, vals)]
model = cp.Model(cons)
self.assertTrue(model.solve())
self.assertIn(bv.value(), vals)
vals = [iv2, 5, 8, -4]
bv = cp.boolvar()
cons = [cp.InDomain(bv, vals)]
model = cp.Model(cons)
self.assertTrue(model.solve())
self.assertIn(bv.value(), vals)
vals = [bv & bv, 5, 8, -4]
bv = cp.boolvar()
cons = [cp.InDomain(bv, vals)]
model = cp.Model(cons)
self.assertTrue(model.solve())
self.assertIn(bv.value(), vals)

def test_indomain_onearg(self):

Expand Down

0 comments on commit dfa81ff

Please sign in to comment.