The following model works for langfords problem
int: m = 2;
int: n = 3;
set of int: DOM = 1..m*n;
set of int: RAN = 1..n;
array [DOM] of var 1..n: nos;
constraint forall(j in DOM, k in j+1..m*n) (nos[j] = nos[k] /\ forall(l in j + 1 .. k - 1)(nos[l] != nos[k]) -> k - j = nos[j] + 1);
constraint forall(r in RAN)( sum([1 | i in DOM where nos[i] = r]) = m);
solve satisfy;
However the to more more natural reading constraint
constraint forall(r in RAN)( card({i | i in DOM where nos[i] = r}) = m);
fails with the error
MiniZinc: type error: no function or predicate with this signature found: `card(var opt set of int)'
Any suggestions?
Your set size is dependent on a var
, this means that the type is var opt
insted of var
as you would imagine.
For more information read here:
MiniZinc: type error: expected `array[int] of int', actual `array[int] of var opt int