/* Global constraint cardinality_atleast in Picat. From Global Constraint Catalogue http://www.emn.fr/x-info/sdemasse/gccat/Ccardinality_atleast.html """ ATLEAST is the minimum number of time that a value of VALUES is taken by the variables of the collection VARIABLES. Example (1, <3, 3, 8>, <3, 8>) In this example, values 3 and 8 are respectively used 2, and 1 times. The cardinality_atleast constraint holds since its first argument ATLEAST = 1 is assigned to the minimum number of time that values 3 and 8 occur in the collection <3, 3, 8>. """ 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, M = 2, Variables = new_list(N), Variables :: 1..8, Values = new_list(M), Values :: 1..8, NVar :: 0..8, Variables = [3,3,8], Values = [3,8], % NVar #= 1, cardinality_atleast(NVar, Variables, Values), Vars = Variables ++ Values ++ [NVar], solve(Vars), println(variables=Variables), println(values=Values), println(nvar=NVar), nl, fail, nl. go => true. cardinality_atleast(NVar, Variables, Values) => foreach(I in 1..Values.len) sum([Values[I] #= Variables[J] : J in 1..Variables.len]) #>= NVar end.