/* Global constraint Increasing values/2 in Picat. increasing_values(X,Values) ensures that the values in Values are increasing in the list X. Here's the solution for a model with a list of 6 distinct element with - increasing_values(X,1..3): 1,2, and 3 should be increasing - increasing_values(X,4..6): and 4, 5, and 6 shoule be increasing Here are all solutions: [1,2,3,4,5,6] [1,2,4,3,5,6] [1,2,4,5,3,6] [1,2,4,5,6,3] [1,4,2,3,5,6] [1,4,2,5,3,6] [1,4,2,5,6,3] [1,4,5,2,3,6] [1,4,5,2,6,3] [1,4,5,6,2,3] [4,1,2,3,5,6] [4,1,2,5,3,6] [4,1,2,5,6,3] [4,1,5,2,3,6] [4,1,5,2,6,3] [4,1,5,6,2,3] [4,5,1,2,3,6] [4,5,1,2,6,3] [4,5,1,6,2,3] [4,5,6,1,2,3] This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => N = 6, X = new_list(N), X :: 1..N, all_different(X), increasing_values(X,1..3), increasing_values(X,4..6), solve(X), println(X), fail, nl. % % increasing_values(X, Values) % Ensure that values that are in Values should be increasing in X. % % It's a generalization (and the oppsite of) the % global constraint increasing_except_0(X). % increasing_values(X,Values) => Len = X.length, foreach(I in 1..Len, J in 1..Len, I < J) ( sum( [X[I] #= V : V in Values] ) #> 0 #/\ sum([X[J] #= V : V in Values]) #> 0) #=> X[I] #=< X[J] end.