% % Global constraint alldifferent_on_intersection in MiniZinc. % % From Global Constraint Catalogue % http://www.emn.fr/x-info/sdemasse/gccat/sec4.9.html % """ % The values that both occur in the VARIABLES1 and VARIABLES2 collections have only % one occurrence. % % Example % ( % <5, 9, 1, 5>, % <2, 1, 6, 9, 6, 2> % ) % % The alldifferent_on_intersection constraint holds since the values 9 and 1 that % both occur in <5, 9, 1, 5> as well as in <2, 1, 6, 9, 6, 2> have exactly one occurrence % in each collection. % """ % % Model created by Hakan Kjellerstrand, hakank@bonetmail.com % See also my MiniZinc page: http://www.hakank.org/minizinc % include "globals.mzn"; int: m = 4; int: n = 6; array[1..m] of var 1..9: x; array[1..n] of var 1..9: y; % % alldifferent_on_intersection % predicate alldifferent_on_intersection(array[int] of var int: x, array[int] of var int: y) = let { int: m = length(x), int: n = length(y) } in forall(i in 1..m) ( sum(j in 1..n) (bool2int(x[i] = y[j])) <= 1 ) /\ forall(j in 1..n) ( sum(i in 1..m) (bool2int(x[i] = y[j])) <= 1 ) ; solve satisfy; constraint x = [5,9,1,5] /\ y = [2,1,6,9,6,2] % constraint holds % y = [2,1,6,9,6,1] % constraint do not hold since there are two 1's in 1 and one 1 in x /\ alldifferent_on_intersection(x,y) ;