简体   繁体   中英

Cardinality constraint type failure; how to use minizinc `card` correctly

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM