基数约束类型失败;如何正确使用minizinc `card`
Cardinality constraint type failure; how to use minizinc `card` correctly
以下模型适用于 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)'
有什么建议吗?
您的设置大小取决于 var
,这意味着类型是 var opt
而不是您想象的 var
。
如需更多信息,请阅读此处:
以下模型适用于 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)'
有什么建议吗?
您的设置大小取决于 var
,这意味着类型是 var opt
而不是您想象的 var
。
如需更多信息,请阅读此处: