以下模型适用于langfords问题
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;
但更自然的阅读约束
constraint forall(r in RAN)( card({i | i in DOM where nos[i] = r}) = m);
失败并显示错误
MiniZinc: type error: no function or predicate with this signature found: `card(var opt set of int)'
有什么建议吗?
答案 0 :(得分:0)
您的设置尺寸取决于var
,这意味着var opt
的类型为var
,如您所想。{/ p>
欲了解更多信息,请阅读:
MiniZinc: type error: expected `array[int] of int', actual `array[int] of var opt int