% % Global constraint discrepancy in MiniZinc. % % From Global Constraint Catalogue % http://www.emn.fr/x-info/sdemasse/gccat/sec4.93.html % """ % discrepancy(VARIABLES,​K) % % Purpose % % K is the number of variables of the collection VARIABLES that take their % value in their respective sets of bad values. % % Example % ( % < % var-4 bad-{1, 4, 6}, % var-5 bad-{0, 1}, % var-5 bad-{1, 6, 9}, % var-4 bad-{1,​4}, % var-1 bad-{} % >, 2 % ) % % The discrepancy constraint holds since exactly K=2 variables % (i.e., the first and fourth variables) of the VARIABLES collection % take their value within their respective sets of bad values. % % """ % This MiniZinc model was created by Hakan Kjellerstrand, hakank@bonetmail.com % See also my MiniZinc page: http://www.hakank.org/minizinc % % include "globals.mzn"; int: n = 5; array[1..n] of var 1..5: variables; array[1..n] of var set of 0..9: bad; var int: k; solve satisfy; constraint bad = [ {1,4,6}, {0,1}, {1,6,9}, {1,4}, {} ] /\ variables = [4,5,5,4,1] /\ k = 2 /\ k = sum(i in 1..n) ( bool2int( variables[i] in bad[i] ) ) ;