From a0f41d2b1111cc8069b967fdc436affef35f9f1d Mon Sep 17 00:00:00 2001 From: Ignace Bleukx Date: Fri, 24 May 2024 09:49:06 +0200 Subject: [PATCH] add typechecking and check for length of lists --- cpmpy/expressions/globalconstraints.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cpmpy/expressions/globalconstraints.py b/cpmpy/expressions/globalconstraints.py index 3fbe2a9e1..1a2935c1a 100644 --- a/cpmpy/expressions/globalconstraints.py +++ b/cpmpy/expressions/globalconstraints.py @@ -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):