% % Global constraint all_min_dist in MiniZinc. % % From Global Constraint Catalogue % http://www.emn.fr/x-info/sdemasse/gccat/sec4.2.html % """ % Enforce for each pair (vari, varj)​ of distinct variables of the collection VARIABLES that % |vari - varj| >= MINDIST. % % Example % (2, <5, 1, 9, 3>) % % The all_min_dist constraint holds since the following expressions % |5-1|, |5-9|, |5-3|, |1-9|, |1-3|, |9-3| are all greater than or equal to the first % argument MINDIST = 2 of the all_min_dist constraint. % """ % % % Model created by Hakan Kjellerstrand, hakank@bonetmail.com % See also my MiniZinc page: http://www.hakank.org/minizinc % include "globals.mzn"; int: n = 4; array[1..n] of var 1..9: x; var 0..9: c; predicate all_min_dist(var int: c, array[int] of var int: x) = forall(i, j in 1..n where i != j) ( abs(x[i]-x[j]) >= c ) ; solve satisfy; constraint x = [5,1,9,3] /\ all_min_dist(c, x) /\ c = 2 ;