/* Inter-distance constraint in Picat. From Claude-Guy Quimper: "Efficient Propagators for Global Constraints" page 3: """ The Inter-Distance constraint ensures that all variables, among a set of variables x1,...,xn, are pairwise distant from p, i.e. |xi-xj| >= p for all i != j. """ Note: when p = 1 then inter_distance is the same as alldifferent. This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> N = 4, X = new_list(N), X :: 0..N*4, P :: 0..10, inter_distance(X, P), P #= 3, Vars = X ++ [P], solve($[],Vars), println(x=X), println(p=P), nl, fail, nl. go => true. inter_distance(X, P) => N = X.len, foreach(I in 1..N, J in I+1..N) abs(X[I]-X[J]) #>= P end.