/* Global constraint domain in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Cdomain.html """ domain(VARIABLES,LOW,UP) Purpose Enforce all the variables of the collection VARIABLES to take a value within the interval [LOW,UP]. Example ([2,8,2],1,9) The domain constraint holds since all the values 2, 8 and 2 of its first argument are greater than or equal to its second argument LOW=1 and less than or equal to its third argument UP=9. """ In Picat we would write this as Variables :: Low..Up so this might not a very useful constraint decomposition. Note: For obtaining the low and up values from a list, we use Low = min(Variables) Max = max(Variables) but this is not really relevant for the constraint at hand. 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 = 3, X = new_list(N), X :: 1..8, Low :: 0..10, Up :: 0..10, Low #= 1, Up #= 9, domain(X, Low, Up), Vars = X ++ [Low,Up], solve(Vars), println(x=X), println([low=Low,up=Up]), nl, fail, nl. go => true. domain(Variables, Low, Up) => foreach(I in 1..Variables.len) Variables[I] #>= Low, Variables[I] #<= Up end.