Skip to content

Commit

Permalink
add typechecking and check for length of lists
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnaceBleukx committed May 24, 2024
1 parent 5718281 commit a0f41d2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cpmpy/expressions/globalconstraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ class AllDifferentLists(GlobalConstraint):
https://sofdem.github.io/gccat/gccat/Clex_alldifferent.html#uid24923
"""
def __init__(self, lists):
if any(not is_any_list(lst) for lst in lists):
raise TypeError(f"AllDifferentLists expects a list of lists, but got {lists}")
if any(len(lst) != len(lists[0]) for lst in lists):
raise ValueError("Lists should have equal length, but got these lengths:", list(map(len, lists)))
super().__init__("alldifferent_lists", [flatlist(lst) for lst in lists])

def decompose(self):
Expand Down

0 comments on commit a0f41d2

Please sign in to comment.